Spaces:
Running
Running
Commit
·
493c49f
1
Parent(s):
0bf58c1
Update index.html
Browse files- index.html +13 -7
index.html
CHANGED
@@ -37,14 +37,18 @@
|
|
37 |
uploadButton.addEventListener('click', upload);
|
38 |
|
39 |
function isS3Url(url) {
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
43 |
}
|
44 |
|
45 |
// Save the original fetch function
|
46 |
const originalFetch = fetch;
|
47 |
|
|
|
|
|
|
|
48 |
// Replace the global fetch function
|
49 |
fetch = (url, init) => {
|
50 |
if (isS3Url(url) && init.method === 'PUT') {
|
@@ -72,8 +76,9 @@
|
|
72 |
|
73 |
xhr.upload.onprogress = (event) => {
|
74 |
if (event.lengthComputable) {
|
|
|
75 |
const progressBar = document.getElementById('progressBar');
|
76 |
-
progressBar.value =
|
77 |
}
|
78 |
};
|
79 |
|
@@ -106,7 +111,8 @@
|
|
106 |
for (let file of files) {
|
107 |
totalSize += file.size;
|
108 |
}
|
109 |
-
|
|
|
110 |
|
111 |
const startTime = Date.now();
|
112 |
|
@@ -133,7 +139,7 @@
|
|
133 |
});
|
134 |
|
135 |
console.log(`All files uploaded successfully`);
|
136 |
-
progressBar.value =
|
137 |
} catch (error) {
|
138 |
console.error('Error uploading files', error);
|
139 |
errorDiv.textContent = 'Error uploading files';
|
@@ -155,4 +161,4 @@
|
|
155 |
}
|
156 |
</script>
|
157 |
</body>
|
158 |
-
</html>
|
|
|
37 |
uploadButton.addEventListener('click', upload);
|
38 |
|
39 |
function isS3Url(url) {
|
40 |
+
// The condition to identify S3 URLs and other URLs to track
|
41 |
+
return url.startsWith('https://s3.amazonaws.com/') ||
|
42 |
+
url.includes('preupload/main') ||
|
43 |
+
url.includes('commit/main');
|
44 |
}
|
45 |
|
46 |
// Save the original fetch function
|
47 |
const originalFetch = fetch;
|
48 |
|
49 |
+
// Create a variable to track the total uploaded size
|
50 |
+
let totalUploaded = 0;
|
51 |
+
|
52 |
// Replace the global fetch function
|
53 |
fetch = (url, init) => {
|
54 |
if (isS3Url(url) && init.method === 'PUT') {
|
|
|
76 |
|
77 |
xhr.upload.onprogress = (event) => {
|
78 |
if (event.lengthComputable) {
|
79 |
+
totalUploaded += event.loaded;
|
80 |
const progressBar = document.getElementById('progressBar');
|
81 |
+
progressBar.value = totalUploaded;
|
82 |
}
|
83 |
};
|
84 |
|
|
|
111 |
for (let file of files) {
|
112 |
totalSize += file.size;
|
113 |
}
|
114 |
+
progressBar.max = totalSize; // Set the max value of progress bar
|
115 |
+
totalUploaded = 0; // Reset total uploaded size
|
116 |
|
117 |
const startTime = Date.now();
|
118 |
|
|
|
139 |
});
|
140 |
|
141 |
console.log(`All files uploaded successfully`);
|
142 |
+
progressBar.value = totalSize;
|
143 |
} catch (error) {
|
144 |
console.error('Error uploading files', error);
|
145 |
errorDiv.textContent = 'Error uploading files';
|
|
|
161 |
}
|
162 |
</script>
|
163 |
</body>
|
164 |
+
</html>
|