« get me outta code hell

url-spec, web-routes, content: static subdirectories - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static/xhr-util.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-21 08:50:20 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-21 08:50:20 -0300
commit9c00d5b47d82da80605d78b762777aeb9a972e21 (patch)
treead8354551693f24072f75171b38756154f8d7ded /src/static/xhr-util.js
parentdc318c6db0b92510e8297739f4f6999f24859215 (diff)
url-spec, web-routes, content: static subdirectories
Diffstat (limited to 'src/static/xhr-util.js')
-rw-r--r--src/static/xhr-util.js64
1 files changed, 0 insertions, 64 deletions
diff --git a/src/static/xhr-util.js b/src/static/xhr-util.js
deleted file mode 100644
index 8a43072c..00000000
--- a/src/static/xhr-util.js
+++ /dev/null
@@ -1,64 +0,0 @@
-/* eslint-env browser */
-
-/**
- * This fetch function is adapted from a `loadImage` function
- * credited to Parziphal, Feb 13, 2017.
- * https://stackoverflow.com/a/42196770
- *
- * The callback is generally run with the loading progress as a decimal 0-1.
- * However, if it's not possible to compute the progress ration (which might
- * only become apparent after a progress amount *has* been sent!),
- * the callback will be run with the value -1.
- *
- * The return promise resolves to a manually instantiated Response object
- * which generally behaves the same as a normal fetch response; access headers,
- * text, blob, arrayBuffer as usual. Accordingly, non-200 responses do *not*
- * reject the prmoise, so be sure to check the response status yourself.
- */
-export function fetchWithProgress(url, progressCallback) {
-  return new Promise(resolve => {
-    const xhr = new XMLHttpRequest();
-    let notifiedNotComputable = false;
-
-    xhr.open('GET', url, true);
-    xhr.responseType = 'arraybuffer';
-
-    xhr.onprogress = event => {
-      if (notifiedNotComputable) {
-        return;
-      }
-
-      if (!event.lengthComputable) {
-        notifiedNotComputable = true;
-        progressCallback(-1);
-        return;
-      }
-
-      progressCallback(event.loaded / event.total);
-    };
-
-    xhr.onloadend = () => {
-      const body = xhr.response;
-
-      const options = {
-        status: xhr.status,
-        headers:
-          parseResponseHeaders(xhr.getAllResponseHeaders()),
-      };
-
-      resolve(new Response(body, options));
-    };
-
-    xhr.send();
-  });
-
-  function parseResponseHeaders(headers) {
-    return (
-      Object.fromEntries(
-        headers
-          .trim()
-          .split(/[\r\n]+/)
-          .map(line => line.match(/(.+?):\s*(.+)/))
-          .map(match => [match[1], match[2]])));
-  }
-}