From 33fc553c55a42d221f63fc390022f4784fd97b90 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 10 Jul 2022 19:54:00 +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=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=8A=D0=B5=D0=B4=D0=B8=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=D0=B7=D0=B8=D1=86=D0=B8=D0=B9=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=BE=D0=B1=D0=BD=D0=B0=D1=80=D1=83=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B8=20=D0=BF=D0=BE=D1=85=D0=BE=D0=B6=D0=B5=D0=B3?= =?UTF-8?q?=D0=BE=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20=D0=B2=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=B6=D0=B5=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/Reader.vue | 31 +++++++++++++++++-- client/components/Reader/share/bookManager.js | 19 ++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/client/components/Reader/Reader.vue b/client/components/Reader/Reader.vue index dd0e294d..e1a786df 100644 --- a/client/components/Reader/Reader.vue +++ b/client/components/Reader/Reader.vue @@ -1090,10 +1090,10 @@ class Reader { progress.show(); progress.setState({state: 'parse'}); - // есть ли среди недавних + // есть ли среди загруженных let wasOpened = bookManager.findRecentByUrlAndPath(url, opts.path); wasOpened = (wasOpened ? _.cloneDeep(wasOpened) : {}); - + wasOpened = Object.assign(wasOpened, { path: (opts.path !== undefined ? opts.path : wasOpened.path), bookPos: (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos), @@ -1166,6 +1166,31 @@ class Reader { progress.setState({progress: prog}); }); + // sameBookKey + if (url.indexOf('disk://') == 0) { + //ищем такой файл в загруженных + let found = bookManager.findRecentBySameBookKey(wasOpened.uploadFileName); + found = (found ? _.cloneDeep(found) : found); + + if (found) { + //спрашиваем, надо ли объединить файлы + const askResult = (wasOpened.path == found.path) || + await this.$root.stdDialog.askYesNo(` +Файл с именем "${wasOpened.uploadFileName}" уже есть в загруженных. +
Объединить позицию?`, 'Найдена похожая книга'); + + if (askResult) { + wasOpened.bookPos = found.bookPos; + wasOpened.bookPosSeen = found.bookPosSeen; + wasOpened.sameBookKey = found.sameBookKey; + } + } else { + wasOpened.sameBookKey = wasOpened.uploadFileName; + } + } else { + wasOpened.sameBookKey = addedBook.url; + } + // добавляем в историю await bookManager.setRecentBook(Object.assign(wasOpened, addedBook)); this.mostRecentBook(); @@ -1217,7 +1242,7 @@ class Reader { progress.hide(); this.progressActive = false; - await this.loadBook({url, uploadFileName: opts.file.name, force: true}); + await this._loadBook({url, uploadFileName: opts.file.name, force: true}); } catch (e) { progress.hide(); this.progressActive = false; this.loaderActive = true; diff --git a/client/components/Reader/share/bookManager.js b/client/components/Reader/share/bookManager.js index b9d0b29e..dbf3cd5f 100644 --- a/client/components/Reader/share/bookManager.js +++ b/client/components/Reader/share/bookManager.js @@ -499,8 +499,23 @@ class BookManager { for (const key in this.recent) { const book = this.recent[key]; - if (!book.deleted && book.url == url && book.addTime > max) { - max = book.addTime; + if (!book.deleted && book.url == url && book.touchTime > max) { + max = book.touchTime; + result = book; + } + } + + return result; + } + + findRecentBySameBookKey(sameKey) { + let max = 0; + let result = null; + + for (const key in this.recent) { + const book = this.recent[key]; + if (!book.deleted && book.sameBookKey == sameKey && book.touchTime > max) { + max = book.touchTime; result = book; } }