Compare commits

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