Coder Social home page Coder Social logo

the-bugging / react-use-downloader Goto Github PK

View Code? Open in Web Editor NEW
81.0 3.0 6.0 108.29 MB

Creates a download handler function and gives progress information

Home Page: https://www.npmjs.com/package/react-use-downloader

License: MIT License

JavaScript 25.76% HTML 1.87% Shell 0.46% TypeScript 71.91%
react download fetch link anchor cancellable percentage hook downloader

react-use-downloader's People

Contributors

9swampy avatar allcontributors[bot] avatar olavoparno avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-use-downloader's Issues

Invalid hook call issue

Describe the bug
Im always get Invalid Hook Call error in version 1.1.7
Tried to use in CodeSandbox and with older versions working with no problems, but in 1.1.7 doesn't really wants to work.
Copied exactly the same code from this GitHub page, and still get invalid hook call error, so i don't really know what should i do with this

Additional context
A quick screenshot about my problem
image

ReferenceError: process is not defined

Describe the bug
When building with esbuild, I get the following error: ReferenceError: process is not defined.

To Reproduce
Steps to reproduce the behavior:

  1. create a sample app with esbuild
  2. add your component
  3. See error

Additional context

const debugMode = process.env.REACT_APP_DEBUG_MODE;

update to

 const debugMode = process?.env?.REACT_APP_DEBUG_MODE

Hey i'm experiencing some CORS issues, not sure why tho

This is the source:

const { size, elapsed, percentage, download, cancel, error, isInProgress } =
    useDownloader({
     //  mode: 'no-cors'
    });

  const fileUrl = 'https://sample-videos.com/img/Sample-jpg-image-30mb.jpg';
  const filename = 'beautiful-carpathia.jpg';

with mode: 'no-cors' - I get opaque, like this
image

any ideas?

Allow custom timeout

When downloading from a slow backend, the request will time out. Eg. backend takes 10 seconds to generate a file, then react-use-downloader will stop at ~3 seconds

Having an optional flag, such as download(fileUrl, filename, timeout) would be great. For example, timeout could default to 3 seconds, but can be manually overridden

Allow configure fetch (mode, headers to add credentials, etc)

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I need to allow download links from another domain. I am getting this error: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource". It can be fixed by passing "mode: no-cors" to fetch.

If the link need any OAuth Token, or Cookie Token, it must allow passing the Authorization Header, and/or HTTP-Only Cookies.

Describe the solution you'd like
A clear and concise description of what you want to happen.

CORS: It can be fixed by passing "mode: no-cors" to fetch. So you could add a "fetchProps" attribute (fetchProps={{ mode: 'no-cors' }}.
Authorization: It can be fixed by passing "authorization: token" to fetch. So you could add a "fetchProps" attribute (fetchProps={{ credentials: 'include', authToken: token }}.

Headers are not working

Hi, is it possible that header are not passing to the request?
useDownloader({
mode: 'no-cors',
headers: {
'access-control-allow-origin': 'http://localhost:3000',
'access-control-allow-methods': 'PUT, GET, HEAD, POST, DELETE, OPTIONS',
},
});

because I cant see those, and also a I receive an opaque response :(

Thanks!

...options not honoured

Describe the bug
If Fetch RequestInit ...options supplied then the default method: GET overrides supplied.

To Reproduce
Attempt to provide a body; download will error because you can't GET with a body.
useDownloader( { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(''), }

ReferenceError: process is not defined (Part II)

I'm still getting the process is not defined error using 1.2.5.

Implementing akin to how MarcoRS had proposed fixes for me

          still errors when it tries to access process. This worked for me : 
  let debugMode = false;
  try {
    if (process) {
      debugMode = !!process?.env?.REACT_APP_DEBUG_MODE;
    }
  } catch (err) {
    //Your error handling
  }

Originally posted by @MarcosRS in #17 (comment)

Allow options to be updated

Is your feature request related to a problem? Please describe.

Currently, you can only to pass options.headers on first render.
This makes it impossible to 'update' things such as the token, if required.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
setOptions() to update the stored options:
eg:

setOptions({
...options,
headers: {
  Authorization: 'Bearer anUpdatedToken`
}

Describe alternatives you've considered
Right now, I have to wrap my component in another component that async gets the bearer token.
Screenshot 2024-04-16 at 15 39 39

Additional context
Add any other context or screenshots about the feature request here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.