fix: await params in GET request and update Content-Disposition header for special characters
This commit is contained in:
@@ -6,7 +6,8 @@ import db from "@/lib/db";
|
|||||||
|
|
||||||
export async function GET(request, { params }) {
|
export async function GET(request, { params }) {
|
||||||
try {
|
try {
|
||||||
const { filename } = params;
|
// Await params (Next.js 15+ requirement)
|
||||||
|
const { filename } = await params;
|
||||||
|
|
||||||
if (!filename) {
|
if (!filename) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@@ -39,12 +40,16 @@ export async function GET(request, { params }) {
|
|||||||
// Read file
|
// Read file
|
||||||
const fileBuffer = await readFile(filePath);
|
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
|
// Return file with proper headers
|
||||||
const response = new NextResponse(fileBuffer, {
|
const response = new NextResponse(fileBuffer, {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": template.mime_type || "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
"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(),
|
"Content-Length": fileBuffer.length.toString(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user