Unverified Commit cd97ded2 authored by Hong Minhee's avatar Hong Minhee
Browse files

`fedify inbox`: Raw Activity tab

parent 56a936a1
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -56,6 +56,9 @@ To be released.
     -  `Service.clone()` method now accepts `service` option.
     -  `Service.clone()` method now accepts `services` option.

 -  In the `fedify inbox` command's web interface, the *Raw Activity* tab is
    added to show the raw JSON object of the received activity.

[FEP-c0e0]: https://w3id.org/fep/c0e0
[FEP-9091]: https://w3id.org/fep/9091
[#146]: https://github.com/dahlia/fedify/issues/146
+10 −0
Original line number Diff line number Diff line
@@ -39,6 +39,16 @@ export async function renderResponse(response: Response): Promise<string> {
  return code;
}

export async function renderRawActivity(request: Request): Promise<string> {
  request = request.clone();
  try {
    const activity = await request.json();
    return JSON.stringify(activity, null, 2);
  } catch {
    return "[Failed to decode body; it may not be JSON.]";
  }
}

export async function renderActivity(
  activity: Activity,
  expand: boolean = false,
+29 −4
Original line number Diff line number Diff line
import type { LogRecord } from "@logtape/logtape";
import { getStatusText } from "@poppanator/http-constants";
import type { FC, PropsWithChildren } from "hono/jsx";
import { getHighlighter } from "shiki";
import { getSingletonHighlighter } from "shiki";
import type { ActivityEntry } from "./entry.ts";
import { renderActivity, renderRequest, renderResponse } from "./rendercode.ts";
import {
  renderActivity,
  renderRawActivity,
  renderRequest,
  renderResponse,
} from "./rendercode.ts";

interface LayoutProps {
  title?: string;
@@ -103,7 +108,7 @@ interface CodeBlockProps {
  code: string;
}

const highlighter = await getHighlighter({
const highlighter = await getSingletonHighlighter({
  themes: ["github-light"],
  langs: ["http", "json"],
});
@@ -166,7 +171,13 @@ const LogList: FC<LogListProps> = ({ logs }: LogListProps) => {

interface ActivityEntryViewProps {
  entry: ActivityEntry;
  tabPage: string;
  tabPage:
    | "request"
    | "response"
    | "raw-activity"
    | "compact-activity"
    | "expanded-activity"
    | "logs";
}

const ActivityEntryView: FC<ActivityEntryViewProps> = async (
@@ -187,6 +198,12 @@ const ActivityEntryView: FC<ActivityEntryViewProps> = async (
          disabled={response == null}
          active={tabPage === "response"}
        />
        <Tab
          label="Raw Activity"
          href="?tab=raw-activity"
          disabled={activity == null}
          active={tabPage === "raw-activity"}
        />
        <Tab
          label="Compact Activity"
          href="?tab=compact-activity"
@@ -222,6 +239,14 @@ const ActivityEntryView: FC<ActivityEntryViewProps> = async (
          />
        </div>
      )}
      {tabPage === "raw-activity" && (
        <div class="tab-page">
          <CodeBlock
            code={await renderRawActivity(request)}
            language="json"
          />
        </div>
      )}
      {tabPage === "compact-activity" && activity != null && (
        <div class="tab-page">
          <CodeBlock