Repository navigation
feat(download): let the browser download Bunny files under their real name - #160
Merged
Merged
Conversation
… name Bunny downloads were pulled into a Blob inside the tab so the app could pick the file name. A multi-GB file held the tab open, was copied again at the end, could not resume, and a drop near the end silently restarted it from zero as a plain navigation. Behind OPENFRAME_ENABLE_BUNNY_NAMED_DOWNLOADS (off by default, and only with a CDN token key), the download route now redirects to a Bunny URL carrying the file name in `fn`, signed inside the token, and a pull-zone edge rule turns it into Content-Disposition. The browser's own download manager then saves the file straight to disk under that name. The server builds the name; a caller may pass a stem, never the extension, which comes from the file's type. Project downloads use the same route, start each file as a download rather than a navigation, and pace requests under the route's rate limit.
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.
Bunny downloads under 10 GB are pulled into a Blob inside the tab so the app can choose the file name. For a multi-GB file that means:
Change. This is behind
OPENFRAME_ENABLE_BUNNY_NAMED_DOWNLOADS. It is off by default and has no effect withoutBUNNY_CDN_TOKEN_KEY.GET /api/versions/[versionId]/downloadredirects to a Bunny URL that carries the file name infn. The name is signed inside the HMAC token:signBunnyNamedDownloadUrl, valid 6h, with notoken_ignore_params.fnintoContent-Disposition: attachment; filename*=UTF-8''.... The rule's exact triggers are documented in.env.example.name=invoice.exesaves asinvoice.exe.mov.downloadattribute on the same-origin route). The browser's own download manager then takes it: straight to disk, resumable, and it survives the tab. Project downloads pace requests at 1.1 s to stay under the route's 60 per minute limit, and hold no unload guard when every file goes to the browser.sanitizeDownloadFileNameand the MIME map moved tolib/download-file-name.tsso the server can use them. The client re-exports them.Tested live against a Bunny test pull zone with token auth on, using headless Chromium:
Magi 2 İlk Video - 1.1 v3.movwith all bytes, including with the live zone's existing Force Download rule mirrored on the test zone. Our header replaces its bareattachment;and only one Content-Disposition is sent.fnonce before substituting it, so the URL carries it encoded twice.fngets 403.%0D%0Astays literal in the header. The header is set per request and never sticks in the cache (the zone ignores query strings for caching).Invoice.pdf.exefrom the zone. The final triggers allow only query-string HS256 tokens withouttoken_ignore_params. Live checks: a playback URL with its ownfngets no name, and adding a fake or copied query token gets 403.Not changed. Attachment (asset) downloads still use the buffered path. The 150-character stem cap can cut the version suffix off a very long project file name; the browser then adds " (1)" instead of overwriting.
Rollout.
OPENFRAME_ENABLE_BUNNY_NAMED_DOWNLOADS=truein the app environment.Validation.
bun run checkpasses, and so do 3330 unit and component tests and the download API tests. New tests:tests/api/bunny-named-download.test.ts,tests/unit/lib/download-file-name.test.ts,tests/component/project-download-manifest.test.ts, plus additions to the token, manifest and hook tests.