summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/i
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-10-20 01:11:13 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-10-20 01:11:13 +0900
commitbc19cd77adfc1ba73df5358dac0a7b49166b02ac (patch)
treec142dd6ae9baf9c6e3a4d6bbf7f465bc2e1fb933 /src/server/api/endpoints/i
parentrefactor: use insert (diff)
downloadsharkey-bc19cd77adfc1ba73df5358dac0a7b49166b02ac.tar.gz
sharkey-bc19cd77adfc1ba73df5358dac0a7b49166b02ac.tar.bz2
sharkey-bc19cd77adfc1ba73df5358dac0a7b49166b02ac.zip
feat: ミュートとブロックのインポート
Resolve #7885
Diffstat (limited to 'src/server/api/endpoints/i')
-rw-r--r--src/server/api/endpoints/i/import-blocking.ts60
-rw-r--r--src/server/api/endpoints/i/import-muting.ts60
2 files changed, 120 insertions, 0 deletions
diff --git a/src/server/api/endpoints/i/import-blocking.ts b/src/server/api/endpoints/i/import-blocking.ts
new file mode 100644
index 0000000000..d44d0b6077
--- /dev/null
+++ b/src/server/api/endpoints/i/import-blocking.ts
@@ -0,0 +1,60 @@
+import $ from 'cafy';
+import { ID } from '@/misc/cafy-id';
+import define from '../../define';
+import { createImportBlockingJob } from '@/queue/index';
+import * as ms from 'ms';
+import { ApiError } from '../../error';
+import { DriveFiles } from '@/models/index';
+
+export const meta = {
+ secure: true,
+ requireCredential: true as const,
+
+ limit: {
+ duration: ms('1hour'),
+ max: 1,
+ },
+
+ params: {
+ fileId: {
+ validator: $.type(ID),
+ }
+ },
+
+ errors: {
+ noSuchFile: {
+ message: 'No such file.',
+ code: 'NO_SUCH_FILE',
+ id: 'ebb53e5f-6574-9c0c-0b92-7ca6def56d7e'
+ },
+
+ unexpectedFileType: {
+ message: 'We need csv file.',
+ code: 'UNEXPECTED_FILE_TYPE',
+ id: 'b6fab7d6-d945-d67c-dfdb-32da1cd12cfe'
+ },
+
+ tooBigFile: {
+ message: 'That file is too big.',
+ code: 'TOO_BIG_FILE',
+ id: 'b7fbf0b1-aeef-3b21-29ef-fadd4cb72ccf'
+ },
+
+ emptyFile: {
+ message: 'That file is empty.',
+ code: 'EMPTY_FILE',
+ id: '6f3a4dcc-f060-a707-4950-806fbdbe60d6'
+ },
+ }
+};
+
+export default define(meta, async (ps, user) => {
+ const file = await DriveFiles.findOne(ps.fileId);
+
+ if (file == null) throw new ApiError(meta.errors.noSuchFile);
+ //if (!file.type.endsWith('/csv')) throw new ApiError(meta.errors.unexpectedFileType);
+ if (file.size > 50000) throw new ApiError(meta.errors.tooBigFile);
+ if (file.size === 0) throw new ApiError(meta.errors.emptyFile);
+
+ createImportBlockingJob(user, file.id);
+});
diff --git a/src/server/api/endpoints/i/import-muting.ts b/src/server/api/endpoints/i/import-muting.ts
new file mode 100644
index 0000000000..c17434c587
--- /dev/null
+++ b/src/server/api/endpoints/i/import-muting.ts
@@ -0,0 +1,60 @@
+import $ from 'cafy';
+import { ID } from '@/misc/cafy-id';
+import define from '../../define';
+import { createImportMutingJob } from '@/queue/index';
+import * as ms from 'ms';
+import { ApiError } from '../../error';
+import { DriveFiles } from '@/models/index';
+
+export const meta = {
+ secure: true,
+ requireCredential: true as const,
+
+ limit: {
+ duration: ms('1hour'),
+ max: 1,
+ },
+
+ params: {
+ fileId: {
+ validator: $.type(ID),
+ }
+ },
+
+ errors: {
+ noSuchFile: {
+ message: 'No such file.',
+ code: 'NO_SUCH_FILE',
+ id: 'e674141e-bd2a-ba85-e616-aefb187c9c2a'
+ },
+
+ unexpectedFileType: {
+ message: 'We need csv file.',
+ code: 'UNEXPECTED_FILE_TYPE',
+ id: '568c6e42-c86c-ba09-c004-517f83f9f1a8'
+ },
+
+ tooBigFile: {
+ message: 'That file is too big.',
+ code: 'TOO_BIG_FILE',
+ id: '9b4ada6d-d7f7-0472-0713-4f558bd1ec9c'
+ },
+
+ emptyFile: {
+ message: 'That file is empty.',
+ code: 'EMPTY_FILE',
+ id: 'd2f12af1-e7b4-feac-86a3-519548f2728e'
+ },
+ }
+};
+
+export default define(meta, async (ps, user) => {
+ const file = await DriveFiles.findOne(ps.fileId);
+
+ if (file == null) throw new ApiError(meta.errors.noSuchFile);
+ //if (!file.type.endsWith('/csv')) throw new ApiError(meta.errors.unexpectedFileType);
+ if (file.size > 50000) throw new ApiError(meta.errors.tooBigFile);
+ if (file.size === 0) throw new ApiError(meta.errors.emptyFile);
+
+ createImportMutingJob(user, file.id);
+});