Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(upload-client): Remove ipfs-utils #1627

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

talentlessguy
Copy link
Contributor

@talentlessguy talentlessguy commented Feb 19, 2025

This PR removes redundant ipfs-utils for the upload-client which only uses it in one place. I rewrote the code from the original ipfs-utils to use native fetch and be platform-agnostic.

pnpm test passed, while preserving 100% code coverage.

Tested on:

  • Node
  • Chromium
  • Firefox
  • Bun
  • Deno
  • Electron
  • React Native

@talentlessguy talentlessguy marked this pull request as ready for review February 20, 2025 15:27
const preH2 = protocol !== 'h2' && protocol !== 'h2c' && protocol !== 'h3'

/* c8 ignore next 3 */
if ((isBrowser || preH2) && !isNode) {
Copy link
Member

Choose a reason for hiding this comment

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

The test for isBrowser is an existence check for XHR, which could be false, but presumably preH2 could be true and we could also not be in Nodejs...

We should not drop in here if XHR is not available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might get confusing so I'll list the conditions/gotchas here:

  1. Node.js fetch aka undici by default doesn't directly support HTTP/2, but supports body streaming either way.

  2. Browser fetch supports streaming only in HTTP/2 (AFAIK)

  3. Deno fetch is the same

  4. Bun doesn't support HTTP/2 yet

  5. All browsers implement XHR, so it's a safe assumption

perhaps a better set of conditions could be handled, not sure which one to handle all these cases (given that for some platforms streaming is available in both. for some in none and for others only in one)

also, in order to test this more thoroughly, a test case with HTTP/2 server perhaps should be added, but I haven't written one yet (should be trivial enough)

body: Exclude<IpfsUtilsFetchOptions['body'], import('node:stream').Readable>
/**
* Can be passed to track upload progress.
* Note that if this option in passed underlying request will be performed using `XMLHttpRequest` and response will not be streamed.
Copy link
Member

Choose a reason for hiding this comment

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

Note: Response not streaming is not an issue - we don't download anything big in the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants