From f44378ec84c72f08088c727909f1367e603fc450 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 20 Nov 2020 18:25:24 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecentBooksPage/RecentBooksPage.vue | 29 ++--------- .../components/Reader/TextPage/TextPage.vue | 49 +++++++------------ client/components/Reader/share/BookParser.js | 2 + client/share/utils.js | 38 ++++++++++++++ 4 files changed, 63 insertions(+), 55 deletions(-) diff --git a/client/components/Reader/RecentBooksPage/RecentBooksPage.vue b/client/components/Reader/RecentBooksPage/RecentBooksPage.vue index 96f677b0..d51b1b6f 100644 --- a/client/components/Reader/RecentBooksPage/RecentBooksPage.vue +++ b/client/components/Reader/RecentBooksPage/RecentBooksPage.vue @@ -87,7 +87,7 @@ import Vue from 'vue'; import Component from 'vue-class-component'; import path from 'path'; -import _ from 'lodash'; +//import _ from 'lodash'; import * as utils from '../../../share/utils'; import Window from '../../share/Window.vue'; @@ -222,30 +222,11 @@ class RecentBooksPage extends Vue { textLen = ` ${Math.round(book.textLength/1000)}k`; } - const fb2 = (book.fb2 ? book.fb2 : {}); + const bt = utils.getBookTitle(book.fb2); - let title = fb2.bookTitle; - if (title) - title = `"${title}"`; - else - title = ''; - - let author = ''; - if (fb2.author) { - const authorNames = fb2.author.map(a => _.compact([ - a.lastName, - a.firstName, - a.middleName - ]).join(' ')); - author = authorNames.join(', '); - } else {//TODO: убрать в будущем - author = _.compact([ - fb2.lastName, - fb2.firstName, - fb2.middleName - ]).join(' '); - } - author = (author ? author : (fb2.bookTitle ? fb2.bookTitle : book.url)); + let title = bt.bookTitle; + title = (title ? `"${title}"`: ''); + const author = (bt.author ? bt.author : (bt.bookTitle ? bt.bookTitle : book.url)); result.push({ num, diff --git a/client/components/Reader/TextPage/TextPage.vue b/client/components/Reader/TextPage/TextPage.vue index 04c3d897..a2c53866 100644 --- a/client/components/Reader/TextPage/TextPage.vue +++ b/client/components/Reader/TextPage/TextPage.vue @@ -40,7 +40,7 @@ import Component from 'vue-class-component'; import {loadCSS} from 'fg-loadcss'; import _ from 'lodash'; -import {sleep} from '../../../share/utils'; +import * as utils from '../../../share/utils'; import bookManager from '../share/bookManager'; import DrawHelper from './DrawHelper'; import rstore from '../../../store/modules/reader'; @@ -134,7 +134,7 @@ class TextPage extends Vue { this.$root.$on('resize', async() => { this.$nextTick(this.onResize); - await sleep(500); + await utils.sleep(500); this.$nextTick(this.onResize); }); } @@ -285,7 +285,7 @@ class TextPage extends Vue { let close = null; (async() => { - await sleep(500); + await utils.sleep(500); if (this.fontsLoading) close = this.$root.notify.info('Загрузка шрифта  '); })(); @@ -342,7 +342,7 @@ class TextPage extends Vue { let i = 0; const t = this.parsed.testText; while (i++ < 50 && this.parsed === parsed && this.drawHelper.measureText(t, {}) === this.parsed.testWidth) - await sleep(100); + await utils.sleep(100); if (this.parsed === parsed) { this.parsed.testWidth = this.drawHelper.measureText(t, {}); @@ -366,7 +366,6 @@ class TextPage extends Vue { this.updateLayout(); this.book = null; this.meta = null; - this.fb2 = null; this.parsed = null; this.linesUp = null; @@ -383,7 +382,7 @@ class TextPage extends Vue { try { //подождем ленивый парсинг this.stopLazyParse = true; - while (this.doingLazyParse) await sleep(10); + while (this.doingLazyParse) await utils.sleep(10); const isParsed = await bookManager.hasBookParsed(this.lastBook); if (!isParsed) { @@ -392,21 +391,9 @@ class TextPage extends Vue { this.book = await bookManager.getBook(this.lastBook); this.meta = bookManager.metaOnly(this.book); - this.fb2 = this.meta.fb2; + const bt = utils.getBookTitle(this.meta.fb2); - let authorNames = []; - if (this.fb2.author) { - authorNames = this.fb2.author.map(a => _.compact([ - a.lastName, - a.firstName, - a.middleName - ]).join(' ')); - } - - this.title = _.compact([ - authorNames.join(', '), - this.fb2.bookTitle - ]).join(' - '); + this.title = bt.title; this.$root.$emit('set-app-title', this.title); @@ -493,7 +480,7 @@ class TextPage extends Vue { let wait = (timeout + 201)/100; while (wait > 0 && !this[stopPropertyName]) { wait--; - await sleep(100); + await utils.sleep(100); } resolve(); })().catch(reject); }); @@ -509,7 +496,7 @@ class TextPage extends Vue { } //ждем анимацию - while (this.inAnimation) await sleep(10); + while (this.inAnimation) await utils.sleep(10); this.stopScrolling = false; this.doingScrolling = true; @@ -520,7 +507,7 @@ class TextPage extends Vue { this.page1 = this.page2; this.toggleLayout = true; await this.$nextTick(); - await sleep(50); + await utils.sleep(50); this.cachedPos = -1; this.draw(); @@ -557,7 +544,7 @@ class TextPage extends Vue { page.style.transform = 'none'; page.offsetHeight; - while (this.doingScrolling) await sleep(10); + while (this.doingScrolling) await utils.sleep(10); } draw() { @@ -766,7 +753,7 @@ class TextPage extends Vue { for (let i = 0; i < this.parsed.para.length; i++) { j++; if (j > 1) { - await sleep(1); + await utils.sleep(1); j = 0; } if (this.stopLazyParse) @@ -788,7 +775,7 @@ class TextPage extends Vue { async refreshTime() { if (!this.timeRefreshing) { this.timeRefreshing = true; - await sleep(60*1000); + await utils.sleep(60*1000); if (this.book && this.parsed.textLength) { this.debouncedDrawStatusBar(); @@ -905,7 +892,7 @@ class TextPage extends Vue { this.settingsChanging = true; const newSize = (this.settings.fontSize + 1 < 200 ? this.settings.fontSize + 1 : 100); this.commit('reader/setSettings', {fontSize: newSize}); - await sleep(50); + await utils.sleep(50); this.settingsChanging = false; } } @@ -915,7 +902,7 @@ class TextPage extends Vue { this.settingsChanging = true; const newSize = (this.settings.fontSize - 1 > 5 ? this.settings.fontSize - 1 : 5); this.commit('reader/setSettings', {fontSize: newSize}); - await sleep(50); + await utils.sleep(50); this.settingsChanging = false; } } @@ -925,7 +912,7 @@ class TextPage extends Vue { this.settingsChanging = true; const newDelay = (this.settings.scrollingDelay - 50 > 1 ? this.settings.scrollingDelay - 50 : 1); this.commit('reader/setSettings', {scrollingDelay: newDelay}); - await sleep(50); + await utils.sleep(50); this.settingsChanging = false; } } @@ -935,7 +922,7 @@ class TextPage extends Vue { this.settingsChanging = true; const newDelay = (this.settings.scrollingDelay + 50 < 10000 ? this.settings.scrollingDelay + 50 : 10000); this.commit('reader/setSettings', {scrollingDelay: newDelay}); - await sleep(50); + await utils.sleep(50); this.settingsChanging = false; } } @@ -949,7 +936,7 @@ class TextPage extends Vue { let delay = 400; while (this.repDoing) { this.handleClick(pointX, pointY); - await sleep(delay); + await utils.sleep(delay); if (delay > 15) delay *= 0.8; } diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index f368b6be..1121e70c 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -455,6 +455,8 @@ export default class BookParser { return {fb2}; } + getAuthor + findParaIndex(bookPos) { let result = undefined; //дихотомия diff --git a/client/share/utils.js b/client/share/utils.js index c773159b..7e440799 100644 --- a/client/share/utils.js +++ b/client/share/utils.js @@ -308,3 +308,41 @@ export function userHotKeysObjectSwap(userHotKeys) { export function removeHtmlTags(s) { return s.replace(/(<([^>]+)>)/ig, ''); } + +export function makeValidFilename(filename, repl = '_') { + let f = filename.replace(/[\x00\\/:*"<>|]/g, repl); // eslint-disable-line no-control-regex + f = f.trim(); + while (f.length && (f[f.length - 1] == '.' || f[f.length - 1] == '_')) { + f = f.substring(0, f.length - 1); + } + + if (f) + return f; + else + throw new Error('Invalid filename'); +} + +export function getBookTitle(fb2) { + fb2 = (fb2 ? fb2 : {}); + const result = {}; + + if (fb2.author) { + const authorNames = fb2.author.map(a => _.compact([ + a.lastName, + a.firstName, + a.middleName + ]).join(' ')); + + result.author = authorNames.join(', '); + } + + if (fb2.bookTitle) + result.bookTitle = fb2.bookTitle; + + result.title = _.compact([ + result.author, + result.bookTitle + ]).join(' - '); + + return result; +} \ No newline at end of file