import { PODCAST_FILES, podcastFor, rangeResponse, resolveReport } from "@/lib/report/serve.mjs"; export const dynamic = "force-dynamic"; // A cut's podcast (build-podcast.mjs): ?project&variant&file=m4a|mp3|notes. // Names, never paths: the file is out// under the pipeline's own // variantPaths() for the manifest's slug. Rendered by the build route's // `options.podcast` run; a 404 until then, said in words. export async function GET(request: Request) { const url = new URL(request.url); const which = url.searchParams.get("file") ?? "m4a"; if (!(which in PODCAST_FILES)) { return new Response(`file must be one of ${Object.keys(PODCAST_FILES).join(", ")}`, { status: 400 }); } const r = await resolveReport(url.searchParams.get("project") ?? "", url.searchParams.get("variant")); if ("error" in r) return new Response(r.error, { status: r.status }); const f = await podcastFor(r.project, r.manifest, r.variant, which as keyof typeof PODCAST_FILES); if (!f) return new Response("no podcast has been rendered for this cut yet", { status: 404 }); return rangeResponse(request, { abs: f.abs, size: f.size, headers: { "content-type": f.type, "accept-ranges": "bytes", "cache-control": "private, no-store", "content-disposition": `${url.searchParams.get("download") === "1" ? "attachment" : "inline"}; filename="${f.download}"`, "x-podcast-mtime": String(f.mtimeMs), }, }); }