mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-23 02:17:40 -07:00
why is this git ignored?
This commit is contained in:
parent
624f305d9c
commit
c05703001c
1 changed files with 76 additions and 0 deletions
76
packages/backend/src/queue/processors/db/import-posts.ts
Normal file
76
packages/backend/src/queue/processors/db/import-posts.ts
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
import { IsNull } from "typeorm";
|
||||||
|
import follow from "@/services/following/create.js";
|
||||||
|
|
||||||
|
import * as Post from "@/misc/posts.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 { queueLogger } from "../../logger.js";
|
||||||
|
import type Bull from "bull";
|
||||||
|
|
||||||
|
const logger = queueLogger.createSubLogger("import-posts");
|
||||||
|
|
||||||
|
export async function importPosts(
|
||||||
|
job: Bull.Job<DbUserImportJobData>,
|
||||||
|
done: any,
|
||||||
|
): Promise<void> {
|
||||||
|
logger.info(`Importing following of ${job.data.user.id} ...`);
|
||||||
|
|
||||||
|
const user = await Users.findOneBy({ id: job.data.user.id });
|
||||||
|
if (user == null) {
|
||||||
|
done();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = await DriveFiles.findOneBy({
|
||||||
|
id: job.data.fileId,
|
||||||
|
});
|
||||||
|
if (file == null) {
|
||||||
|
done();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const csv = await downloadTextFile(file.url);
|
||||||
|
|
||||||
|
let linenum = 0;
|
||||||
|
|
||||||
|
if (file.type.endsWith("json")) {
|
||||||
|
for (const post of JSON.parse(csv)) {
|
||||||
|
try {
|
||||||
|
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: "public",
|
||||||
|
visibleUsers: [],
|
||||||
|
channel: null,
|
||||||
|
apMentions: undefined,
|
||||||
|
apHashtags: undefined,
|
||||||
|
apEmojis: undefined,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn(`Error in line:${linenum} ${e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.succ("Imported");
|
||||||
|
done();
|
||||||
|
}
|
Loading…
Reference in a new issue