Unverified Commit 841d94c5 authored by Hong Minhee's avatar Hong Minhee
Browse files

cli: Improved compat of inbox with Mitra

parent a509d6af
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -119,12 +119,16 @@ To be released.
     -  Ephemeral actors now have the following properties: `summary`,
        `following`, `followers`, `outbox`, `manuallyApprovesFollowers`, and
        `url`.
     -  Improved the compatibility of the `fedify inbox` command with Misskey
        and Mitra.

 -  Added more log messages using the [LogTape] library.  Currently the below
    logger categories are used:

     -  `["fedify", "sig", "proof"]`
     -  `["fedify", "sig", "key"]`
     -  `["fedify", "vocab", "lookup"]`
     -  `["fedify", "webfinger", "lookup"]`

[#54]: https://github.com/dahlia/fedify/issues/54
[#55]: https://github.com/dahlia/fedify/issues/55
+2 −2
Original line number Diff line number Diff line
@@ -141,8 +141,7 @@ federation
        url: new URL("https://fedify.dev/logo.png"),
        mediaType: "image/png",
      }),
      publicKeys: (await ctx.getActorKeyPairs(handle))
        .map((pair) => pair.cryptographicKey),
      publicKey: (await ctx.getActorKeyPairs(handle))[0].cryptographicKey,
      assertionMethods: (await ctx.getActorKeyPairs(handle))
        .map((pair) => pair.multikey),
      url: ctx.getActorUri(handle),
@@ -209,6 +208,7 @@ federation
        { handle },
        follower,
        new Accept({
          id: new URL(`#accepts/${follower.id?.href}`, ctx.getActorUri("i")),
          actor: ctx.getActorUri(handle),
          object: activity.id,
        }),
+13 −7
Original line number Diff line number Diff line
import { getLogger } from "@logtape/logtape";
import {
  type DocumentLoader,
  fetchDocumentLoader,
@@ -5,6 +6,8 @@ import {
import { lookupWebFinger } from "../webfinger/lookup.ts";
import { Object } from "./vocab.ts";

const logger = getLogger(["fedify", "vocab", "lookup"]);

/**
 * Options for the `lookupObject` function.
 *
@@ -73,8 +76,8 @@ export async function lookupObject(
    try {
      const remoteDoc = await documentLoader(identifier.href);
      document = remoteDoc.document;
    } catch (_) {
      // Silently ignore errors.
    } catch (error) {
      logger.debug("Failed to fetch remote document:\n{error}", { error });
    }
  }
  if (document == null) {
@@ -91,8 +94,8 @@ export async function lookupObject(
        const remoteDoc = await documentLoader(l.href);
        document = remoteDoc.document;
        break;
      } catch (_) {
        // Silently ignore errors.
      } catch (error) {
        logger.debug("Failed to fetch remote document:\n{error}", { error });
        continue;
      }
    }
@@ -103,8 +106,11 @@ export async function lookupObject(
      documentLoader,
      contextLoader: options.contextLoader,
    });
  } catch (e) {
    if (e instanceof TypeError) return null;
    throw e;
  } catch (error) {
    if (error instanceof TypeError) {
      logger.debug("Failed to parse JSON-LD document:\n{error}", { error });
      return null;
    }
    throw error;
  }
}
+25 −2
Original line number Diff line number Diff line
import { getLogger } from "@logtape/logtape";
import type { ResourceDescriptor } from "./jrd.ts";

const logger = getLogger(["fedify", "webfinger", "lookup"]);

/**
 * Looks up a WebFinger resource.
 * @param resource The resource URL to look up.
@@ -22,6 +25,10 @@ export async function lookupWebFinger(
  let url = new URL(`https://${server}/.well-known/webfinger`);
  url.searchParams.set("resource", resource.href);
  while (true) {
    logger.debug(
      "Fetching WebFinger resource descriptor from {url}...",
      { url: url.href },
    );
    const response = await fetch(url, {
      headers: { Accept: "application/jrd+json" },
      redirect: "manual",
@@ -33,11 +40,27 @@ export async function lookupWebFinger(
      url = new URL(response.headers.get("Location")!);
      continue;
    }
    if (!response.ok) return null;
    if (!response.ok) {
      logger.debug(
        "Failed to fetch WebFinger resource descriptor: {status} {statusText}.",
        {
          url: url.href,
          status: response.status,
          statusText: response.statusText,
        },
      );
      return null;
    }
    try {
      return await response.json() as ResourceDescriptor;
    } catch (e) {
      if (e instanceof SyntaxError) return null;
      if (e instanceof SyntaxError) {
        logger.debug(
          "Failed to parse WebFinger resource descriptor as JSON: {error}",
          { error: e },
        );
        return null;
      }
      throw e;
    }
  }