forked from FoundKeyGang/FoundKey
refactor deliver to extract actor from activity
This commit is contained in:
parent
cec77dafa8
commit
071f4fa82a
3 changed files with 12 additions and 9 deletions
|
@ -88,9 +88,6 @@ export function deliver(user: ThinUser, content: unknown, to: string | null) {
|
|||
if (to == null) return null;
|
||||
|
||||
const data = {
|
||||
user: {
|
||||
id: user.id,
|
||||
},
|
||||
content,
|
||||
to,
|
||||
};
|
||||
|
|
|
@ -9,6 +9,7 @@ import { toPuny } from '@/misc/convert-host.js';
|
|||
import { StatusError } from '@/misc/fetch.js';
|
||||
import { shouldSkipInstance } from '@/misc/skipped-instances.js';
|
||||
import { DeliverJobData } from '@/queue/types.js';
|
||||
import { DbResolver } from '@/remote/activitypub/db-resolver.js';
|
||||
|
||||
const logger = new Logger('deliver');
|
||||
|
||||
|
@ -18,13 +19,20 @@ export default async (job: Bull.Job<DeliverJobData>) => {
|
|||
|
||||
if (await shouldSkipInstance(puny)) return 'skip';
|
||||
|
||||
// get user/actor for signing
|
||||
const userUri = job.data.content.actor;
|
||||
if (userUri == null) return 'error: missing actor';
|
||||
const user = await new DbResolver().getUserFromApId(userUri);
|
||||
if (user == null) return 'error: actor not found';
|
||||
if (user.host != null) return 'error: actor not local';
|
||||
|
||||
try {
|
||||
if (Array.isArray(job.data.content)) {
|
||||
await Promise.all(
|
||||
job.data.content.map(x => request(job.data.user, job.data.to, x))
|
||||
job.data.content.map(x => request(user, job.data.to, x))
|
||||
);
|
||||
} else {
|
||||
await request(job.data.user, job.data.to, job.data.content);
|
||||
await request(user, job.data.to, job.data.content);
|
||||
}
|
||||
|
||||
// Update stats
|
||||
|
|
|
@ -6,10 +6,8 @@ import { Webhook } from '@/models/entities/webhook.js';
|
|||
import { IActivity } from '@/remote/activitypub/type.js';
|
||||
|
||||
export type DeliverJobData = {
|
||||
/** Actor */
|
||||
user: ThinUser;
|
||||
/** Activity */
|
||||
content: unknown;
|
||||
/** Activity, containing the actor URI */
|
||||
content: IActivity;
|
||||
/** inbox URL to deliver */
|
||||
to: string;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue