refactor: extract base64ToBlob utility, fix MIME resolution in download#1356
Merged
ringringlin merged 3 commits intomainfrom Mar 17, 2026
Merged
refactor: extract base64ToBlob utility, fix MIME resolution in download#1356ringringlin merged 3 commits intomainfrom
ringringlin merged 3 commits intomainfrom
Conversation
added 3 commits
March 17, 2026 13:58
…e download - Add src/renderer/utils/base64.ts with base64ToBlob() and BINARY_MIME_MAP - Remove duplicated atob decode logic from PreviewPanel and useWorkspaceFileOps - Fix MIME type resolution in useWorkspaceFileOps to use extension lookup instead of parsing the data URL prefix (which returns octet-stream for binary files like Excel/PDF) - Remove console.error residual from useWorkspaceFileOps - Add unit tests for base64ToBlob and BINARY_MIME_MAP (6 tests) - Register base64.ts in vitest coverage.include
Extract shared download.ts with downloadFileFromPath and downloadTextContent, replacing duplicated blob/link logic in both PreviewPanel and useWorkspaceFileOps. Fix ZIP (and other archive) downloads from PreviewPanel toolbar that previously fell through to the text branch, producing corrupted files. The root cause was that contentType for unknown extensions defaults to 'code', so the old binary check (excel/pdf/ppt/word only) missed zip. Changes: - Add zip/tar/gz/bz2/7z/rar MIME entries to BINARY_MIME_MAP - New src/renderer/utils/download.ts: downloadFileFromPath reads raw bytes via getImageBase64+atob (CSP-safe); downloadTextContent wraps Blob creation; both share a private triggerBlobDownload helper - PreviewPanel.handleDownload: any file with metadata.filePath goes through downloadFileFromPath; pure base64 image keeps fetch path; text/code uses downloadTextContent - useWorkspaceFileOps.handleDownloadFile: simplified to one-liner call - Tests: add archive MIME assertions to base64.test.ts; new download.dom.test.ts with 6 cases covering MIME resolution, click trigger, URL revocation, and error propagation
ringringlin
approved these changes
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1324.
Summary
atobdecode logic andMIME_MAPintosrc/renderer/utils/base64.ts(base64ToBlob+BINARY_MIME_MAP), eliminating the DRY violation introduced in fix: binary file download fails with 0KB in WebUI mode + add context menu download #1324useWorkspaceFileOps.ts: was regex-extracting fromdata:URL prefix (returnsapplication/octet-streamfor binary files); now uses extension-based lookup viaBINARY_MIME_MAP, consistent withPreviewPanel.tsxconsole.errorresidual fromuseWorkspaceFileOps.tsTest plan
bun run test tests/unit/base64.test.ts— 6 tests should passbunx tsc --noEmit— no type errors