Skip to content

Commit 712515f

Browse files
dodok8dahlia
andcommitted
change: WebFingerLinkDispatcher to WebFingerLinksDispatcher
Co-authored-by: Hong Minhee (洪 民憙) <[email protected]>
1 parent 1b29a6e commit 712515f

File tree

7 files changed

+27
-26
lines changed

7 files changed

+27
-26
lines changed

packages/fedify/src/federation/builder.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
ObjectAuthorizePredicate,
2323
ObjectDispatcher,
2424
SharedInboxKeyDispatcher,
25-
WebFingerLinkDispatcher,
25+
WebFingerLinksDispatcher,
2626
} from "./callback.ts";
2727
import type { Context, RequestContext } from "./context.ts";
2828
import type {
@@ -49,7 +49,7 @@ export class FederationBuilderImpl<TContextData>
4949
router: Router;
5050
actorCallbacks?: ActorCallbacks<TContextData>;
5151
nodeInfoDispatcher?: NodeInfoDispatcher<TContextData>;
52-
webFingerDispatcher?: WebFingerLinkDispatcher<TContextData>;
52+
webFingerLinksDispatcher?: WebFingerLinksDispatcher<TContextData>;
5353
objectCallbacks: Record<string, ObjectCallbacks<TContextData, string>>;
5454
objectTypeIds: Record<
5555
string,
@@ -150,7 +150,7 @@ export class FederationBuilderImpl<TContextData>
150150
? undefined
151151
: { ...this.actorCallbacks };
152152
f.nodeInfoDispatcher = this.nodeInfoDispatcher;
153-
f.webFingerDispatcher = this.webFingerDispatcher;
153+
f.webFingerLinksDispatcher = this.webFingerLinksDispatcher;
154154
f.objectCallbacks = { ...this.objectCallbacks };
155155
f.objectTypeIds = { ...this.objectTypeIds };
156156
f.inboxPath = this.inboxPath;
@@ -494,10 +494,10 @@ export class FederationBuilderImpl<TContextData>
494494
this.nodeInfoDispatcher = dispatcher;
495495
}
496496

497-
setWebFingerLinkDispatcher(
498-
dispatcher: WebFingerLinkDispatcher<TContextData>,
497+
setWebFingerLinksDispatcher(
498+
dispatcher: WebFingerLinksDispatcher<TContextData>,
499499
): void {
500-
this.webFingerDispatcher = dispatcher;
500+
this.webFingerLinksDispatcher = dispatcher;
501501
}
502502

503503
setObjectDispatcher<TObject extends Object, TParam extends string>(

packages/fedify/src/federation/callback.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ export type NodeInfoDispatcher<TContextData> = (
2121
*
2222
* @template TContextData The context data to pass to the {@link Context}.
2323
*/
24-
export type WebFingerLinkDispatcher<TContextData> = (
24+
export type WebFingerLinksDispatcher<TContextData> = (
2525
context: RequestContext<TContextData>,
26-
) => Link[] | Promise<Link[]>;
26+
resource: URL,
27+
) => readonly Link[] | Promise<readonly Link[]>;
2728

2829
/**
2930
* A callback that dispatches an {@link Actor} object.

packages/fedify/src/federation/federation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type {
2828
ObjectDispatcher,
2929
OutboxErrorHandler,
3030
SharedInboxKeyDispatcher,
31-
WebFingerLinkDispatcher,
31+
WebFingerLinksDispatcher,
3232
} from "./callback.ts";
3333
import type { Context, RequestContext } from "./context.ts";
3434
import type { KvStore } from "./kv.ts";
@@ -84,8 +84,8 @@ export interface Federatable<TContextData> {
8484
* Registers a links dispatcher to WebFinger
8585
* @param dispatcher A links dispatcher callback to register.
8686
*/
87-
setWebFingerLinkDispatcher(
88-
dispatcher: WebFingerLinkDispatcher<TContextData>,
87+
setWebFingerLinksDispatcher(
88+
dispatcher: WebFingerLinksDispatcher<TContextData>,
8989
): void;
9090

9191
/**

packages/fedify/src/federation/middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import {
1616
ATTR_HTTP_RESPONSE_STATUS_CODE,
1717
ATTR_URL_FULL,
1818
} from "@opentelemetry/semantic-conventions";
19+
import metadata from "../../deno.json" with { type: "json" };
1920
import { getDefaultActivityTransformers } from "../compat/transformers.ts";
2021
import type { ActivityTransformer } from "../compat/types.ts";
21-
import metadata from "../../deno.json" with { type: "json" };
2222
import { getNodeInfo, type GetNodeInfoOptions } from "../nodeinfo/client.ts";
2323
import { handleNodeInfo, handleNodeInfoJrd } from "../nodeinfo/handler.ts";
2424
import type { JsonValue, NodeInfo } from "../nodeinfo/types.ts";
@@ -1280,7 +1280,7 @@ export class FederationImpl<TContextData>
12801280
actorDispatcher: this.actorCallbacks?.dispatcher,
12811281
actorHandleMapper: this.actorCallbacks?.handleMapper,
12821282
actorAliasMapper: this.actorCallbacks?.aliasMapper,
1283-
webFingerLinkDispatcher: this.webFingerDispatcher,
1283+
webFingerLinksDispatcher: this.webFingerLinksDispatcher,
12841284
onNotFound,
12851285
tracer,
12861286
});

packages/fedify/src/webfinger/handler.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
ActorAliasMapper,
44
ActorDispatcher,
55
ActorHandleMapper,
6-
WebFingerLinkDispatcher,
6+
WebFingerLinksDispatcher,
77
} from "../federation/callback.ts";
88
import type { RequestContext } from "../federation/context.ts";
99
import { MemoryKvStore } from "../federation/kv.ts";
@@ -540,8 +540,8 @@ test("handleWebFinger()", async (t) => {
540540
assertEquals(await response.json(), expectedForHostnameWithPort);
541541
});
542542

543-
await t.step("webFingerLinkDispatcher", async () => {
544-
const webFingerLinkDispatcher: WebFingerLinkDispatcher<void> = (_ctx) => {
543+
await t.step("webFingerLinksDispatcher", async () => {
544+
const webFingerLinksDispatcher: WebFingerLinksDispatcher<void> = (_ctx) => {
545545
return [
546546
{
547547
rel: "http://ostatus.org/schema/1.0/subscribe",
@@ -557,7 +557,7 @@ test("handleWebFinger()", async (t) => {
557557
const response = await handleWebFinger(request, {
558558
context,
559559
actorDispatcher,
560-
webFingerLinkDispatcher,
560+
webFingerLinksDispatcher,
561561
onNotFound,
562562
});
563563

packages/fedify/src/webfinger/handler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
ActorAliasMapper,
77
ActorDispatcher,
88
ActorHandleMapper,
9-
WebFingerLinkDispatcher,
9+
WebFingerLinksDispatcher,
1010
} from "../federation/callback.ts";
1111
import type { RequestContext } from "../federation/context.ts";
1212
import { Link as LinkObject } from "../vocab/mod.ts";
@@ -51,7 +51,7 @@ export interface WebFingerHandlerParameters<TContextData> {
5151
/**
5252
* The callback for dispatching the Links of webFinger.
5353
*/
54-
webFingerLinkDispatcher?: WebFingerLinkDispatcher<TContextData>;
54+
webFingerLinksDispatcher?: WebFingerLinksDispatcher<TContextData>;
5555

5656
/**
5757
* The function to call when the actor is not found.
@@ -118,7 +118,7 @@ async function handleWebFingerInternal<TContextData>(
118118
actorAliasMapper,
119119
onNotFound,
120120
span,
121-
webFingerLinkDispatcher,
121+
webFingerLinksDispatcher,
122122
}: WebFingerHandlerParameters<TContextData>,
123123
): Promise<Response> {
124124
if (actorDispatcher == null) {
@@ -231,8 +231,8 @@ async function handleWebFingerInternal<TContextData>(
231231
links.push(link);
232232
}
233233

234-
if (webFingerLinkDispatcher != null) {
235-
const customLinks = await webFingerLinkDispatcher(context);
234+
if (webFingerLinksDispatcher != null) {
235+
const customLinks = await webFingerLinksDispatcher(context, context.url);
236236
if (customLinks != null) {
237237
for (const link of customLinks) {
238238
links.push(link);

packages/testing/src/mock.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {
2121
SendActivityOptions,
2222
SendActivityOptionsForCollection,
2323
SenderKeyPair,
24-
WebFingerLinkDispatcher,
24+
WebFingerLinksDispatcher,
2525
} from "@fedify/fedify/federation";
2626
import type { JsonValue, NodeInfo } from "@fedify/fedify/nodeinfo";
2727
import type { DocumentLoader } from "@fedify/fedify/runtime";
@@ -109,7 +109,7 @@ export class MockFederation<TContextData> implements Federation<TContextData> {
109109
private activeQueues: Set<"inbox" | "outbox" | "fanout"> = new Set();
110110
public sentCounter = 0;
111111
private nodeInfoDispatcher?: NodeInfoDispatcher<TContextData>;
112-
private webFingerDispatcher?: WebFingerLinkDispatcher<TContextData>;
112+
private webFingerDispatcher?: WebFingerLinksDispatcher<TContextData>;
113113
private actorDispatchers: Map<string, ActorDispatcher<TContextData>> =
114114
new Map();
115115
public actorPath?: string;
@@ -192,8 +192,8 @@ export class MockFederation<TContextData> implements Federation<TContextData> {
192192
this.nodeInfoPath = path;
193193
}
194194

195-
setWebFingerLinkDispatcher(
196-
dispatcher: WebFingerLinkDispatcher<TContextData>,
195+
setWebFingerLinksDispatcher(
196+
dispatcher: WebFingerLinksDispatcher<TContextData>,
197197
): void {
198198
this.webFingerDispatcher = dispatcher;
199199
}

0 commit comments

Comments
 (0)