Compare commits

...
2 Commits
+9 -8
View File
@@ -117,10 +117,10 @@ document.addEventListener("DOMContentLoaded", () => {
: "Uploading..."; : "Uploading...";
const MAX_CONCURRENCY = 4; const MAX_CONCURRENCY = 4;
let uploadFailed = false; let failedChunksCount = 0;
async function worker() { async function worker() {
while (pendingIndices.length > 0 && !uploadFailed) { while (pendingIndices.length > 0) {
const index = pendingIndices.shift(); const index = pendingIndices.shift();
const start = index * CHUNK_SIZE; const start = index * CHUNK_SIZE;
const end = Math.min(start + CHUNK_SIZE, file.size); const end = Math.min(start + CHUNK_SIZE, file.size);
@@ -149,7 +149,9 @@ document.addEventListener("DOMContentLoaded", () => {
}); });
if (!response.ok) { if (!response.ok) {
throw new Error(`Chunk ${index} failed`); throw new Error(
`Chunk ${index} failed with status ${response.status}`,
);
} }
chunkCheckmark?.classList.remove("hidden"); chunkCheckmark?.classList.remove("hidden");
@@ -159,8 +161,8 @@ document.addEventListener("DOMContentLoaded", () => {
chunkStatus.innerText = "Succeeded"; chunkStatus.innerText = "Succeeded";
} }
} catch (err) { } catch (err) {
console.err(err); console.error(`Chunk ${index} failed:`, err);
uploadFailed = true; failedChunksCount++;
chunkRedX?.classList.remove("hidden"); chunkRedX?.classList.remove("hidden");
chunkSpinner?.classList.add("hidden"); chunkSpinner?.classList.add("hidden");
@@ -181,11 +183,10 @@ document.addEventListener("DOMContentLoaded", () => {
await Promise.all(workers); await Promise.all(workers);
if (uploadFailed) { if (failedChunksCount > 0) {
fileSpinnerElement?.classList.add("hidden"); fileSpinnerElement?.classList.add("hidden");
fileRedXElement?.classList.remove("hidden"); fileRedXElement?.classList.remove("hidden");
fileStatusElement.innerText = fileStatusElement.innerText = `${failedChunksCount} chunk(s) failed. Select file again to resume.`;
"Upload paused/failed. Select file again to resume.";
return; return;
} }