import { readFile } from "node:fs/promises"; import { join } from "node:path"; import { withAuth } from "@/lib/api-auth"; import { apiError } from "@/lib/api-errors"; import { REPORT_FILE, runDir } from "@/lib/benchmark-paths"; import { getBenchmark } from "@/lib/benchmarks"; export const dynamic = "force-dynamic"; /** * BetterBench's self-contained HTML report. Served sandboxed (opaque origin, no network): it is * generated content and must not run with access to Kaname's session. */ export const GET = withAuth>(async (_req, { params }) => { const run = await getBenchmark((await params).id); if (!run?.hasReport) return apiError(404, "not_found", "This run has no report."); const html = await readFile(join(runDir(run.id), REPORT_FILE)).catch(() => null); if (!html) return apiError(404, "not_found", "The report file is missing."); return new Response(html, { headers: { "Content-Type": "text/html; charset=utf-8", "Content-Security-Policy": "sandbox allow-scripts; default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; font-src data:", "X-Content-Type-Options": "nosniff", "Cache-Control": "private, max-age=300", }, }); });