handle mastodon style posts
This commit is contained in:
parent
7650c60cdf
commit
21c7f93d7a
|
@ -8,6 +8,7 @@ import { Users, DriveFiles } from "@/models/index.js";
|
|||
import type { DbUserImportJobData } from "@/queue/types.js";
|
||||
import { queueLogger } from "../../logger.js";
|
||||
import type Bull from "bull";
|
||||
import { htmlToMfm } from "@/remote/activitypub/misc/html-to-mfm.js";
|
||||
|
||||
const logger = queueLogger.createSubLogger("import-posts");
|
||||
|
||||
|
@ -36,6 +37,8 @@ export async function importPosts(
|
|||
let linenum = 0;
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(json);
|
||||
if (parsed instanceof Array) {
|
||||
for (const post of JSON.parse(json)) {
|
||||
try {
|
||||
linenum++;
|
||||
|
@ -75,6 +78,38 @@ export async function importPosts(
|
|||
logger.warn(`Error in line:${linenum} ${e}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const post of parsed.orderedItems) {
|
||||
linenum++;
|
||||
if (post.inReplyTo != null) {
|
||||
logger.info(`Is reply, skip [${linenum}] ...`);
|
||||
continue;
|
||||
}
|
||||
if (post.directMessage) {
|
||||
logger.info(`Is dm, skip [${linenum}] ...`);
|
||||
continue;
|
||||
}
|
||||
const text = htmlToMfm(post.content, post.tag);
|
||||
logger.info(`Posting[${linenum}] ...`);
|
||||
|
||||
const note = await create(user, {
|
||||
createdAt: new Date(post.published),
|
||||
files: undefined,
|
||||
poll: undefined,
|
||||
text: text || undefined,
|
||||
reply: null,
|
||||
renote: null,
|
||||
cw: post.sensitive,
|
||||
localOnly: false,
|
||||
visibility: "public",
|
||||
visibleUsers: [],
|
||||
channel: null,
|
||||
apMentions: null,
|
||||
apHashtags: undefined,
|
||||
apEmojis: undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// handle error
|
||||
logger.warn(`Error reading: ${e}`);
|
||||
|
|
|
@ -112,13 +112,13 @@ export async function createNote(
|
|||
const note: IPost = object;
|
||||
|
||||
if (note.id && !note.id.startsWith("https://")) {
|
||||
throw new Error(`unexpected shcema of note.id: ${note.id}`);
|
||||
throw new Error(`unexpected schema of note.id: ${note.id}`);
|
||||
}
|
||||
|
||||
const url = getOneApHrefNullable(note.url);
|
||||
|
||||
if (url && !url.startsWith("https://")) {
|
||||
throw new Error(`unexpected shcema of note url: ${url}`);
|
||||
throw new Error(`unexpected schema of note url: ${url}`);
|
||||
}
|
||||
|
||||
logger.debug(`Note fetched: ${JSON.stringify(note, null, 2)}`);
|
||||
|
|
Loading…
Reference in New Issue