From 0b6730c06fd16321d27336bddb9cd1294237f0d5 Mon Sep 17 00:00:00 2001 From: Philip Okugbe Date: Fri, 13 Sep 2024 17:40:24 +0100 Subject: [PATCH] fix page export failure when title contains non-ASCII characters (#309) --- .../src/features/page/services/page-service.ts | 13 ++++++++----- .../src/core/attachment/attachment.controller.ts | 2 +- .../src/integrations/export/export.controller.ts | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/client/src/features/page/services/page-service.ts b/apps/client/src/features/page/services/page-service.ts index ebe22063..1fce401b 100644 --- a/apps/client/src/features/page/services/page-service.ts +++ b/apps/client/src/features/page/services/page-service.ts @@ -59,12 +59,12 @@ export async function exportPage(data: IExportPageParams): Promise { const req = await api.post("/pages/export", data, { responseType: "blob", }); - + console.log(req?.headers); const fileName = req?.headers["content-disposition"] .split("filename=")[1] .replace(/"/g, ""); - saveAs(req.data, fileName); + saveAs(req.data, decodeURIComponent(fileName)); } export async function importPage(file: File, spaceId: string) { @@ -81,14 +81,17 @@ export async function importPage(file: File, spaceId: string) { return req.data; } -export async function uploadFile(file: File, pageId: string, attachmentId?: string): Promise { +export async function uploadFile( + file: File, + pageId: string, + attachmentId?: string, +): Promise { const formData = new FormData(); - if(attachmentId){ + if (attachmentId) { formData.append("attachmentId", attachmentId); } formData.append("pageId", pageId); formData.append("file", file); - const req = await api.post("/files/upload", formData, { headers: { diff --git a/apps/server/src/core/attachment/attachment.controller.ts b/apps/server/src/core/attachment/attachment.controller.ts index c06769f0..77773783 100644 --- a/apps/server/src/core/attachment/attachment.controller.ts +++ b/apps/server/src/core/attachment/attachment.controller.ts @@ -182,7 +182,7 @@ export class AttachmentController { if (!inlineFileExtensions.includes(attachment.fileExt)) { res.header( 'Content-Disposition', - `attachment; filename="${attachment.fileName}"`, + `attachment; filename="${encodeURIComponent(attachment.fileName)}"`, ); } diff --git a/apps/server/src/integrations/export/export.controller.ts b/apps/server/src/integrations/export/export.controller.ts index 09b2c5d6..0273113b 100644 --- a/apps/server/src/integrations/export/export.controller.ts +++ b/apps/server/src/integrations/export/export.controller.ts @@ -61,7 +61,8 @@ export class ImportController { res.headers({ 'Content-Type': getMimeType(fileExt), - 'Content-Disposition': 'attachment; filename="' + fileName + '"', + 'Content-Disposition': + 'attachment; filename="' + encodeURIComponent(fileName) + '"', }); res.send(rawContent);