From 24bd05d09040103ee5eb275ef7fbaeec957831f3 Mon Sep 17 00:00:00 2001 From: limepotato Date: Sun, 30 Jun 2024 15:19:46 -0600 Subject: [PATCH] temporarily re-enable post imports (not masto) Signed-off-by: limepotato --- locales/en-US.yml | 6 ++++ .../processors/db/import-firefish-post.ts | 36 +++++++++++++++++++ .../server/api/endpoints/i/import-posts.ts | 15 ++++++-- .../src/pages/settings/import-export.vue | 29 +++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index 74174beec..e0cb2b3b6 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -1490,6 +1490,12 @@ _time: hour: "Hour(s)" day: "Day(s)" _filters: + _experiments: + title: "Experiments" + enablePostImports: "Enable post imports" + postImportsCaption: "Allows users to import their posts from past Iceshrimp, Misskey, + Mastodon, Akkoma, and Pleroma accounts. It may cause slowdowns during load if + your queue is bottlenecked." _dialog: title: "Search filter syntax" learnMore: "View filter syntax" diff --git a/packages/backend/src/queue/processors/db/import-firefish-post.ts b/packages/backend/src/queue/processors/db/import-firefish-post.ts index c7a6fd7f0..504cf9e50 100644 --- a/packages/backend/src/queue/processors/db/import-firefish-post.ts +++ b/packages/backend/src/queue/processors/db/import-firefish-post.ts @@ -11,5 +11,41 @@ export async function importCkPost( job: Bull.Job, done: any, ): Promise { + const user = await Users.findOneBy({ id: job.data.user.id }); + if (user == null) { + done(); + return; + } + const post = job.data.post; + if (post.replyId != null) { + done(); + return; + } + if (post.renoteId != null) { + done(); + return; + } + if (post.visibility !== "public") { + done(); + return; + } + const { text, cw, localOnly, createdAt } = Post.parse(post); + const note = await create(user, { + createdAt: createdAt, + files: undefined, + poll: undefined, + text: text || undefined, + reply: null, + renote: null, + cw: cw, + localOnly, + visibility: "hidden", + visibleUsers: [], + channel: null, + apMentions: new Array(0), + apHashtags: undefined, + apEmojis: undefined, + }); + logger.succ("Imported"); done(); } 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 a4cfa4101..3adba0514 100644 --- a/packages/backend/src/server/api/endpoints/i/import-posts.ts +++ b/packages/backend/src/server/api/endpoints/i/import-posts.ts @@ -1,6 +1,9 @@ import define from "../../define.js"; +import { createImportPostsJob } from "@/queue/index.js"; import { ApiError } from "../../error.js"; +import { DriveFiles } from "@/models/index.js"; import { DAY } from "@/const.js"; +import { fetchMeta } from "@/misc/fetch-meta.js"; export const meta = { secure: true, @@ -23,7 +26,7 @@ export const meta = { }, importsDisabled: { - message: "Post imports are disabled for security reasons.", + message: "Post imports are disabled.", code: "IMPORTS_DISABLED", id: " bc9227e4-fb82-11ed-be56-0242ac120002", }, @@ -40,5 +43,13 @@ export const paramDef = { } as const; export default define(meta, paramDef, async (ps, user) => { - throw new ApiError(meta.errors.importsDisabled); + const file = await DriveFiles.findOneBy({ id: ps.fileId }); + + const instanceMeta = await fetchMeta(); + if (instanceMeta.experimentalFeatures?.postImports === false) + throw new ApiError(meta.errors.importsDisabled); + + if (file == null) throw new ApiError(meta.errors.noSuchFile); + if (file.size === 0) throw new ApiError(meta.errors.emptyFile); + 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 8ffe50ebf..770f90b10 100644 --- a/packages/client/src/pages/settings/import-export.vue +++ b/packages/client/src/pages/settings/import-export.vue @@ -16,6 +16,25 @@ {{ i18n.ts.export }} + + + + + + + + + + {{ i18n.ts.import }} +