fix(web): stream file-panel downloads directly in browsers and show a spinner #41900
Openzs-andy(GitHub profile, opens in a new tab)wants to merge 13 commits into
main fromrefs/pull/41900/headopened View on GitHubzs-andy(GitHub profile, opens in a new tab) linked this to fix #41519
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelstakeover:in-progress
- @@ -154,0 +175,21 @@175+176+export function saveBlobDownload(blob: Blob, fileName: string): void {177+ const downloadUrl = URL.createObjectURL(blob);178+ // Scheduled before the click so the URL is revoked even if the click throws.179+ setTimeout(() => URL.revokeObjectURL(downloadUrl), 30_000);180+ triggerAnchorDownload(downloadUrl, fileName);181+}182+183+export async function saveAssetDownload(input: {184+ readonly prepareUrl: () => Promise<string | null>;185+ readonly fileName: string;186+ readonly unavailableMessage: string;187+ readonly loadFailedMessage: string;188+ readonly useBlobDownload?: boolean;189+}): Promise<void> {190+ const target = await input.prepareUrl();191+ if (!target) throw new Error(input.unavailableMessage);192+ // Plain browsers stream attachment-disposition URLs straight into the native download manager.193+ // Desktop's custom app scheme needs a blob URL so it does not open an external browser.194+ if (!(input.useBlobDownload ?? isElectron)) {195+ triggerAnchorDownload(target, input.fileName);
Sign in to join this conversation.
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review.
Walkthrough
File preview download actions now use shared helpers. Browsers download asset URLs directly, while Electron fetches assets and downloads them as blobs. The server marks resources with attachment disposition as downloads. Save actions show a spinner while saving.
Changes: File downloads
apps/web/src/components/files/fileSurfaceChrome.tsx,apps/server/src/assets/AssetAccess.ts,apps/server/src/assets/AssetAccess.test.tsapps/web/src/components/files/fileSurfaceChrome.tsx,apps/web/src/components/files/fileSurfaceChrome.test.tsapps/web/src/components/files/AttachmentFilePreview.tsx,apps/web/src/components/files/FilePreviewPanel.tsx,apps/web/src/components/files/AttachmentFilePreview.browser.test.tsxEstimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
Suggested reviewers:
juliusmarmingeMerge Risk:
Minimal · previous review
4e556Save actions in the file panels now start a download directly from the server in plain browsers, and the server marks attachment-disposition resources as downloads. No concrete merge-blocking risk remains.
Pre-merge checks:
4
#41519and reproduction context), Change (helpers, plain-browser direct download, Electron fetch-to-Blob path, spinner, disposition change), and Verif…#41519] The issue requires visible evidence that a file-panel save has started. It allows either the browser's native download UI or in-app progress feedback. The reviewed head meets this requirement…#41519or to the direct-link approach they use:-
fileSurfaceChrome.tsx: addsattachmentDownloadResource,saveBlobDownload, and `saveAssetDownlo…Full details: Title check
Explanation
The title names the core change: file-panel saves now stream directly in browsers and show a spinner. It follows conventional commit form and matches the changeset, the PR objectives, and linked issue
#41519. It is a clear, specific summary.Full details: Description check
Explanation
The description covers Problem (with linked issue
#41519and reproduction context), Change (helpers, plain-browser direct download, Electron fetch-to-Blob path, spinner, disposition change), and Verification (named browser tests, check commands, and stated gaps such as no live Electron or 50+ MB Edge testing). Scope is only partly addressed: it links the issue that shows the bug but does not state the explicit bug-fix justification beyond that, which is acceptable because an issue is linked. Required sections are all present and substantive, so the description is mostly complete.Full details: Linked Issues check
Explanation
[
#41519] The issue requires visible evidence that a file-panel save has started. It allows either the browser's native download UI or in-app progress feedback. The reviewed head meets this requirement:!isElectron):saveAssetDownloadinapps/web/src/components/files/fileSurfaceChrome.tsxclicks an anchor on the server attachment URL. The browser download manager starts without buffering the file in a Blob.isElectron): the fetch-to-Blob path remains. The issue permits this path when feedback is shown.<Spinner size="sm" />replaces the download icon inAttachmentFilePreview,WorkspacePdfSaveAction, andLargeFileActionswhilesavingis true.attachmentDownloadResourcesetsdisposition: "attachment"forattachment,media-file, anddraft-workspace-fileresources.apps/server/src/assets/AssetAccess.tssets the download claim when disposition isattachment. Before this change, video and some image attachments ignored that request. The direct-link path needs this for those types.AssetAccess.test.tscovers it.AttachmentFilePreview.browser.test.tsxcovers the plain-browser spinner, attachment request, and direct click withoutfetch. The desktop path is covered withuseBlobDownload: true. The suspected causes in the issue (preview remount, duplicate clicks) are not addressed directly. The issue lists them as unverified, and the requested feedback does not depend on them. The 50 MB limit and ZIP routing are unchanged, and the issue does not require changes to them. Live Electron behavior and 50+ MB remote downloads remain unverified. This verdict rests on the whole-PR change summaries and the previous review. Line-level review of the diffs was not performed.Full details: Out of Scope Changes check
Explanation
Each changed area connects to the save actions in
#41519or to the direct-link approach they use:fileSurfaceChrome.tsx: addsattachmentDownloadResource,saveBlobDownload, andsaveAssetDownload. The three save actions use these helpers.AttachmentFilePreview.tsxandFilePreviewPanel.tsx: switch the save paths to the helpers and add the spinner.apps/server/src/assets/AssetAccess.tsandAssetAccess.test.ts: honor explicitattachmentdisposition for video and image attachments. The plain-browser direct-link path needs this to download these types instead of displaying them inline.AttachmentFilePreview.browser.test.tsxandfileSurfaceChrome.test.ts: test the new behavior. No unrelated changes were identified. The 50 MB preview limit and Office/OpenXML routing for ZIP files are not changed. This verdict rests on change summaries. Line-level review of the server and test diffs was not performed.Finishing Touches
Generate unit tests (beta)
1fadc3fd-10e4-40c1-9c6b-8339826ec550Reviewing files that changed from the base of the PR and between 0a762e72f5a95601331027df2b9be9b74c0072b5 and 4e5564d9ec3ad608dcef6c9a59d7c8a73009b749.
apps/server/src/assets/AssetAccess.test.tsapps/server/src/assets/AssetAccess.tsapps/web/src/components/files/AttachmentFilePreview.browser.test.tsxapps/web/src/components/files/fileSurfaceChrome.tsxIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.