"use client";
import { useCallback, useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { Button } from "@/components/ui/button";
import { InspectorFrame, SaidLine, announceManifestChanged, call, refusal, useOnManifestChanged, type InspectorProps, type Said } from "./shared";
// THE RUMBLE CITE FIX (umtool redesign L6, item 5; 4 and 8 Nov: a Rumble clip's QR named the URL-slug folder the
// corpus keeps it under, and the archive serves the EMBED id -- 15/15 dead on quartering-midterms): each clip of
// the cut that cites such a folder, with its published embed id read from the folder's metadata through L1's one
// mapping, and "Use the published embed id" -- per row, and once for every dead Rumble row (every row only when no
// check has read any of them). It writes `siteVideo` (a citeUrl naming the folder moves with it): POST /api/report/embed-ids,
// one write, one undo point. No network; `umtool links
` checks the sites, `umtool links
--embed-ids` is
// this panel's twin. With `block`, only that clip's row.
type Row = { clip: string; channel: string | null; video: string; siteVideo: string; url: string | null; fixedUrl: string | null; citeUrl: string | null; state: string };
type View = { rows: Row[]; checkedAt: string | null; token: string | null };
export default function LinksInspector({ project, block = null }: InspectorProps) {
const router = useRouter();
const [view, setView] = useState(null);
const [busy, setBusy] = useState(false);
const [said, setSaid] = useState(null);
const load = useCallback(async () => {
const { ok, j } = await call(`/api/report/embed-ids?project=${encodeURIComponent(project)}`);
if (ok) setView(j);
return ok ? j : null;
}, [project]);
useEffect(() => {
void load();
}, [load]);
useOnManifestChanged(project, load);
if (!view) return null;
const rows = block ? view.rows.filter((r) => r.clip === block) : view.rows;
const dead = rows.filter((r) => r.state === "dead");
// Once a check has read these rows, "all" is the dead ones only (a row it found open is left as it is); with no
// check yet, every row.
const checked = rows.some((r) => r.state !== "unchecked");
const allOf = checked ? dead : rows;
const use = async (clips: string[]) => {
setBusy(true);
setSaid(null);
try {
const { ok, status, j } = await call<{ fixed?: { clip: string; siteVideo: string }[] }>("/api/report/embed-ids", { method: "POST", body: JSON.stringify({ project, token: view.token, clips }) });
if (!ok) {
setSaid({ ok: false, text: refusal(j, status) });
if (j.stale) await load();
return;
}
await load();
const fixed = j.fixed ?? [];
setSaid({ ok: true, text: `${fixed.map((f) => `${f.clip} → ${f.siteVideo}`).join(", ")}: saved to the draft — Check links on the Overview reads the site again.` });
announceManifestChanged(project);
router.refresh();
} finally {
setBusy(false);
}
};
return (
no dead links at the last check
) : allOf.length > 1 ? (
) : null
}
>
{rows.length === 0 ? (
Every clip names the id its archive serves{view.checkedAt ? ` (links last checked ${view.checkedAt.slice(0, 16).replace("T", " ")})` : ""}.