From 6ab960d399fe3f8e5461a4d206b595a88fe1da92 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 18 Sep 2024 23:56:00 +0800 Subject: [PATCH] :rewind: Rollback to fix bugs --- pages/gallery/new.vue | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/pages/gallery/new.vue b/pages/gallery/new.vue index b65f7ab..9f816e5 100644 --- a/pages/gallery/new.vue +++ b/pages/gallery/new.vue @@ -133,34 +133,11 @@ async function submit() { } } - const queue = [] - const limit = 3 // Set the concurrency limit - - for (let i = 0; i < chunks.length; i++) { - // Wrap the promise with an object that holds the promise itself - const task = uploadChunks(chunks[i]).then( - () => ({ chunk: chunks[i], status: "fulfilled" }), - () => ({ chunk: chunks[i], status: "rejected" }), - ) - - queue.push(task) - - // If the number of running tasks exceeds the limit, wait for one to finish - if (queue.length >= limit) { - // Wait for any one task to finish - const finishedTask = await Promise.race(queue) - - // Find and remove the finished task's promise from the queue - queue.splice( - queue.findIndex((p) => p === task), - 1, - ) - } + for (let i = 0; i < chunks.length; i += limit) { + const chunkSlice = chunks.slice(i, i + limit) + await Promise.all(chunkSlice.map(uploadChunks)) } - // Await remaining tasks after the loop finishes - await Promise.all(queue) - if (multipartInfo.value["is_uploaded"]) { console.log(`[PAPERCLIP] Entire file has been uploaded in ${multipartProgress.total} chunk(s)`) success.value = true