import { readdir, stat } from "node:fs/promises"; import path from "node:path"; import CopyButton from "@/components/CopyButton"; import { fmtBytes } from "@/lib/format"; import { latestWorkingTake } from "@/lib/report/workingCut.mjs"; import { listTakes } from "@/lib/report/takes.mjs"; import PlayLink from "../PlayLink"; // --------------------------------------------------------------------------- // OUTPUT FILES, AS LOCAL PATHS (lane/ui-simplify, 5 Nov; the operator's rule: // "output files get local paths (absolute), never an /api/... download URL // shown as the place a file is"). The newest take's rendered mp4s first -- // takes//out/.mp4 and its ladder -- then the newest few other takes', // then the build's out/.mp4: each an absolute path with Copy. // --------------------------------------------------------------------------- type File = { path: string; bytes: number; mtimeMs: number }; async function mp4sIn(dir: string): Promise { const names = await readdir(dir).catch(() => [] as string[]); const out: File[] = []; for (const n of names) { if (!n.endsWith(".mp4")) continue; const f = path.join(dir, n); const st = await stat(f).catch(() => null); if (st?.isFile() && st.size > 0) out.push({ path: f, bytes: st.size, mtimeMs: st.mtimeMs }); } return out.sort((a, b) => a.path.localeCompare(b.path)); } export default async function OutputFiles({ project, dir }: { project: string; dir: string }) { const listing = await listTakes(dir); const takes = (listing.takes as { id: string; builtAt?: string | null; label?: string }[]).filter((t) => t.builtAt).sort((a, b) => String(b.builtAt).localeCompare(String(a.builtAt))); const latest = latestWorkingTake(listing.takes as never[]) as { id: string } | null; const order = latest ? [takes.find((t) => t.id === latest.id)!, ...takes.filter((t) => t.id !== latest.id)].filter(Boolean) : takes; const rows = await Promise.all(order.slice(0, 4).map(async (t) => ({ take: t, files: await mp4sIn(path.join(dir, "takes", t.id, "out")) }))); const build = await mp4sIn(path.join(dir, "out")); const shown = rows.filter((r) => r.files.length > 0); return (

Output files

{shown.length === 0 && build.length === 0 &&

No rendered file yet: render a take (Takes, or the take card's Render full).

} {shown.map(({ take, files }) => (
{take.id} {latest?.id === take.id && latest} {take.label && {take.label}}
    {files.map((f) => (
  • {f.path} {fmtBytes(f.bytes)}
  • ))}
))} {build.length > 0 && (
the build
    {build.map((f) => (
  • {f.path} {fmtBytes(f.bytes)}
  • ))}
)}
); }