"use client"; import Link from "next/link"; import { useCallback, useEffect, useState } from "react"; import { badgeVariants } from "@/components/ui/badge"; import { buttonVariants } from "@/components/ui/button"; import { Panel } from "@/components/ui/panel"; import { fmtAgo, fmtBytes } from "@/lib/format"; import { clipEditorHref } from "@/lib/hrefs"; // THE SHORTS (release 36 lane C): `/shorts/.mp4`, each one // clip at 1080x1920 (the clip editor's Make a short). Play one here, download // it, or make it again (the old one is set aside, never overwritten). type Short = { clip: string; size: number; mtimeMs: number; stale: boolean; gone: boolean; record: { cut?: [number, number] | null; captions?: { lines: number } | null; loudness?: { target: number } | null } | null }; type Job = { id: string; state: string; error: string | null; kind?: string }; export default function ShortsList({ project }: { project: string }) { const [shorts, setShorts] = useState(null); const [job, setJob] = useState(null); const [playing, setPlaying] = useState(null); const [error, setError] = useState(null); const load = useCallback(async () => { const r = await fetch(`/api/report/shorts?project=${encodeURIComponent(project)}`, { cache: "no-store" }); const j = (await r.json()) as { shorts?: Short[]; running?: Job | null; error?: string }; if (!r.ok) throw new Error(j.error ?? `HTTP ${r.status}`); setShorts(j.shorts ?? []); if (j.running) setJob(j.running); }, [project]); useEffect(() => { load().catch((e) => setError(e instanceof Error ? e.message : String(e))); }, [load]); useEffect(() => { if (!job || job.state !== "running") return; const t = setInterval(async () => { const r = await fetch(`/api/report/shorts?job=${job.id}`, { cache: "no-store" }).catch(() => null); if (!r?.ok) return; const j = (await r.json()) as Job; setJob(j); if (j.state !== "running") await load().catch(() => {}); }, 1500); return () => clearInterval(t); }, [job, load]); const remake = async (clip: string) => { setError(null); const r = await fetch("/api/report/shorts", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, clip, replace: true }) }); const j = (await r.json().catch(() => ({}))) as { job?: Job; error?: string }; if (!r.ok || !j.job) setError(j.error ?? `HTTP ${r.status}`); else setJob(j.job); }; const cancel = async () => { if (!job) return; await fetch(`/api/report/shorts?cancel=${job.id}`, { method: "POST" }).catch(() => null); }; const file = (s: Short, extra = "") => `/api/report/shorts?project=${encodeURIComponent(project)}&clip=${encodeURIComponent(s.clip)}&file=1&v=${s.mtimeMs}${extra}`; const running = job?.state === "running"; return ( {shorts === null ? (

{error ?? "reading the shorts…"}

) : shorts.length === 0 && !running ? (

No shorts yet: the clip editor makes one of a clip (Make a short).{" "} Clip editor

) : (
    {shorts.map((s) => (
  • {s.clip} {fmtBytes(s.size)} · {fmtAgo(s.mtimeMs)} {s.record?.cut ? ` · ${(s.record.cut[1] - s.record.cut[0]).toFixed(1)} s` : ""} {s.stale && the clip moved since} {s.gone && no such clip now} Download {!s.gone && ( )} {!s.gone && ( Frame it )}
    {playing === s.clip && (
  • ))}
)} {job && (

{running ? `Making ${job.kind?.split(" ").at(-1) ?? "a short"}…` : job.state === "done" ? "Made." : `Failed${job.error ? `: ${job.error}` : ""}`} {running && ( )}

)} {error && shorts !== null && (

{error}

)}
); }