"use client"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; // The cut as SOUND ONLY, beside the video's exports (release 25, T3). // // "podcast" starts one build-route job with `options.podcast` -- build-podcast.mjs // over the segments on disk -- and follows it by id; when it ends the page is // refreshed, so the links below are the server's word on what is there, never // a guess from here. A running build is a 409 that is shown, not swallowed; a // cut with a segment missing fails with the pipeline's own sentence. type File = { size: number; mtimeMs: number } | null; export default function PodcastExport({ project, variant, files, }: { project: string; variant: string; files: { m4a: File; mp3: File; notes: File }; }) { const router = useRouter(); const [job, setJob] = useState(null); const [state, setState] = useState<"idle" | "busy" | "running" | "done" | "failed">("idle"); const [msg, setMsg] = useState(null); useEffect(() => { if (!job) return; const t = setInterval(async () => { const r = await fetch(`/api/report/build?job=${encodeURIComponent(job)}`, { cache: "no-store" }); if (!r.ok) return; const j = (await r.json()) as { state: string; error: string | null }; if (j.state === "running") return; clearInterval(t); setJob(null); setState(j.state === "done" ? "done" : "failed"); setMsg(j.state === "done" ? null : j.error ?? "the podcast was not rendered"); router.refresh(); }, 700); return () => clearInterval(t); }, [job, router]); const href = (file: string, download = false) => `/api/report/podcast?project=${encodeURIComponent(project)}&variant=${encodeURIComponent(variant)}&file=${file}` + (download ? "&download=1" : "") + // The mtime, so a re-render is a new URL and never a cached old one. `&v=${(files as Record)[file]?.mtimeMs ?? 0}`; return ( {files.m4a && ( podcast.m4a )} {files.mp3 && ( podcast.mp3 )} {files.notes && ( show-notes.md )} {msg && ( {msg} )} ); }