From 84e816099986946e50b19d91e2d592314dc7e6a4 Mon Sep 17 00:00:00 2001 From: jj Date: Wed, 23 Apr 2025 16:48:58 +0000 Subject: [PATCH] web/fetch: use estimated length only for progress reports --- web/src/lib/task-manager/workers/fetch.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web/src/lib/task-manager/workers/fetch.ts b/web/src/lib/task-manager/workers/fetch.ts index 98c9dad2..e51fc884 100644 --- a/web/src/lib/task-manager/workers/fetch.ts +++ b/web/src/lib/task-manager/workers/fetch.ts @@ -34,10 +34,17 @@ const fetchFile = async (url: string) => { const contentType = response.headers.get('Content-Type') || 'application/octet-stream'; - const contentLength = response.headers.get('Content-Length') - || response.headers.get('Estimated-Content-Length'); + const contentLength = response.headers.get('Content-Length'); + const estimatedLength = response.headers.get('Estimated-Content-Length'); + + let totalBytes = null; + + if (contentLength) { + totalBytes = +contentLength; + } else if (estimatedLength) { + totalBytes = +estimatedLength; + } - const totalBytes = contentLength ? parseInt(contentLength, 10) : null; const reader = response.body?.getReader(); const storage = await OPFSStorage.init(); @@ -71,7 +78,7 @@ const fetchFile = async (url: string) => { const file = await storage.res(); - if (Number(contentLength) !== file.size) { + if (contentLength && Number(contentLength) !== file.size) { return error("file was not downloaded fully"); }