forked from FoundKeyGang/FoundKey
refactor deliver to extract actor from activity
This commit is contained in:
parent
a786fd99fc
commit
ff4b6d932e
2 changed files with 10 additions and 2 deletions
|
@ -7,6 +7,7 @@ import { Webhook, webhookEventTypes } from '@/models/entities/webhook.js';
|
|||
import { IActivity } from '@/remote/activitypub/type.js';
|
||||
import { envOption } from '@/env.js';
|
||||
import { MINUTE } from '@/const.js';
|
||||
import { DbResolver } from '@/remote/activitypub/db-resolver.js';
|
||||
|
||||
import processDeliver from './processors/deliver.js';
|
||||
import processInbox from './processors/inbox.js';
|
||||
|
@ -83,10 +84,17 @@ webhookDeliverQueue
|
|||
.on('error', (job: any, err: Error) => webhookLogger.error(`error ${err}`, { job, e: renderError(err) }))
|
||||
.on('stalled', (job) => webhookLogger.warn(`stalled ${getJobInfo(job)} to=${job.data.to}`));
|
||||
|
||||
export function deliver(user: ThinUser, content: unknown, to: string | null) {
|
||||
export async function deliver(_user: ThinUser, content: unknown, to: string | null) {
|
||||
if (content == null) return null;
|
||||
if (to == null) return null;
|
||||
|
||||
// extract user from the Activity
|
||||
const userUri = content.actor;
|
||||
if (!userUri) throw new Error("Cannot deliver activity without actor.");
|
||||
const user = await new DbResolver().getUserFromApId(userUri);
|
||||
if (!user) throw new Error("Actor not found, cannot deliver.");
|
||||
if (user.host != null) throw new Error("Cannot deliver for remote actor.");
|
||||
|
||||
const data = {
|
||||
user: {
|
||||
id: user.id,
|
||||
|
|
|
@ -9,7 +9,7 @@ export type DeliverJobData = {
|
|||
/** Actor */
|
||||
user: ThinUser;
|
||||
/** Activity */
|
||||
content: unknown;
|
||||
content: IActivity;
|
||||
/** inbox URL to deliver */
|
||||
to: string;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue