Поправки прогресса загрузки

This commit is contained in:
Book Pauk
2019-02-10 16:18:39 +07:00
parent aac8338025
commit d7175d0fc5

View File

@@ -56,11 +56,19 @@ class Reader {
} }
async loadCachedBook(url, callback){ async loadCachedBook(url, callback){
const response = await axios.get(url, {method: 'HEAD'});
let estSize = 1000000;
if (response.headers['content-length']) {
estSize = response.headers['content-length'];
}
const options = { const options = {
onDownloadProgress: progress => { onDownloadProgress: progress => {
const total = (progress.total ? progress.total : progress.loaded + 200000); while (progress.loaded > estSize) estSize *= 1.5;
if (callback) if (callback)
callback({state: 'loading', progress: Math.round((progress.loaded*100)/total)}); callback({state: 'loading', progress: Math.round((progress.loaded*100)/estSize)});
} }
} }
//загрузка //загрузка