Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(desktop): preserve attachment filenames on download

tianma-if389c140eb1c1
diff --git a/apps/web/src/components/editor/FileAttachment.tsx b/apps/web/src/components/editor/FileAttachment.tsx
index 1e638309..62d1c0a7 100644
--- a/apps/web/src/components/editor/FileAttachment.tsx
+++ b/apps/web/src/components/editor/FileAttachment.tsx
@@ -14,7 +14,7 @@ import { COMPACT_ATTACHMENT_WIDTH_CLASS } from "@/components/attachments/attachm
import { VideoAttachmentPlayer } from "@/components/attachments/VideoAttachmentPlayer";
import { ButtonTooltip } from "@/components/ui/button-tooltip";
import { useAttachmentByteSize } from "@/hooks/useAttachmentByteSize";
-import { isDesktopResourceRuntime, toApiResourceUrl } from "@/lib/desktop-resources";
+import { isDesktopResourceRuntime, toApiResourceUrl, toDesktopResourceDownloadUrl } from "@/lib/desktop-resources";
import { cn } from "@/lib/utils";
const FileAttachmentNodeView = ({ node, updateAttributes }: NodeViewProps) => {
@@ -26,6 +26,7 @@ const FileAttachmentNodeView = ({ node, updateAttributes }: NodeViewProps) => {
: getAttachmentFilenameFromLabel(label);
const mimeType = typeof node.attrs.mimeType === "string" ? node.attrs.mimeType : "";
const resolvedUrl = isDesktopResourceRuntime() ? url : toApiResourceUrl(url);
+ const downloadUrl = toDesktopResourceDownloadUrl(resolvedUrl, filename || label);
const byteSize = useAttachmentByteSize(resolvedUrl, node.attrs.byteSize);
const metadata = formatAttachmentMetadata(mimeType, filename || label, byteSize);
const attachmentKind = resolveAttachmentKind(mimeType, filename || label);
@@ -76,7 +77,7 @@ const FileAttachmentNodeView = ({ node, updateAttributes }: NodeViewProps) => {
</a>
)}
<ButtonTooltip title={t("editor.resourceActions.download")}>
- <a className="pdf-viewer-action" href={resolvedUrl} download={filename || label} aria-label={t("editor.resourceActions.download")}>
+ <a className="pdf-viewer-action" href={downloadUrl} download={filename || label} aria-label={t("editor.resourceActions.download")}>
<Download aria-hidden="true" />
</a>
</ButtonTooltip>
diff --git a/apps/web/src/components/pdf/PdfViewer.tsx b/apps/web/src/components/pdf/PdfViewer.tsx
index 3329f8af..6f32c692 100644
--- a/apps/web/src/components/pdf/PdfViewer.tsx
+++ b/apps/web/src/components/pdf/PdfViewer.tsx
@@ -21,7 +21,7 @@ import { AttachmentFileIcon } from "@/components/attachments/AttachmentFileIcon"
import { COMPACT_ATTACHMENT_WIDTH_CLASS } from "@/components/attachments/attachment-layout";
import { ButtonTooltip } from "@/components/ui/button-tooltip";
import { useAttachmentByteSize } from "@/hooks/useAttachmentByteSize";
-import { isDesktopResourceRuntime, toApiResourceUrl } from "@/lib/desktop-resources";
+import { isDesktopResourceRuntime, toApiResourceUrl, toDesktopResourceDownloadUrl } from "@/lib/desktop-resources";
import { cn } from "@/lib/utils";
import { loadPdfJs } from "./pdfjs-loader";
import { canPreviewPdfInline, loadPdfDocumentSource } from "./pdf-document-source";
@@ -310,7 +310,7 @@ export const PdfViewer = ({
</>
) : null}
<ButtonTooltip title={t("pdfViewer.download")}>
- <a className="pdf-viewer-action" href={resolvedUrl} download={label} aria-label={t("pdfViewer.download")}><Download aria-hidden="true" /></a>
+ <a className="pdf-viewer-action" href={toDesktopResourceDownloadUrl(resolvedUrl, filename || label)} download={filename || label} aria-label={t("pdfViewer.download")}><Download aria-hidden="true" /></a>
</ButtonTooltip>
<ButtonTooltip title={t("pdfViewer.openExternal")}>
<a className="pdf-viewer-action" href={resolvedUrl} target="_blank" rel="noreferrer" aria-label={t("pdfViewer.openExternal")}><ExternalLink aria-hidden="true" /></a>