From d7175d0fc5959beb568eea07bfa73ea6d196e23f Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 10 Feb 2019 16:18:39 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B5=D1=81=D1=81=D0=B0?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/api/reader.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/client/api/reader.js b/client/api/reader.js index d8ca7348..cddb3c38 100644 --- a/client/api/reader.js +++ b/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)}); } } //загрузка