Skip to content

[BR-2165]:feat/add multipart download for shared files - #2040

Closed
jaaaaavier wants to merge 3 commits into
masterfrom
feat/add-multipart-download-for-shared-files
Closed

[BR-2165]:feat/add multipart download for shared files#2040
jaaaaavier wants to merge 3 commits into
masterfrom
feat/add-multipart-download-for-shared-files

Conversation

@jaaaaavier

@jaaaaavier jaaaaavier commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

Adds multipart download support to public shared file links.

Changes:

  • NetworkFacade.downloadChunk: honor options?.key as an override for the SDK-derived decryption key, mirroring the existing behavior in download(). Needed because shared links have no mnemonic to derive a key from the real key is the link's own encryptionKey.
  • download/v2.ts: split multipartDownload into multipartDownloadOwnFile (existing behavior) and a new multipartDownloadSharedFile, dispatching on token && encryptionKey, the same discriminator already used by downloadFile() for the non-multipart case.
  • network/index.ts: re-export multipartDownloadFile from the network facade so it's actually reachable from views (it already existed in download.ts but wasn't exposed).
  • ShareFileView.tsx: use network.multipartDownloadFile when fileInfo.item.size >= MIN_DOWNLOAD_MULTIPART_SIZE, otherwise keep the regular single-request downloadFile`.

Related Issues

Related Pull Requests

Checklist

  • Changes have been tested locally.
  • Unit tests have been written or updated as necessary.
  • The code adheres to the repository's coding standards.
  • Relevant documentation has been added or updated.
  • No new warnings or errors have been introduced.
  • SonarCloud issues have been reviewed and addressed.
  • QA Passed

Testing Process

Manually verified in the browser: shared files above the threshold trigger multiple parallel 206 Partial Content range requests instead of one single request, and the resulting file downloads and decrypts correctly.

Additional Notes

@jaaaaavier jaaaaavier self-assigned this Jul 13, 2026
@jaaaaavier jaaaaavier added the enhancement New feature or request label Jul 13, 2026
@sonarqubecloud

Copy link
Copy Markdown

@jaaaaavier
jaaaaavier marked this pull request as ready for review July 14, 2026 06:28
@jaaaaavier
jaaaaavier requested review from a team, CandelR and larryrider as code owners July 14, 2026 06:28
(downloadFile as any).mockImplementation(
async (fileId, bucketId, mnemonic, network, cryptoLib, bufferFrom, downloadCallback, decryptCallback) => {
await downloadCallback([{ url: downloadExample }]);
await decryptCallback('aes256ctr', sdkDerivedKey, iv, 2048);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be called with the overrideKey?

@terrerox terrerox Aug 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think so, because that's the purpose of the test: to check if the derived key is overridden by the override key. If we changed that line to the override key, it would be checking the same key — overrideKey === overrideKey.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added the test because you added the key override to decryptStream. Why was override added to decryptStream?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answer this @terrerox pls

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sg-gs This PR was clashing with changes I made for new private sharings. So, I've incorporated multi-part downloads into new private sharings: #2116

We can close this PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S. It's working, and server changes were already merged, but QA was postponed due to Mail & Mobile

@github-actions

Copy link
Copy Markdown

This pull request has been inactive for 30 days. Is it still in progress? If so, please leave a comment or make an update to keep it open. Otherwise, it will be closed automatically in 15 days.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 14, 2026

Copy link
Copy Markdown

Deploying drive-web with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2471c96
Status: ✅  Deploy successful!
Preview URL: https://84cb1927.drive-web.pages.dev
Branch Preview URL: https://feat-add-multipart-download.drive-web.pages.dev

View logs

@github-actions github-actions Bot removed the stalled label Aug 15, 2026
@terrerox terrerox self-assigned this Aug 16, 2026
@sonarqubecloud

Copy link
Copy Markdown

* Creates a NetworkFacade for the bridge. Pass auth for downloads of the user's own files;
* omit it for shared-link downloads, which authenticate through the share token instead.
*/
const createNetworkFacade = (auth?: { username: string; password: string }): NetworkFacade =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's easier to remove the shared download from the network than create an empty auth

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That empty auth was already there before this PR tbh, downloadSharedFile on master did the same thing, I just moved it into createNetworkFacade. And we can't really avoid it, the SDK client requires those fields and for shared files the backend only gives us the key + token, no network creds. The token is what authorizes the download so the auth is ignored anyway.

fileStream = decryptStream(encryptedContentStreams, key as Buffer, iv as Buffer, chunkStart);
fileStream = decryptStream(
encryptedContentStreams,
(options?.key || key) as Buffer,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why override with options.key? It wasn't there before

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this change adds multipart download for shared files, this wasn't needed before, multipart was only used for own files, where the SDK derives the key from the mnemonic. Shared files don't have a mnemonic; the share link provides the key directly as encryptionKey, which we pass as options.key, so downloadChunk needs to honor it. It's the same options?.key || key logic the single-part download() already had. Own-file downloads never set options.key, so nothing changes for them.

@TamaraFinogina

Copy link
Copy Markdown
Contributor
Screenshot 2026-08-18 at 10 43 56 I uploaded a 1,2GB video into a business workspace (not workspace owner, invited user), and video streaming was failing

@terrerox
terrerox requested a review from sg-gs August 29, 2026 17:31
@terrerox terrerox closed this Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants