From ccfc26276204e0d2c7073b0e15708154ec9df3c4 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 13 Jan 2019 03:39:39 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=BE=D0=B5=20=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/api/reader.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/client/api/reader.js b/client/api/reader.js index 33b69fd6..add90583 100644 --- a/client/api/reader.js +++ b/client/api/reader.js @@ -23,8 +23,18 @@ class Reader { while (1) {// eslint-disable-line no-constant-condition if (callback) 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}); } if (response.data.state == 'error') { @@ -42,6 +52,7 @@ class Reader { if (i > 30*1000/refreshPause) { throw new Error('Слишком долгое время ожидания'); } + //проверка воркера response = await workerApi.post('/get-state', {workerId}); } }