Skip to content

Commit

Permalink
Get rid of redundant documentLoader parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Mar 5, 2024
1 parent 4038e5e commit 296eb9c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
13 changes: 4 additions & 9 deletions federation/handler.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -97,7 +96,6 @@ export interface CollectionCallbacks<TItem, TContextData> {
export interface CollectionHandlerParameters<TItem, TContextData> {
handle: string;
context: RequestContext<TContextData>;
documentLoader: DocumentLoader;
collectionCallbacks?: CollectionCallbacks<TItem, TContextData>;
onNotFound(request: Request): Response | Promise<Response>;
onNotAcceptable(request: Request): Response | Promise<Response>;
Expand All @@ -111,7 +109,6 @@ export async function handleCollection<
{
handle,
context,
documentLoader,
collectionCallbacks,
onNotFound,
onNotAcceptable,
Expand Down Expand Up @@ -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",
Expand All @@ -217,7 +214,6 @@ export interface InboxHandlerParameters<TContextData> {
InboxListener<TContextData, Activity>
>;
inboxErrorHandler?: (error: Error) => void | Promise<void>;
documentLoader: DocumentLoader;
onNotFound(request: Request): Response | Promise<Response>;
}

Expand All @@ -231,7 +227,6 @@ export async function handleInbox<TContextData>(
actorDispatcher,
inboxListeners,
inboxErrorHandler,
documentLoader,
onNotFound,
}: InboxHandlerParameters<TContextData>,
): Promise<Response> {
Expand All @@ -247,7 +242,7 @@ export async function handleInbox<TContextData>(
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,
Expand All @@ -268,7 +263,7 @@ export async function handleInbox<TContextData>(
}
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;
Expand Down Expand Up @@ -297,7 +292,7 @@ export async function handleInbox<TContextData>(
});
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" },
Expand Down
4 changes: 0 additions & 4 deletions federation/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ export class Federation<TContextData> {
return await handleCollection(request, {
handle: route.values.handle,
context,
documentLoader: this.#documentLoader,
collectionCallbacks: this.#outboxCallbacks,
onNotFound,
onNotAcceptable,
Expand All @@ -674,7 +673,6 @@ export class Federation<TContextData> {
context,
kv: this.#kv,
kvPrefix: this.#kvPrefixes.activityIdempotence,
documentLoader: this.#documentLoader,
actorDispatcher: this.#actorCallbacks?.dispatcher,
inboxListeners: this.#inboxListeners,
inboxErrorHandler: this.#inboxErrorHandler,
Expand All @@ -684,7 +682,6 @@ export class Federation<TContextData> {
return await handleCollection(request, {
handle: route.values.handle,
context,
documentLoader: this.#documentLoader,
collectionCallbacks: this.#followingCallbacks,
onNotFound,
onNotAcceptable,
Expand All @@ -693,7 +690,6 @@ export class Federation<TContextData> {
return await handleCollection(request, {
handle: route.values.handle,
context,
documentLoader: this.#documentLoader,
collectionCallbacks: this.#followersCallbacks,
onNotFound,
onNotAcceptable,
Expand Down

0 comments on commit 296eb9c

Please sign in to comment.