Spaces:
Running
Running
Commit
•
3ce1c06
1
Parent(s):
a8b0dee
Update index.html
Browse files- index.html +12 -9
index.html
CHANGED
@@ -50,18 +50,19 @@
|
|
50 |
let totalUploaded = 0;
|
51 |
|
52 |
// Replace the global fetch function
|
|
|
|
|
53 |
fetch = (url, init) => {
|
54 |
-
|
55 |
-
if (isS3Url(url) && init.method === 'PUT') {
|
56 |
return new Promise((resolve, reject) => {
|
57 |
const xhr = new XMLHttpRequest();
|
58 |
-
|
59 |
xhr.open(init.method, url);
|
60 |
-
|
61 |
for (let header in init.headers) {
|
62 |
xhr.setRequestHeader(header, init.headers[header]);
|
63 |
}
|
64 |
-
|
65 |
xhr.onload = () => {
|
66 |
resolve({
|
67 |
ok: xhr.status >= 200 && xhr.status < 300,
|
@@ -71,18 +72,19 @@
|
|
71 |
json: () => Promise.resolve(JSON.parse(xhr.responseText))
|
72 |
});
|
73 |
};
|
74 |
-
|
75 |
xhr.onerror = () => reject(new TypeError('Network request failed'));
|
76 |
xhr.ontimeout = () => reject(new TypeError('Network request failed due to timeout'));
|
77 |
-
|
78 |
xhr.upload.onprogress = (event) => {
|
79 |
if (event.lengthComputable) {
|
80 |
-
|
|
|
81 |
const progressBar = document.getElementById('progressBar');
|
82 |
progressBar.value = totalUploaded;
|
83 |
}
|
84 |
};
|
85 |
-
|
86 |
xhr.send(init.body);
|
87 |
});
|
88 |
} else {
|
@@ -91,6 +93,7 @@
|
|
91 |
}
|
92 |
};
|
93 |
|
|
|
94 |
async function upload() {
|
95 |
const fileInput = document.getElementById('fileUpload');
|
96 |
const files = Array.from(fileInput.files);
|
|
|
50 |
let totalUploaded = 0;
|
51 |
|
52 |
// Replace the global fetch function
|
53 |
+
let progressMap = new Map();
|
54 |
+
|
55 |
fetch = (url, init) => {
|
56 |
+
if (init.method === 'PUT') {
|
|
|
57 |
return new Promise((resolve, reject) => {
|
58 |
const xhr = new XMLHttpRequest();
|
59 |
+
|
60 |
xhr.open(init.method, url);
|
61 |
+
|
62 |
for (let header in init.headers) {
|
63 |
xhr.setRequestHeader(header, init.headers[header]);
|
64 |
}
|
65 |
+
|
66 |
xhr.onload = () => {
|
67 |
resolve({
|
68 |
ok: xhr.status >= 200 && xhr.status < 300,
|
|
|
72 |
json: () => Promise.resolve(JSON.parse(xhr.responseText))
|
73 |
});
|
74 |
};
|
75 |
+
|
76 |
xhr.onerror = () => reject(new TypeError('Network request failed'));
|
77 |
xhr.ontimeout = () => reject(new TypeError('Network request failed due to timeout'));
|
78 |
+
|
79 |
xhr.upload.onprogress = (event) => {
|
80 |
if (event.lengthComputable) {
|
81 |
+
progressMap.set(url, event.loaded);
|
82 |
+
totalUploaded = Array.from(progressMap.values()).reduce((a, b) => a + b, 0);
|
83 |
const progressBar = document.getElementById('progressBar');
|
84 |
progressBar.value = totalUploaded;
|
85 |
}
|
86 |
};
|
87 |
+
|
88 |
xhr.send(init.body);
|
89 |
});
|
90 |
} else {
|
|
|
93 |
}
|
94 |
};
|
95 |
|
96 |
+
|
97 |
async function upload() {
|
98 |
const fileInput = document.getElementById('fileUpload');
|
99 |
const files = Array.from(fileInput.files);
|