hsmusic / hsmusic-wiki

The Homestuck Music Wiki — static wiki software cataloguing collaborative creation
MIT License
2 stars 6 forks source link

Add generic fetchWithProgress() client utility function #489

Closed towerofnix closed 4 months ago

towerofnix commented 4 months ago

This is basically an updated version of the existing loadImage function we used, which was pulled basically one for one from Parziphal on Stack Overflow: https://stackoverflow.com/a/42196770

The new function's biggest difference is that the resolved value is an ordinary fetch Response object, manually instantiated from an XHR's results, which supports the usual body-access functions. We get blob MIME type detection for free, though we have to manually parse the XHR's headers.

In the future, the guts of this function can probably be rewritten to report progress from a real fetch call and return its response object verbatim! For now all that matters to us is being able to choose whether we want a blob or array buffer out of the response, and building off XHR works fine for that.