From 296eb9cce00db921304ecf8175925af2b3a73474 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Wed, 6 Mar 2024 01:06:34 +0900 Subject: [PATCH] Get rid of redundant documentLoader parameters --- federation/handler.ts | 13 ++++--------- federation/middleware.ts | 4 ---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/federation/handler.ts b/federation/handler.ts index 8612bf26..464bf110 100644 --- a/federation/handler.ts +++ b/federation/handler.ts @@ -1,6 +1,5 @@ import { accepts } from "jsr:@std/http@^0.218.2"; import { doesActorOwnKey, verify } from "../httpsig/mod.ts"; -import { DocumentLoader } from "../runtime/docloader.ts"; import { Activity, Link, @@ -97,7 +96,6 @@ export interface CollectionCallbacks { export interface CollectionHandlerParameters { handle: string; context: RequestContext; - documentLoader: DocumentLoader; collectionCallbacks?: CollectionCallbacks; onNotFound(request: Request): Response | Promise; onNotAcceptable(request: Request): Response | Promise; @@ -111,7 +109,6 @@ export async function handleCollection< { handle, context, - documentLoader, collectionCallbacks, onNotFound, onNotAcceptable, @@ -197,7 +194,7 @@ export async function handleCollection< } collection = new OrderedCollectionPage({ prev, next, items }); } - const jsonLd = await collection.toJsonLd({ documentLoader }); + const jsonLd = await collection.toJsonLd(context); return new Response(JSON.stringify(jsonLd), { headers: { "Content-Type": "application/activity+json", @@ -217,7 +214,6 @@ export interface InboxHandlerParameters { InboxListener >; inboxErrorHandler?: (error: Error) => void | Promise; - documentLoader: DocumentLoader; onNotFound(request: Request): Response | Promise; } @@ -231,7 +227,6 @@ export async function handleInbox( actorDispatcher, inboxListeners, inboxErrorHandler, - documentLoader, onNotFound, }: InboxHandlerParameters, ): Promise { @@ -247,7 +242,7 @@ export async function handleInbox( return response instanceof Promise ? await response : response; } } - const key = await verify(request, documentLoader); + const key = await verify(request, context.documentLoader); if (key == null) { const response = new Response("Failed to verify the request signature.", { status: 401, @@ -268,7 +263,7 @@ export async function handleInbox( } let activity: Activity; try { - activity = await Activity.fromJsonLd(json, { documentLoader }); + activity = await Activity.fromJsonLd(json, context); } catch (e) { const promise = inboxErrorHandler?.(e); if (promise instanceof Promise) await promise; @@ -297,7 +292,7 @@ export async function handleInbox( }); return response; } - if (!await doesActorOwnKey(activity, key, documentLoader)) { + if (!await doesActorOwnKey(activity, key, context.documentLoader)) { const response = new Response("The signer and the actor do not match.", { status: 401, headers: { "Content-Type": "text/plain; charset=utf-8" }, diff --git a/federation/middleware.ts b/federation/middleware.ts index feb7b47b..1fd0d44b 100644 --- a/federation/middleware.ts +++ b/federation/middleware.ts @@ -662,7 +662,6 @@ export class Federation { return await handleCollection(request, { handle: route.values.handle, context, - documentLoader: this.#documentLoader, collectionCallbacks: this.#outboxCallbacks, onNotFound, onNotAcceptable, @@ -674,7 +673,6 @@ export class Federation { context, kv: this.#kv, kvPrefix: this.#kvPrefixes.activityIdempotence, - documentLoader: this.#documentLoader, actorDispatcher: this.#actorCallbacks?.dispatcher, inboxListeners: this.#inboxListeners, inboxErrorHandler: this.#inboxErrorHandler, @@ -684,7 +682,6 @@ export class Federation { return await handleCollection(request, { handle: route.values.handle, context, - documentLoader: this.#documentLoader, collectionCallbacks: this.#followingCallbacks, onNotFound, onNotAcceptable, @@ -693,7 +690,6 @@ export class Federation { return await handleCollection(request, { handle: route.values.handle, context, - documentLoader: this.#documentLoader, collectionCallbacks: this.#followersCallbacks, onNotFound, onNotAcceptable,