Update route.ts
This commit is contained in:
@@ -75,11 +75,17 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
const pdfBuffer = Buffer.from(pdf.output("arraybuffer"));
|
const pdfBuffer = Buffer.from(pdf.output("arraybuffer"));
|
||||||
|
|
||||||
|
// Sanitize filename to only contain ASCII characters
|
||||||
|
const safeFilename = story.title
|
||||||
|
.replace(/[^\x00-\x7F]/g, "") // Remove non-ASCII characters
|
||||||
|
.replace(/[<>:"/\\|?*]/g, "-") // Replace invalid filename characters
|
||||||
|
.trim() || "comic";
|
||||||
|
|
||||||
// Return PDF as response
|
// Return PDF as response
|
||||||
return new NextResponse(pdfBuffer, {
|
return new NextResponse(pdfBuffer, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/pdf",
|
"Content-Type": "application/pdf",
|
||||||
"Content-Disposition": `attachment; filename="${story.title}.pdf"`,
|
"Content-Disposition": `attachment; filename="${safeFilename}.pdf"`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user