This commit is contained in:
cutestnekoaqua 2023-03-30 17:31:29 +02:00
parent 00dc860574
commit 09aeb6e2f5
No known key found for this signature in database
GPG Key ID: 6BF0964A5069C1E0
5 changed files with 18 additions and 4 deletions

View File

@ -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,

View File

@ -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<DbUserImportJobData>,
job: Bull.Job<DbUserImportPostsJobData>,
done: any,
): Promise<void> {
logger.info(`Importing posts of ${job.data.user.id} ...`);

View File

@ -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<string, unknown>;

View File

@ -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);
});

View File

@ -10,6 +10,9 @@
<FormFolder class="_formBlock">
<template #label>{{ i18n.ts.import }}</template>
<template #icon><i class="ph-upload-simple ph-bold ph-lg"></i></template>
<FormSwitch v-model="signatureCheck" class="_formBlock">
Mastodon import?
</FormSwitch>
<MkButton primary :class="$style.button" inline @click="importPosts($event)"><i class="ph-upload-simple ph-bold ph-lg"></i> {{ i18n.ts.import }}</MkButton>
</FormFolder>
</FormSection>
@ -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 = () => {