Небольшое улучшение
This commit is contained in:
@@ -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') {
|
if (response.data.state == 'finish') {//воркер закончил работу, можно скачивать
|
||||||
const book = await axios.get(response.data.path, {});
|
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});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user