From cf968b35902753777ee3ce6b100dce4ff459f9a8 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 28 Dec 2025 20:45:33 +0200 Subject: [PATCH] fix(export/share): attachment download links not working --- apps/server/src/services/export/zip/share_theme.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/server/src/services/export/zip/share_theme.ts b/apps/server/src/services/export/zip/share_theme.ts index 493e98b48..ed2f7db40 100644 --- a/apps/server/src/services/export/zip/share_theme.ts +++ b/apps/server/src/services/export/zip/share_theme.ts @@ -76,6 +76,16 @@ export default class ShareThemeExportProvider extends ZipExportProvider { content = renderNoteForExport(note, branch, basePath, noteMeta.notePath.slice(0, -1), this.iconPacks); if (typeof content === "string") { + // Rewrite attachment download links + content = content.replace(/href="api\/attachments\/([a-zA-Z0-9_]+)\/download"/g, (match, attachmentId) => { + const attachmentMeta = (noteMeta.attachments || []).find((attMeta) => attMeta.attachmentId === attachmentId); + if (attachmentMeta?.dataFileName) { + return `href="${attachmentMeta.dataFileName}"`; + } + return match; + }); + + // Rewrite note links content = content.replace(/href="[^"]*\.\/([a-zA-Z0-9_\/]{12})[^"]*"/g, (match, id) => { if (match.includes("/assets/")) return match; if (id === this.rootMeta?.noteId) {