Fixed 267U.pre2

This commit is contained in:
2026-07-26 18:25:37 +09:00
parent 50bfaeafdf
commit 317d00a284
1286 changed files with 80222 additions and 1 deletions
@@ -0,0 +1,40 @@
import Resolver from "../../resolver.js";
import createNote from "./note.js";
import { getApId, isPost, getApType } from "../../type.js";
import { apLogger } from "../../logger.js";
import { toArray, concat, unique } from "../../../../prelude/array.js";
const logger = apLogger;
export default (async (actor, activity)=>{
const uri = getApId(activity);
logger.info(`Create: ${uri}`);
// copy audiences between activity <=> object.
if (typeof activity.object === "object") {
const to = unique(concat([
toArray(activity.to),
toArray(activity.object.to)
]));
const cc = unique(concat([
toArray(activity.cc),
toArray(activity.object.cc)
]));
activity.to = to;
activity.cc = cc;
activity.object.to = to;
activity.object.cc = cc;
}
// If there is no attributedTo, use Activity actor.
if (typeof activity.object === "object" && !activity.object.attributedTo) {
activity.object.attributedTo = activity.actor;
}
const resolver = new Resolver();
const object = await resolver.resolve(activity.object).catch((e)=>{
logger.error(`Resolution failed: ${e}`);
throw e;
});
if (isPost(object)) {
return createNote(resolver, actor, object, false, activity);
} else {
logger.warn(`Unknown type: ${getApType(object)}`);
return "skip: unknown create type";
}
});
@@ -0,0 +1,37 @@
import { createNote, fetchNote } from "../../models/note.js";
import { getApId } from "../../type.js";
import { getApLock } from "../../../../misc/app-lock.js";
import { extractDbHost } from "../../../../misc/convert-host.js";
import { StatusError } from "../../../../misc/fetch.js";
/**
* Handle post creation activity
*/ export default async function(resolver, actor, note, silent = false, activity) {
const uri = getApId(note);
if (typeof note === "object") {
if (actor.uri !== note.attributedTo) {
return "skip: actor.uri !== note.attributedTo";
}
if (typeof note.id === "string") {
if (extractDbHost(actor.uri) !== extractDbHost(note.id)) {
return "skip: host in actor.uri !== note.id";
}
} else {
return "skip: note.id is not a string";
}
}
const unlock = await getApLock(uri);
try {
const exist = await fetchNote(note);
if (exist) return "skip: note exists";
await createNote(note, resolver, silent);
return "ok";
} catch (e) {
if (e instanceof StatusError && !e.isRetryable) {
return `skip ${e.statusCode}`;
} else {
throw e;
}
} finally{
unlock();
}
}