From 09aeb6e2f536207bf2838f9c5bd3c081453c877d Mon Sep 17 00:00:00 2001 From: cutestnekoaqua Date: Thu, 30 Mar 2023 17:31:29 +0200 Subject: [PATCH] nyaa --- packages/backend/src/queue/index.ts | 2 ++ packages/backend/src/queue/processors/db/import-posts.ts | 4 ++-- packages/backend/src/queue/types.ts | 7 +++++++ .../backend/src/server/api/endpoints/i/import-posts.ts | 3 ++- packages/client/src/pages/settings/import-export.vue | 6 +++++- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/queue/index.ts b/packages/backend/src/queue/index.ts index d5b42d637..1327853d0 100644 --- a/packages/backend/src/queue/index.ts +++ b/packages/backend/src/queue/index.ts @@ -317,12 +317,14 @@ export function createImportFollowingJob( export function createImportPostsJob( user: ThinUser, fileId: DriveFile["id"], + signatureCheck: boolean, ) { return dbQueue.add( "importPosts", { user: user, fileId: fileId, + signatureCheck: signatureCheck, }, { removeOnComplete: true, diff --git a/packages/backend/src/queue/processors/db/import-posts.ts b/packages/backend/src/queue/processors/db/import-posts.ts index 3bfb3acca..cbeb33335 100644 --- a/packages/backend/src/queue/processors/db/import-posts.ts +++ b/packages/backend/src/queue/processors/db/import-posts.ts @@ -5,7 +5,7 @@ import * as Post from "@/misc/post.js"; import create from "@/services/note/create.js"; import { downloadTextFile } from "@/misc/download-text-file.js"; import { Users, DriveFiles } from "@/models/index.js"; -import type { DbUserImportJobData } from "@/queue/types.js"; +import type { DbUserImportPostsJobData } from "@/queue/types.js"; import { queueLogger } from "../../logger.js"; import type Bull from "bull"; import { htmlToMfm } from "@/remote/activitypub/misc/html-to-mfm.js"; @@ -13,7 +13,7 @@ import { htmlToMfm } from "@/remote/activitypub/misc/html-to-mfm.js"; const logger = queueLogger.createSubLogger("import-posts"); export async function importPosts( - job: Bull.Job, + job: Bull.Job, done: any, ): Promise { logger.info(`Importing posts of ${job.data.user.id} ...`); diff --git a/packages/backend/src/queue/types.ts b/packages/backend/src/queue/types.ts index 90e88f736..e31619ff2 100644 --- a/packages/backend/src/queue/types.ts +++ b/packages/backend/src/queue/types.ts @@ -21,6 +21,7 @@ export type InboxJobData = { export type DbJobData = | DbUserJobData + | DbUserImportPostsJobData | DbUserImportJobData | DbUserDeleteJobData; @@ -40,6 +41,12 @@ export type DbUserImportJobData = { fileId: DriveFile["id"]; }; +export type DbUserImportPostsJobData = { + user: ThinUser; + fileId: DriveFile["id"]; + signatureCheck: boolean; +}; + export type ObjectStorageJobData = | ObjectStorageFileJobData | Record; diff --git a/packages/backend/src/server/api/endpoints/i/import-posts.ts b/packages/backend/src/server/api/endpoints/i/import-posts.ts index 254e37d8a..6fdf562fd 100644 --- a/packages/backend/src/server/api/endpoints/i/import-posts.ts +++ b/packages/backend/src/server/api/endpoints/i/import-posts.ts @@ -30,6 +30,7 @@ export const paramDef = { type: "object", properties: { fileId: { type: "string", format: "misskey:id" }, + signatureCheck: { type: "boolean" }, }, required: ["fileId"], } as const; @@ -39,5 +40,5 @@ export default define(meta, paramDef, async (ps, user) => { if (file == null) throw new ApiError(meta.errors.noSuchFile); if (file.size === 0) throw new ApiError(meta.errors.emptyFile); - createImportPostsJob(user, file.id); + createImportPostsJob(user, file.id, ps.signatureCheck); }); diff --git a/packages/client/src/pages/settings/import-export.vue b/packages/client/src/pages/settings/import-export.vue index 4822ccff0..4222c6fa0 100644 --- a/packages/client/src/pages/settings/import-export.vue +++ b/packages/client/src/pages/settings/import-export.vue @@ -10,6 +10,9 @@ + + Mastodon import? + {{ i18n.ts.import }} @@ -86,6 +89,7 @@ import { i18n } from '@/i18n'; import { definePageMetadata } from '@/scripts/page-metadata'; const excludeMutingUsers = ref(false); +const signatureCheck = ref(false); const excludeInactiveUsers = ref(false); const onExportSuccess = () => { @@ -115,7 +119,7 @@ const exportNotes = () => { const importPosts = async (ev) => { const file = await selectFile(ev.currentTarget ?? ev.target); - os.api('i/import-posts', { fileId: file.id }).then(onImportSuccess).catch(onError); + os.api('i/import-posts', { fileId: file.id, signatureCheck: signatureCheck }).then(onImportSuccess).catch(onError); }; const exportFollowing = () => {