web/workers/fetch: rename totalBytes to expectedSize

This commit is contained in:
jj 2025-05-23 15:55:25 +00:00
parent 5cd911bbde
commit c647e191f3
No known key found for this signature in database

View File

@ -32,17 +32,17 @@ const fetchFile = async (url: string) => {
const contentLength = response.headers.get('Content-Length'); const contentLength = response.headers.get('Content-Length');
const estimatedLength = response.headers.get('Estimated-Content-Length'); const estimatedLength = response.headers.get('Estimated-Content-Length');
let totalBytes; let expectedSize;
if (contentLength) { if (contentLength) {
totalBytes = +contentLength; expectedSize = +contentLength;
} else if (estimatedLength) { } else if (estimatedLength) {
totalBytes = +estimatedLength; expectedSize = +estimatedLength;
} }
const reader = response.body?.getReader(); const reader = response.body?.getReader();
const storage = await Storage.init(totalBytes); const storage = await Storage.init(expectedSize);
if (!reader) { if (!reader) {
return error("queue.fetch.no_file_reader"); return error("queue.fetch.no_file_reader");
@ -57,10 +57,10 @@ const fetchFile = async (url: string) => {
await storage.write(value, receivedBytes); await storage.write(value, receivedBytes);
receivedBytes += value.length; receivedBytes += value.length;
if (totalBytes) { if (expectedSize) {
self.postMessage({ self.postMessage({
cobaltFetchWorker: { cobaltFetchWorker: {
progress: Math.round((receivedBytes / totalBytes) * 100), progress: Math.round((receivedBytes / expectedSize) * 100),
size: receivedBytes, size: receivedBytes,
} }
}); });