Commit 72f8a9d3 authored by Kim, Hyeonseo's avatar Kim, Hyeonseo Committed by Hyeonseo Kim
Browse files

feat: add WebFingerLinkDispatcher support in FederationBuilder

parent 89aafe97
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import type {
  ObjectAuthorizePredicate,
  ObjectDispatcher,
  SharedInboxKeyDispatcher,
  WebFingerLinkDispatcher,
} from "./callback.ts";
import type { Context, RequestContext } from "./context.ts";
import type {
@@ -48,6 +49,7 @@ export class FederationBuilderImpl<TContextData>
  router: Router;
  actorCallbacks?: ActorCallbacks<TContextData>;
  nodeInfoDispatcher?: NodeInfoDispatcher<TContextData>;
  webFingerDispatcher?: WebFingerLinkDispatcher<TContextData>;
  objectCallbacks: Record<string, ObjectCallbacks<TContextData, string>>;
  objectTypeIds: Record<
    string,
@@ -148,6 +150,7 @@ export class FederationBuilderImpl<TContextData>
      ? undefined
      : { ...this.actorCallbacks };
    f.nodeInfoDispatcher = this.nodeInfoDispatcher;
    f.webFingerDispatcher = this.webFingerDispatcher;
    f.objectCallbacks = { ...this.objectCallbacks };
    f.objectTypeIds = { ...this.objectTypeIds };
    f.inboxPath = this.inboxPath;
@@ -491,6 +494,12 @@ export class FederationBuilderImpl<TContextData>
    this.nodeInfoDispatcher = dispatcher;
  }

  setWebFingerLinkDispatcher(
    dispatcher: WebFingerLinkDispatcher<TContextData>,
  ): void {
    this.webFingerDispatcher = dispatcher;
  }

  setObjectDispatcher<TObject extends Object, TParam extends string>(
    // deno-lint-ignore no-explicit-any
    cls: (new (...args: any[]) => TObject) & { typeId: URL },
+10 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import type { NodeInfo } from "../nodeinfo/types.ts";
import type { Actor } from "../vocab/actor.ts";
import type { Activity, CryptographicKey } from "../vocab/mod.ts";
import type { Object } from "../vocab/vocab.ts";
import type { Link } from "../webfinger/mod.ts";
import type { PageItems } from "./collection.ts";
import type { Context, InboxContext, RequestContext } from "./context.ts";
import type { SenderKeyPair } from "./send.ts";
@@ -15,6 +16,15 @@ export type NodeInfoDispatcher<TContextData> = (
  context: RequestContext<TContextData>,
) => NodeInfo | Promise<NodeInfo>;

/**
 * A callback that dispatches a array of {@link Link}.
 *
 * @template TContextData The context data to pass to the {@link Context}.
 */
export type WebFingerLinkDispatcher<TContextData> = (
  context: RequestContext<TContextData>,
) => Link[] | Promise<Link[]>;

/**
 * A callback that dispatches an {@link Actor} object.
 *
+9 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import type {
  ObjectDispatcher,
  OutboxErrorHandler,
  SharedInboxKeyDispatcher,
  WebFingerLinkDispatcher,
} from "./callback.ts";
import type { Context, RequestContext } from "./context.ts";
import type { KvStore } from "./kv.ts";
@@ -79,6 +80,14 @@ export interface Federatable<TContextData> {
    dispatcher: NodeInfoDispatcher<TContextData>,
  ): void;

  /**
   * Registers a links dispatcher to WebFinger
   * @param dispatcher A links dispatcher callback to register.
   */
  setWebFingerLinkDispatcher(
    dispatcher: WebFingerLinkDispatcher<TContextData>,
  ): void;

  /**
   * Registers an actor dispatcher.
   *