30 lines
822 B
TypeScript
30 lines
822 B
TypeScript
import { createReadStream } from "node:fs";
|
|
import { Readable } from "node:stream";
|
|
import { getJobZip } from "@/lib/jobs";
|
|
|
|
export const runtime = "nodejs";
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function GET(
|
|
_req: Request,
|
|
context: { params: Promise<{ jobId: string }> },
|
|
): Promise<Response> {
|
|
const { jobId } = await context.params;
|
|
const job = await getJobZip(jobId);
|
|
if (!job) {
|
|
return Response.json(
|
|
{ error: "Download expired or not found" },
|
|
{ status: 404 },
|
|
);
|
|
}
|
|
|
|
return new Response(Readable.toWeb(createReadStream(job.zipPath)) as ReadableStream, {
|
|
headers: {
|
|
"Content-Type": "application/zip",
|
|
"Content-Length": String(job.size),
|
|
"Content-Disposition": 'attachment; filename="ids.zip"',
|
|
"Cache-Control": "no-store",
|
|
},
|
|
});
|
|
}
|