import { readFile } from "node:fs/promises"; import { withAuth } from "@/lib/api-auth"; import { apiError } from "@/lib/api-errors"; import { payloadFile } from "@/lib/publications"; export const dynamic = "force-dynamic"; /** The exact payload the preview built, byte for byte what would be sent to launch80. */ export const GET = withAuth>(async (_req, { params }) => { const { id, pubId } = await params; let path: string; try { path = payloadFile(id, pubId); } catch { return apiError(404, "not_found", "No payload for this preview."); } const body = await readFile(path).catch(() => null); if (!body) return apiError(404, "not_found", "No payload for this preview."); return new Response(body, { headers: { "Content-Type": "application/json", "Content-Disposition": `attachment; filename="launch80-payload-${pubId.slice(-6).toLowerCase()}.json"` } }); });