Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
revert fix
Marc Seitz81b8508ec424
diff --git a/lib/utils/download-document.ts b/lib/utils/download-document.tsindex 8d02b5bf..daccca59 100644--- a/lib/utils/download-document.ts+++ b/lib/utils/download-document.ts@@ -1,3 +1,24 @@+/**+ * Trigger a document download from one of the link-scoped download+ * endpoints (`/api/links/download` or `/api/links/download/dataroom-document`).+ *+ * The server returns one of two response shapes:+ *+ * 1. A buffered binary response (currently only watermarked PDFs that need+ * mupdf annotation) with `Content-Disposition` set to the desired+ * filename. We turn it into a blob + `<a download>` to save it.+ *+ * 2. A JSON response of the form `{ downloadUrl, fileName }`. The URL is+ * a CloudFront / S3 presigned URL with `Content-Disposition: attachment`+ * baked into the object metadata, so the browser will save it directly.+ * We hand it to a hidden iframe instead of `<a download>` because the+ * `download` attribute is silently ignored for cross-origin URLs in+ * Chromium/Firefox/Safari, which would otherwise navigate the top-level+ * page to the CloudFront URL.+ *+ * `fallbackFileName` is used only when the buffered response is missing+ * its `Content-Disposition` header (shouldn't happen in practice).+ */export async function downloadFromLinkEndpoint({endpoint,body,@@ -21,12 +42,12 @@ export async function downloadFromLinkEndpoint({const contentType = response.headers.get("content-type");if (contentType?.includes("application/json")) {- const { downloadUrl, fileName } = (await response.json()) as {+ const { downloadUrl } = (await response.json()) as {downloadUrl: string;fileName?: string;};- triggerDownloadFromUrl(downloadUrl, fileName ?? fallbackFileName);+ triggerDownloadFromUrl(downloadUrl);return;}@@ -52,20 +73,17 @@ export async function downloadFromLinkEndpoint({}, 100);}-function triggerDownloadFromUrl(url: string, suggestedFileName: string): void {- const link = window.document.createElement("a");- link.href = url;- link.rel = "noopener noreferrer";- link.download = suggestedFileName;- link.style.display = "none";- window.document.body.appendChild(link);- link.click();+function triggerDownloadFromUrl(url: string): void {+ const iframe = window.document.createElement("iframe");+ iframe.style.display = "none";+ window.document.body.appendChild(iframe);+ iframe.src = url;setTimeout(() => {- if (link.parentNode) {- window.document.body.removeChild(link);+ if (iframe.parentNode) {+ window.document.body.removeChild(iframe);}- }, 100);+ }, 5000);}export function extractFilenameFromContentDisposition(