"use client"; import { useCallback, useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { useDisplay } from "yt-dlp-transcript-common/components/PrivacyProvider"; import { Button } from "@/components/ui/button"; import { Field, Input } from "@/components/ui/field"; import LinkPolicyPanel from "../report/LinkPolicyPanel"; import { InspectorFrame, SaidLine, announceManifestChanged, call, refusal, useOnManifestChanged, type InspectorProps, type Said } from "./shared"; // THE PROJECT'S PROVENANCE (umtool redesign L6, item 1; the owed provenance writer): where the cut's QRs open // (provenance.siteOrigin), the channel a clip with no `channel` of its own is from (provenance.channelSlug -- // `check` blocks without it), the sweep's display name (provenance.channel); and, under them, the link policy per // channel (LinkPolicyPanel, its own writer). PUT /api/report/provenance; `umtool provenance

set` is the twin. type Prov = { siteOrigin: string | null; channelSlug: string | null; channel: string | null }; type View = { provenance: Prov; channels: { slug: string; clips: number }[]; corpusChannels: string[]; sites: { origin: string; siteId: string; title: string | null }[]; token: string | null; }; const KEYS = ["siteOrigin", "channelSlug", "channel"] as const; export default function ProvenanceInspector({ project }: InspectorProps) { const router = useRouter(); // settings.privacy: a site's title as the suggestion DRAWS it (client-side). const { displayText } = useDisplay(); const [view, setView] = useState(null); const [draft, setDraft] = useState>({ siteOrigin: "", channelSlug: "", channel: "" }); const [busy, setBusy] = useState(false); const [said, setSaid] = useState(null); const [policyKey, setPolicyKey] = useState(0); const load = useCallback(async (reset = true) => { const { ok, j } = await call(`/api/report/provenance?project=${encodeURIComponent(project)}`); if (!ok) return null; setView(j); if (reset) setDraft({ siteOrigin: j.provenance.siteOrigin ?? "", channelSlug: j.provenance.channelSlug ?? "", channel: j.provenance.channel ?? "" }); return j; }, [project]); useEffect(() => { void load(); }, [load]); useOnManifestChanged(project, () => load(false)); if (!view) return null; const changed = KEYS.filter((k) => draft[k].trim() !== (view.provenance[k] ?? "")); const set = (k: (typeof KEYS)[number], v: string) => { setSaid(null); setDraft((d) => ({ ...d, [k]: v })); }; const save = async () => { setBusy(true); setSaid(null); try { const patch = Object.fromEntries(changed.map((k) => [k, draft[k].trim() || null])); const { ok, status, j } = await call<{ changed?: Record }>("/api/report/provenance", { method: "PUT", body: JSON.stringify({ project, token: view.token, patch }) }); if (!ok) { setSaid({ ok: false, text: refusal(j, status) }); if (j.stale) await load(); return; } await load(); setPolicyKey((n) => n + 1); setSaid({ ok: true, text: `Saved to the draft: ${Object.keys(j.changed ?? {}).join(", ") || "nothing changed"}.` }); announceManifestChanged(project); router.refresh(); } finally { setBusy(false); } }; const slugs = [...view.channels.map((c) => c.slug), ...view.corpusChannels.filter((s) => !view.channels.some((c) => c.slug === s))]; return (

set("siteOrigin", e.target.value)} /> set("channelSlug", e.target.value)} /> set("channel", e.target.value)} />
{view.sites.map((s) => ( ))} {slugs.map((s) => (
); }