"use client"; import { useEffect, useState } from "react"; import { badgeVariants } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Table, TD, TH } from "@/components/ui/table"; import { caseStageApi } from "@/lib/research/case-stage-hrefs"; import type { EvidenceRow, EvidenceView } from "@/lib/research/case-evidence"; // STAGE 10, EVIDENCE CAPTURE (release 38 lane C): Wayback captures of a target // list at chosen dates (a 403 is a row of its own: "excluded from the Wayback // Machine (cause unknown)"), and a forum post's attachments and screenshot, // marked "forum attachment, post #N, unverified" wherever they show. Every // capture is the editor's job, paced by it. const STATE_BADGE: Record = { planned: "info", queued: "state", captured: "neutral", excluded: "open", failed: "blocking", }; const iso = (d?: string) => (d && /^\d{8}/.test(d) ? `${d.slice(0, 4)}-${d.slice(4, 6)}-${d.slice(6, 8)}` : ""); async function call(url: string, init?: { method?: string; body?: unknown }): Promise { const res = await fetch(url, { method: init?.method ?? "GET", headers: init?.body !== undefined ? { "content-type": "application/json" } : undefined, body: init?.body !== undefined ? JSON.stringify(init.body) : undefined, cache: "no-store", }); const body = await res.json().catch(() => ({})); if (!res.ok) throw new Error(body?.error ?? `HTTP ${res.status}`); return body as T; } export default function EvidencePanel({ caseId, initial }: { caseId: string; initial: EvidenceView }) { const [view, setView] = useState(initial); const [error, setError] = useState(null); const [busy, setBusy] = useState(null); const [urls, setUrls] = useState(""); const [dates, setDates] = useState(""); const [forum, setForum] = useState(initial.forumChannels[0]?.slug ?? ""); const [post, setPost] = useState(""); const [into, setInto] = useState>({}); const act = async (key: string, body: Record) => { setBusy(key); setError(null); try { const r = await call<{ view: EvidenceView }>(caseStageApi(caseId, "evidence"), { method: "POST", body }); setView(r.view); return true; } catch (e) { setError((e as Error).message); return false; } finally { setBusy(null); } }; // A queued row is asked again every 1.5 s until its job ends. const queued = view.rows.filter((r) => r.state === "queued").map((r) => r.id).join(","); useEffect(() => { if (!queued) return; const t = setTimeout(async () => { for (const id of queued.split(",")) { try { const r = await call<{ view: EvidenceView }>(caseStageApi(caseId, "evidence"), { method: "POST", body: { action: "refresh", id } }); setView(r.view); } catch (e) { setError((e as Error).message); } } }, 1500); return () => clearTimeout(t); }, [caseId, queued, view]); const pagesChannel = (r: EvidenceRow) => into[r.id] ?? r.slug ?? view.pagesChannels[0]?.slug ?? "__new"; return (
{ e.preventDefault(); if (await act("add", { action: "add", urls: urls.split(/\s+/).filter(Boolean), dates: dates.split(/[\s,]+/).filter(Boolean) })) { setUrls(""); } }} >

Wayback captures at chosen dates