import { NextResponse } from "next/server"; import { minioClient, MINIO_BUCKET } from "@/lib/minio"; export const runtime = "nodejs"; export async function GET(_request: Request, { params }: { params: Promise<{ key: string[] }> }) { const { key } = await params; const objectKey = key.join("/"); try { const stat = await minioClient.statObject(MINIO_BUCKET, objectKey); const stream = await minioClient.getObject(MINIO_BUCKET, objectKey); const chunks: Buffer[] = []; for await (const chunk of stream) { chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk as Uint8Array)); } const buffer = Buffer.concat(chunks); const metaData = stat.metaData as Record | undefined; const contentType = metaData?.["content-type"] ?? metaData?.["Content-Type"] ?? "application/octet-stream"; return new Response(buffer, { headers: { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable", "Content-Length": String(buffer.length), }, }); } catch { return NextResponse.json({ error: "Not found" }, { status: 404 }); } }