瀏覽代碼

Небольшое улучшение

Book Pauk 6 年之前
父節點
當前提交
ccfc262762
共有 1 個文件被更改,包括 13 次插入2 次删除
  1. 13 2
      client/api/reader.js

+ 13 - 2
client/api/reader.js

@@ -23,8 +23,18 @@ class Reader {
         while (1) {// eslint-disable-line no-constant-condition
         while (1) {// eslint-disable-line no-constant-condition
             if (callback)
             if (callback)
                 callback(response.data);
                 callback(response.data);
-            if (response.data.state == 'finish') {
-                const book = await axios.get(response.data.path, {});
+            if (response.data.state == 'finish') {//воркер закончил работу, можно скачивать
+                const options = {
+                    onDownloadProgress: progress => {
+                        if (callback)
+                            callback(Object.assign({}, 
+                                response.data, 
+                                {state: 'loading', stage: 4, progress: Math.round((progress.loaded*100)/progress.total)}
+                            ));
+                    }
+                }
+                //загрузка
+                const book = await axios.get(response.data.path, options);
                 return Object.assign({}, response.data, {data: book.data});
                 return Object.assign({}, response.data, {data: book.data});
             }
             }
             if (response.data.state == 'error') {
             if (response.data.state == 'error') {
@@ -42,6 +52,7 @@ class Reader {
             if (i > 30*1000/refreshPause) {
             if (i > 30*1000/refreshPause) {
                 throw new Error('Слишком долгое время ожидания');
                 throw new Error('Слишком долгое время ожидания');
             }
             }
+            //проверка воркера
             response = await workerApi.post('/get-state', {workerId});
             response = await workerApi.post('/get-state', {workerId});
         }
         }
     }
     }