import fs from "fs"; import path from "path"; import { NextResponse } from "next/server"; import { REQUIRED_BINS, resolveFirmwareDir } from "@/lib/firmware"; export const dynamic = "force-dynamic"; type Params = { params: Promise<{ project: string; variant: string; file: string }>; }; export async function GET(_req: Request, { params }: Params) { const { project, variant, file } = await params; if (!(REQUIRED_BINS as readonly string[]).includes(file)) { return NextResponse.json({ error: "invalid file" }, { status: 400 }); } const dir = resolveFirmwareDir(project, variant); if (!dir) { return NextResponse.json({ error: "not found" }, { status: 404 }); } const abs = path.join(dir, file); if (!fs.existsSync(abs)) { return NextResponse.json({ error: "not found" }, { status: 404 }); } const buf = fs.readFileSync(abs); return new NextResponse(buf, { headers: { "Content-Type": "application/octet-stream", "Content-Length": String(buf.length), "Cache-Control": "no-store", "Content-Disposition": `attachment; filename="${file}"`, }, }); }