diff --git a/app/api/download-pdf/route.ts b/app/api/download-pdf/route.ts index 4990e35..a0b41ea 100644 --- a/app/api/download-pdf/route.ts +++ b/app/api/download-pdf/route.ts @@ -75,11 +75,17 @@ export async function GET(request: NextRequest) { 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 new NextResponse(pdfBuffer, { headers: { "Content-Type": "application/pdf", - "Content-Disposition": `attachment; filename="${story.title}.pdf"`, + "Content-Disposition": `attachment; filename="${safeFilename}.pdf"`, }, }); } catch (error) {