diff --git a/packages/forms/src/components/form/UploadBigFile/uploadBigFileClient.ts b/packages/forms/src/components/form/UploadBigFile/uploadBigFileClient.ts index 738306a..e277d19 100644 --- a/packages/forms/src/components/form/UploadBigFile/uploadBigFileClient.ts +++ b/packages/forms/src/components/form/UploadBigFile/uploadBigFileClient.ts @@ -60,7 +60,7 @@ async function uploadBigFile(fileId: string, file: File, progressCallback: Progr const activeLoads = new Map(); let finishedSize = 0; - for (let i = 0; i < totalChunks; i++) { + const uploadChunk = async (i: number) => { while (activeChunks.size >= options.parallelChunks) { await Promise.race(activeChunks); } @@ -90,6 +90,10 @@ async function uploadBigFile(fileId: string, file: File, progressCallback: Progr try { const response: any = await upload; + if(response?.missingChunk){ + await uploadChunk(response?.missingChunk - 1); + } + if (!response?.ok) { throw new Error(response.error); } @@ -108,6 +112,10 @@ async function uploadBigFile(fileId: string, file: File, progressCallback: Progr activeChunks.add(uploadPromiseWithRetry); } + for (let i = 0; i < totalChunks; i++) { + await uploadChunk(i); + } + await Promise.all(activeChunks); } diff --git a/packages/forms/src/components/form/UploadBigFile/uploadBigFileServer.ts b/packages/forms/src/components/form/UploadBigFile/uploadBigFileServer.ts index ab862b8..a9e4cbd 100644 --- a/packages/forms/src/components/form/UploadBigFile/uploadBigFileServer.ts +++ b/packages/forms/src/components/form/UploadBigFile/uploadBigFileServer.ts @@ -68,13 +68,15 @@ export async function loadUploadFiles(astro: AstroGlobal, options: Partial { - await fsExtra.emptyDir(uploadDir); + const sendError = async (errorMessage: string, emptyDir = true, extraInfo?: any) => { + if(emptyDir){ + await fsExtra.emptyDir(uploadDir); + } const errorPath = path.join(uploadDir, 'error.txt'); if (!await checkIfFileExists(errorPath)) { await fs.writeFile(path.join(uploadDir, 'error.txt'), errorMessage); } - return Response.json({ ok: false, error: errorMessage }); + return Response.json({ ok: false, error: errorMessage, ...extraInfo }); }; if (typeof allowUpload === "function") { @@ -105,7 +107,8 @@ export async function loadUploadFiles(astro: AstroGlobal, options: Partial