From eebf17c42ce2d88b2634f332e1dd98026977dc4e Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 27 Nov 2019 17:12:07 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=BB=D0=B8=D1=87=D0=B8=D1=8F=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=B0=20=D0=BD=D0=B0=20=D1=81=D0=B5=D1=80=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=20=D1=81?= =?UTF-8?q?=D0=BA=D0=B0=D1=87=D0=B8=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC=20?= =?UTF-8?q?fb2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/api/reader.js | 6 +++++- .../RecentBooksPage/RecentBooksPage.vue | 20 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/client/api/reader.js b/client/api/reader.js index 52bfbde6..b3e2da87 100644 --- a/client/api/reader.js +++ b/client/api/reader.js @@ -56,7 +56,11 @@ class Reader { } } - async loadCachedBook(url, callback){ + async checkUrl(url) { + return await axios.head(url, {headers: {'Cache-Control': 'no-cache'}}); + } + + async loadCachedBook(url, callback) { const response = await axios.head(url); let estSize = 1000000; diff --git a/client/components/Reader/RecentBooksPage/RecentBooksPage.vue b/client/components/Reader/RecentBooksPage/RecentBooksPage.vue index 200dc9c1..c39e8845 100644 --- a/client/components/Reader/RecentBooksPage/RecentBooksPage.vue +++ b/client/components/Reader/RecentBooksPage/RecentBooksPage.vue @@ -5,6 +5,7 @@ Список загружается + @@ -104,6 +105,7 @@ import _ from 'lodash'; import * as utils from '../../../share/utils'; import Window from '../../share/Window.vue'; import bookManager from '../share/bookManager'; +import readerApi from '../../../api/reader'; export default @Component({ components: { @@ -268,8 +270,20 @@ class RecentBooksPage extends Vue { return result; } - getFileNameFromPath(fb2Path) { - return path.basename(fb2Path).substr(0, 10) + '.fb2'; + async downloadBook(fb2path) { + try { + await readerApi.checkUrl(fb2path); + + const d = this.$refs.download; + d.href = fb2path; + d.download = path.basename(fb2path).substr(0, 10) + '.fb2'; + d.click(); + } catch (e) { + let errMes = e.message; + if (errMes.indexOf('404') >= 0) + errMes = 'Файл не найден на сервере (возможно был удален как устаревший)'; + this.$alert(errMes, 'Ошибка', {type: 'error'}); + } } openOriginal(url) {