Files
cydweb/app/api/firmware/[project]/[variant]/[file]/route.ts
DESKTOP-PUHFO60\dsx2016 ae63378fdb Add CYD browser flasher with Next.js, i18n, and Web Serial install.
Replace the starter app with a public/local flasher that discovers sibling firmwares, supports en/zh, and documents HTTPS deploy.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-19 19:38:53 +08:00

38 lines
1.1 KiB
TypeScript

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}"`,
},
});
}