fix: await params in GET request and update Content-Disposition header for special characters

This commit is contained in:
2026-01-13 13:25:05 +01:00
parent b1f64d37bb
commit 7520e9d422

View File

@@ -6,7 +6,8 @@ import db from "@/lib/db";
export async function GET(request, { params }) {
try {
const { filename } = params;
// Await params (Next.js 15+ requirement)
const { filename } = await params;
if (!filename) {
return NextResponse.json(
@@ -39,12 +40,16 @@ export async function GET(request, { params }) {
// Read file
const fileBuffer = await readFile(filePath);
// Encode filename for Content-Disposition header (RFC 5987)
// This handles Polish and other special characters
const encodedFilename = encodeURIComponent(template.original_filename);
// Return file with proper headers
const response = new NextResponse(fileBuffer, {
status: 200,
headers: {
"Content-Type": template.mime_type || "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"Content-Disposition": `attachment; filename="${template.original_filename}"`,
"Content-Disposition": `attachment; filename*=UTF-8''${encodedFilename}`,
"Content-Length": fileBuffer.length.toString(),
},
});