import Link from "next/link"; import CopyButton from "@/components/CopyButton"; import PlayLink from "@/components/projects/PlayLink"; import { badgeVariants, type BadgeVariants } from "@/components/ui/badge"; import { takeRenderLogHref, takesHref } from "@/lib/hrefs"; import type { RenderView } from "@/lib/queue/view"; // A take's render RECORD (lib/report/renderRecord.mjs: takes//render.json, // written by every render whoever started it), as one block: its state, its // stage and percent while it runs, and when it failed the error, the log's // last lines (folded) and the full log. Server-safe: no hooks. Used by the // Takes panel (a take's card, a first render that failed) and /jobs. // // `show` is the page's displayer (settings.privacy, demo epic D4): the // server's displayText on /jobs, useDisplay()'s in a client panel; the // identity when absent. It changes what is DRAWN — the path, the error, the // tail — never the copied path or a data-* attribute. const TONE: Record = { queued: "info", waiting: "meter", running: "meter", done: "on", failed: "blocking", cancelled: "state", }; const same = (s: string) => s; const clock = (iso: string | null) => (iso ? iso.slice(0, 16).replace("T", " ") : ""); export default function RenderRecord({ project, rec, showProject = false, compact = false, show = same, }: { project: string; rec: RenderView; /** /jobs: the project's takes page, linked. */ showProject?: boolean; /** A take's card: one line, the tail folded. */ compact?: boolean; /** The displayer for drawn text (settings.privacy); identity by default. */ show?: (s: string) => string; }) { const live = rec.state === "running" || rec.state === "waiting"; // The output file as a local path (never an /api/ URL shown as where a file is). const mp4Path = rec.mp4 ? (rec.mp4.startsWith("/") ? rec.mp4 : rec.projectDir ? `${rec.projectDir}/takes/${rec.take}/${rec.mp4}` : `takes/${rec.take}/${rec.mp4}`) : null; const bad = rec.state === "failed" || rec.state === "cancelled"; return (
{rec.state === "failed" ? "render failed" : rec.state === "cancelled" ? "render cancelled" : `render ${rec.state}`} {showProject && ( {project} )} {rec.take} {showProject && project && } {rec.label && !compact && {rec.label}} {live && ( {rec.stage ?? "…"} {rec.percent != null ? ` · ${rec.percent}%` : ""} {rec.entries?.of ? ` · ${rec.entries.done}/${rec.entries.of} segments` : ""} )} {clock(rec.startedAt)} {rec.endedAt ? ` → ${rec.endedAt.slice(11, 16)}` : ""} {rec.exitCode != null ? ` · exit ${rec.exitCode}` : ""} {rec.state === "done" && rec.seconds != null ? ` · ${rec.seconds.toFixed(1)} s` : ""} log
{rec.state === "done" && mp4Path && (

{show(mp4Path)}

)} {rec.error && (

{show(rec.error)}

)} {bad && rec.tail?.length > 0 && (
the log’s last {Math.min(rec.tail.length, 40)} lines
{show(rec.tail.slice(-40).join("\n"))}
)}
); }