Feat: move post imports to new jobs
This commit is contained in:
parent
d6c8e0dbf4
commit
e4a821a494
|
@ -333,6 +333,44 @@ export function createImportPostsJob(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createImportMastoPostJob(
|
||||||
|
user: ThinUser,
|
||||||
|
post: any,
|
||||||
|
signatureCheck: boolean,
|
||||||
|
) {
|
||||||
|
return dbQueue.add(
|
||||||
|
"importMastoPost",
|
||||||
|
{
|
||||||
|
user: user,
|
||||||
|
post: post,
|
||||||
|
signatureCheck: signatureCheck,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
removeOnComplete: true,
|
||||||
|
removeOnFail: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createImportCkPostJob(
|
||||||
|
user: ThinUser,
|
||||||
|
post: any,
|
||||||
|
signatureCheck: boolean,
|
||||||
|
) {
|
||||||
|
return dbQueue.add(
|
||||||
|
"importCkPost",
|
||||||
|
{
|
||||||
|
user: user,
|
||||||
|
post: post,
|
||||||
|
signatureCheck: signatureCheck,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
removeOnComplete: true,
|
||||||
|
removeOnFail: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function createImportMutingJob(user: ThinUser, fileId: DriveFile["id"]) {
|
export function createImportMutingJob(user: ThinUser, fileId: DriveFile["id"]) {
|
||||||
return dbQueue.add(
|
return dbQueue.add(
|
||||||
"importMuting",
|
"importMuting",
|
||||||
|
|
|
@ -1,16 +1,9 @@
|
||||||
import { IsNull } from "typeorm";
|
|
||||||
import follow from "@/services/following/create.js";
|
|
||||||
|
|
||||||
import * as Post from "@/misc/post.js";
|
|
||||||
import create from "@/services/note/create.js";
|
|
||||||
import { downloadTextFile } from "@/misc/download-text-file.js";
|
import { downloadTextFile } from "@/misc/download-text-file.js";
|
||||||
import { Users, DriveFiles } from "@/models/index.js";
|
import { Users, DriveFiles } from "@/models/index.js";
|
||||||
import type { DbUserImportPostsJobData } from "@/queue/types.js";
|
import type { DbUserImportPostsJobData } from "@/queue/types.js";
|
||||||
import { queueLogger } from "../../logger.js";
|
import { queueLogger } from "../../logger.js";
|
||||||
import type Bull from "bull";
|
import type Bull from "bull";
|
||||||
import { htmlToMfm } from "@/remote/activitypub/misc/html-to-mfm.js";
|
import { createImportCkPostJob, createImportMastoPostJob } from "@/queue/index.js";
|
||||||
import { resolveNote } from "@/remote/activitypub/models/note.js";
|
|
||||||
import { Note } from "@/models/entities/note.js";
|
|
||||||
|
|
||||||
const logger = queueLogger.createSubLogger("import-posts");
|
const logger = queueLogger.createSubLogger("import-posts");
|
||||||
|
|
||||||
|
@ -36,94 +29,17 @@ export async function importPosts(
|
||||||
|
|
||||||
const json = await downloadTextFile(file.url);
|
const json = await downloadTextFile(file.url);
|
||||||
|
|
||||||
let linenum = 0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(json);
|
const parsed = JSON.parse(json);
|
||||||
if (parsed instanceof Array) {
|
if (parsed instanceof Array) {
|
||||||
logger.info("Parsing key style posts");
|
logger.info("Parsing key style posts");
|
||||||
for (const post of JSON.parse(json)) {
|
for (const post of JSON.parse(json)) {
|
||||||
try {
|
createImportCkPostJob(job.data.user, post, job.data.signatureCheck);
|
||||||
linenum++;
|
|
||||||
if (post.replyId != null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (post.renoteId != null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (post.visibility !== "public") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const { text, cw, localOnly, createdAt } = Post.parse(post);
|
|
||||||
|
|
||||||
logger.info(`Posting[${linenum}] ...`);
|
|
||||||
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
logger.warn(`Error in line:${linenum} ${e}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (parsed instanceof Object) {
|
} else if (parsed instanceof Object) {
|
||||||
logger.info("Parsing animal style posts");
|
logger.info("Parsing animal style posts");
|
||||||
for (const post of parsed.orderedItems) {
|
for (const post of parsed.orderedItems) {
|
||||||
async () => {
|
createImportMastoPostJob(job.data.user, post, job.data.signatureCheck);
|
||||||
try {
|
|
||||||
linenum++;
|
|
||||||
let reply: Note | null = null;
|
|
||||||
if (post.object.inReplyTo != null) {
|
|
||||||
reply = await resolveNote(post.object.inReplyTo);
|
|
||||||
}
|
|
||||||
if (post.directMessage) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (job.data.signatureCheck) {
|
|
||||||
if (!post.signature) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let text;
|
|
||||||
try {
|
|
||||||
text = htmlToMfm(post.object.content, post.object.tag);
|
|
||||||
} catch (e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
logger.info(`Posting[${linenum}] ...`);
|
|
||||||
|
|
||||||
const note = await create(user, {
|
|
||||||
createdAt: new Date(post.object.published),
|
|
||||||
files: undefined,
|
|
||||||
poll: undefined,
|
|
||||||
text: text || undefined,
|
|
||||||
reply,
|
|
||||||
renote: null,
|
|
||||||
cw: post.sensitive,
|
|
||||||
localOnly: false,
|
|
||||||
visibility: "hidden",
|
|
||||||
visibleUsers: [],
|
|
||||||
channel: null,
|
|
||||||
apMentions: new Array(0),
|
|
||||||
apHashtags: undefined,
|
|
||||||
apEmojis: undefined,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
logger.warn(`Error in line:${linenum} ${e}`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -12,6 +12,8 @@ import { importUserLists } from "./import-user-lists.js";
|
||||||
import { deleteAccount } from "./delete-account.js";
|
import { deleteAccount } from "./delete-account.js";
|
||||||
import { importMuting } from "./import-muting.js";
|
import { importMuting } from "./import-muting.js";
|
||||||
import { importPosts } from "./import-posts.js";
|
import { importPosts } from "./import-posts.js";
|
||||||
|
import { importMastoPost } from "./import-masto-post.js";
|
||||||
|
import { importCkPost } from "./import-calckey-post.js";
|
||||||
import { importBlocking } from "./import-blocking.js";
|
import { importBlocking } from "./import-blocking.js";
|
||||||
import { importCustomEmojis } from "./import-custom-emojis.js";
|
import { importCustomEmojis } from "./import-custom-emojis.js";
|
||||||
|
|
||||||
|
@ -28,6 +30,8 @@ const jobs = {
|
||||||
importBlocking,
|
importBlocking,
|
||||||
importUserLists,
|
importUserLists,
|
||||||
importPosts,
|
importPosts,
|
||||||
|
importMastoPost,
|
||||||
|
importCkPost,
|
||||||
importCustomEmojis,
|
importCustomEmojis,
|
||||||
deleteAccount,
|
deleteAccount,
|
||||||
} as Record<
|
} as Record<
|
||||||
|
|
|
@ -23,7 +23,8 @@ export type DbJobData =
|
||||||
| DbUserJobData
|
| DbUserJobData
|
||||||
| DbUserImportPostsJobData
|
| DbUserImportPostsJobData
|
||||||
| DbUserImportJobData
|
| DbUserImportJobData
|
||||||
| DbUserDeleteJobData;
|
| DbUserDeleteJobData
|
||||||
|
| DbUserImportMastoPostJobData;
|
||||||
|
|
||||||
export type DbUserJobData = {
|
export type DbUserJobData = {
|
||||||
user: ThinUser;
|
user: ThinUser;
|
||||||
|
@ -47,6 +48,12 @@ export type DbUserImportPostsJobData = {
|
||||||
signatureCheck: boolean;
|
signatureCheck: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type DbUserImportMastoPostJobData = {
|
||||||
|
user: ThinUser;
|
||||||
|
post: any;
|
||||||
|
signatureCheck: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export type ObjectStorageJobData =
|
export type ObjectStorageJobData =
|
||||||
| ObjectStorageFileJobData
|
| ObjectStorageFileJobData
|
||||||
| Record<string, unknown>;
|
| Record<string, unknown>;
|
||||||
|
|
Loading…
Reference in New Issue