Browse Source

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

Book Pauk 6 years ago
parent
commit
d7175d0fc5
1 changed files with 10 additions and 2 deletions
  1. 10 2
      client/api/reader.js

+ 10 - 2
client/api/reader.js

@@ -56,11 +56,19 @@ class Reader {
     }
 
     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 = {
             onDownloadProgress: progress => {
-                const total = (progress.total ? progress.total : progress.loaded + 200000);
+                while (progress.loaded > estSize) estSize *= 1.5;
+
                 if (callback)
-                    callback({state: 'loading', progress: Math.round((progress.loaded*100)/total)});
+                    callback({state: 'loading', progress: Math.round((progress.loaded*100)/estSize)});
             }
         }
         //загрузка