mirror of
https://github.com/wukko/cobalt.git
synced 2025-05-24 18:42:09 +02:00
web/workers/fetch: rename totalBytes to expectedSize
This commit is contained in:
parent
5cd911bbde
commit
c647e191f3
@ -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,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user