From 507b328fdf649112c1896a5c1ffac462da73a10f Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sat, 10 Dec 2022 11:20:56 +0100 Subject: [PATCH] activitypub: also forward resolver to resolveNote --- packages/backend/src/remote/activitypub/kernel/add/index.ts | 5 +++-- .../backend/src/remote/activitypub/kernel/announce/note.ts | 2 +- packages/backend/src/remote/activitypub/kernel/index.ts | 2 +- .../backend/src/remote/activitypub/kernel/remove/index.ts | 5 +++-- packages/backend/src/remote/activitypub/models/note.ts | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/remote/activitypub/kernel/add/index.ts b/packages/backend/src/remote/activitypub/kernel/add/index.ts index e3ae01ef2..f78ddf138 100644 --- a/packages/backend/src/remote/activitypub/kernel/add/index.ts +++ b/packages/backend/src/remote/activitypub/kernel/add/index.ts @@ -2,8 +2,9 @@ import { CacheableRemoteUser } from '@/models/entities/user.js'; import { addPinned } from '@/services/i/pin.js'; import { resolveNote } from '@/remote/activitypub/models/note.js'; import { IAdd } from '@/remote/activitypub/type.js'; +import Resolver from '@/remote/activitypub/resolver.js'; -export default async (actor: CacheableRemoteUser, activity: IAdd): Promise => { +export default async (actor: CacheableRemoteUser, activity: IAdd, resolver: Resolver): Promise => { if ('actor' in activity && actor.uri !== activity.actor) { throw new Error('invalid actor'); } @@ -13,7 +14,7 @@ export default async (actor: CacheableRemoteUser, activity: IAdd): Promise } if (activity.target === actor.featured) { - const note = await resolveNote(activity.object); + const note = await resolveNote(activity.object, resolver); if (note == null) throw new Error('note not found'); await addPinned(actor, note.id); return; diff --git a/packages/backend/src/remote/activitypub/kernel/announce/note.ts b/packages/backend/src/remote/activitypub/kernel/announce/note.ts index 82c232bce..f1fb80bbd 100644 --- a/packages/backend/src/remote/activitypub/kernel/announce/note.ts +++ b/packages/backend/src/remote/activitypub/kernel/announce/note.ts @@ -33,7 +33,7 @@ export default async function(resolver: Resolver, actor: CacheableRemoteUser, ac // resolve the announce target let renote; try { - renote = await resolveNote(targetUri); + renote = await resolveNote(targetUri, resolver); } catch (e) { // skip if the target returns a HTTP client error if (e instanceof StatusError) { diff --git a/packages/backend/src/remote/activitypub/kernel/index.ts b/packages/backend/src/remote/activitypub/kernel/index.ts index d1c1199b7..59e9a56a5 100644 --- a/packages/backend/src/remote/activitypub/kernel/index.ts +++ b/packages/backend/src/remote/activitypub/kernel/index.ts @@ -53,7 +53,7 @@ async function performOneActivity(actor: CacheableRemoteUser, activity: IObject, } else if (isReject(activity)) { await reject(actor, activity, resolver); } else if (isAdd(activity)) { - await add(actor, activity).catch(err => apLogger.error(err)); + await add(actor, activity, resolver).catch(err => apLogger.error(err)); } else if (isRemove(activity)) { await remove(actor, activity).catch(err => apLogger.error(err)); } else if (isAnnounce(activity)) { diff --git a/packages/backend/src/remote/activitypub/kernel/remove/index.ts b/packages/backend/src/remote/activitypub/kernel/remove/index.ts index 5ff71c91f..8c36de4d8 100644 --- a/packages/backend/src/remote/activitypub/kernel/remove/index.ts +++ b/packages/backend/src/remote/activitypub/kernel/remove/index.ts @@ -2,8 +2,9 @@ import { CacheableRemoteUser } from '@/models/entities/user.js'; import { removePinned } from '@/services/i/pin.js'; import { IRemove } from '../../type.js'; import { resolveNote } from '../../models/note.js'; +import Resolver from '@/remote/activitypub/resolver.js'; -export default async (actor: CacheableRemoteUser, activity: IRemove): Promise => { +export default async (actor: CacheableRemoteUser, activity: IRemove, resolver: Resolver): Promise => { if ('actor' in activity && actor.uri !== activity.actor) { throw new Error('invalid actor'); } @@ -13,7 +14,7 @@ export default async (actor: CacheableRemoteUser, activity: IRemove): Promise => { if (typeof uri !== 'string' || !uri.match(/^https?:/)) return { status: 'permerror' }; try { - const res = await resolveNote(uri); + const res = await resolveNote(uri, resolver); if (res) { return { status: 'ok', @@ -266,7 +266,7 @@ export async function createNote(value: string | IObject, resolver: Resolver, si * If the target Note is registered in FoundKey, return it; otherwise, fetch it from a remote server and return it. * Fetch the Note from the remote server, register it in FoundKey, and return it. */ -export async function resolveNote(value: string | IObject, resolver?: Resolver): Promise { +export async function resolveNote(value: string | IObject, resolver: Resolver): Promise { const uri = typeof value === 'string' ? value : value.id; if (uri == null) throw new Error('missing uri');