From ae1b05189e0eea216536e09a78119b3dc4ead63b Mon Sep 17 00:00:00 2001 From: Cyril Date: Thu, 2 Oct 2025 11:27:09 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(frontend)=20fix=20attachment=20downlo?= =?UTF-8?q?ad=20filename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit use the document title instead of the uuid when downloading attachments Signed-off-by: Cyril --- CHANGELOG.md | 3 ++- .../__tests__/app-impress/doc-editor.spec.ts | 8 ++++++++ .../BlockNoteToolBar/FileDownloadButton.tsx | 17 +++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2f8c9d4..7ba02295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ and this project adheres to - ♿ remove redundant aria-label on hidden icons and update tests #1432 - ♿ improve semantic structure and aria roles of leftpanel #1431 - ♿ add default background to left panel for better accessibility #1423 - - ♿ restyle checked checkboxes: removing strikethrough #1439 + - ♿ restyle checked checkboxes: removing strikethrough #1439 - ♿ add h1 for SR on 40X pages and remove alt texts #1438 - ♿ update labels and shared document icon accessibility #1442 @@ -38,6 +38,7 @@ and this project adheres to - 🐛(frontend) fix legacy role computation #1376 - 🛂(frontend) block editing title when not allowed #1412 - 🐛(frontend) scroll back to top when navigate to a document #1406 +- 🐛(frontend) fix attachment download filename #1447 - 🐛(frontend) exclude h4-h6 headings from table of contents #1441 - 🔒(frontend) prevent readers from changing callout emoji #1449 diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts index 47a318b6..c15fcdfa 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts @@ -846,6 +846,7 @@ test.describe('Doc Editor', () => { await page.getByText('Add PDF').click(); const fileChooserPromise = page.waitForEvent('filechooser'); + const downloadPromise = page.waitForEvent('download'); await page.getByText('Upload file').click(); const fileChooser = await fileChooserPromise; @@ -866,5 +867,12 @@ test.describe('Doc Editor', () => { await expect(pdfEmbed).toHaveAttribute('type', 'application/pdf'); await expect(pdfEmbed).toHaveAttribute('role', 'presentation'); + + // Check download with original filename + await page.locator('.bn-block-content[data-content-type="pdf"]').click(); + await page.locator('[data-test="downloadfile"]').click(); + + const download = await downloadPromise; + expect(download.suggestedFilename()).toBe('test-pdf.pdf'); }); }); diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/FileDownloadButton.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/FileDownloadButton.tsx index e0c31847..0cbf61e7 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/FileDownloadButton.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/FileDownloadButton.tsx @@ -76,11 +76,23 @@ export const FileDownloadButton = ({ if (!url.includes('-unsafe')) { const blob = (await exportResolveFileUrl(url)) as Blob; - downloadFile(blob, url.split('/').pop() || 'file'); + downloadFile( + blob, + fileBlock.props.name || url.split('/').pop() || 'file', + ); } else { const onConfirm = async () => { const blob = (await exportResolveFileUrl(url)) as Blob; - downloadFile(blob, url.split('/').pop() || 'file (unsafe)'); + + const baseName = + fileBlock.props.name || url.split('/').pop() || 'file'; + + const regFindLastDot = /(\.[^/.]+)$/; + const unsafeName = baseName.includes('.') + ? baseName.replace(regFindLastDot, '-unsafe$1') + : baseName + '-unsafe'; + + downloadFile(blob, unsafeName); }; open(onConfirm); @@ -100,6 +112,7 @@ export const FileDownloadButton = ({ <>