diff --git a/client/api/misc.js b/client/api/misc.js index 94ebdab5..04fe804b 100644 --- a/client/api/misc.js +++ b/client/api/misc.js @@ -6,7 +6,7 @@ const api = axios.create({ class Misc { async loadConfig() { - const response = await api.post('/config', {params: ['name', 'version', 'mode', 'maxUploadFileSize']}); + const response = await api.post('/config', {params: ['name', 'version', 'mode', 'maxUploadFileSize', 'branch']}); return response.data; } } diff --git a/client/components/App.vue b/client/components/App.vue index d189863e..7cb8b160 100644 --- a/client/components/App.vue +++ b/client/components/App.vue @@ -210,7 +210,7 @@ class App extends Vue { } //yandex-метрика для omnireader - if (this.mode == 'omnireader' && !this.yaMetricsDone) { + if (this.config.branch == 'production' && this.mode == 'omnireader' && !this.yaMetricsDone) { (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)}) (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");// eslint-disable-line no-unexpected-multiline diff --git a/client/components/Reader/HistoryPage/HistoryPage.vue b/client/components/Reader/HistoryPage/HistoryPage.vue index a9884b13..ea24ec44 100644 --- a/client/components/Reader/HistoryPage/HistoryPage.vue +++ b/client/components/Reader/HistoryPage/HistoryPage.vue @@ -126,8 +126,10 @@ class HistoryPage extends Vue { updateTableData() { let result = []; - for (let bookKey in bookManager.recent) { - const book = bookManager.recent[bookKey]; + const sorted = bookManager.getSortedRecent(); + const len = (sorted.length < 100 ? sorted.length : 100); + for (let i = 0; i < len; i++) { + const book = sorted[i]; let d = new Date(); d.setTime(book.touchTime); const t = formatDate(d).split(' '); diff --git a/client/components/Reader/TextPage/TextPage.vue b/client/components/Reader/TextPage/TextPage.vue index 4d604d59..ea1395a5 100644 --- a/client/components/Reader/TextPage/TextPage.vue +++ b/client/components/Reader/TextPage/TextPage.vue @@ -569,7 +569,7 @@ class TextPage extends Vue { } if (this.book && this.bookPos > 0 && this.bookPos >= this.parsed.textLength) { - this.doEnd(); + this.doEnd(true); return; } @@ -591,7 +591,7 @@ class TextPage extends Vue { this.debouncedDrawStatusBar(); if (this.book && this.linesDown && this.linesDown.length < this.pageLineCount) { - this.doEnd(); + this.doEnd(true); return; } } @@ -822,7 +822,7 @@ class TextPage extends Vue { this.bookPos = 0; } - doEnd() { + doEnd(noAni) { if (this.parsed.para.length && this.pageLineCount > 0) { let i = this.parsed.para.length - 1; let lastPos = this.parsed.para[i].offset + this.parsed.para[i].length - 1; @@ -830,7 +830,8 @@ class TextPage extends Vue { if (lines) { i = this.pageLineCount - 1; i = (i > lines.length - 1 ? lines.length - 1 : i); - this.currentAnimation = this.pageChangeAnimation; + if (!noAni) + this.currentAnimation = this.pageChangeAnimation; this.pageChangeDirectionDown = true; this.bookPos = lines[i].begin; } diff --git a/client/components/Reader/share/bookManager.js b/client/components/Reader/share/bookManager.js index 67b9b812..12215372 100644 --- a/client/components/Reader/share/bookManager.js +++ b/client/components/Reader/share/bookManager.js @@ -22,7 +22,8 @@ class BookManager { this.settings = settings; this.books = {}; this.recent = {}; - this.recentChanged = true; + this.recentChanged1 = true; + this.recentChanged2 = true; let len = await bmMetaStore.length(); for (let i = 0; i < len; i++) { @@ -170,7 +171,8 @@ class BookManager { await bmRecentStore.setItem(result.key, result); await this.cleanRecentBooks(); - this.recentChanged = true; + this.recentChanged1 = true; + this.recentChanged2 = true; return result; } @@ -186,14 +188,15 @@ class BookManager { await bmRecentStore.removeItem(value.key); delete this.recent[value.key]; - this.recentChanged = true; + this.recentChanged1 = true; + this.recentChanged2 = true; } async cleanRecentBooks() { if (!this.recent) await this.init(); - if (Object.keys(this.recent).length > 100) { + if (Object.keys(this.recent).length > 1000) { let min = Date.now(); let found = null; for (let key in this.recent) { @@ -212,7 +215,7 @@ class BookManager { } mostRecentBook() { - if (!this.recentChanged && this.mostRecentCached) { + if (!this.recentChanged1 && this.mostRecentCached) { return this.mostRecentCached; } @@ -226,10 +229,25 @@ class BookManager { } } this.mostRecentCached = result; - this.recentChanged = false; + this.recentChanged1 = false; return result; } + getSortedRecent() { + if (!this.recentChanged2 && this.sortedRecentCached) { + return this.sortedRecentCached; + } + + let result = Object.values(this.recent); + + result.sort((a, b) => b.touchTime - a.touchTime); + + this.sortedRecentCached = result; + this.recentChanged2 = false; + return result; + } + + } export default new BookManager(); \ No newline at end of file diff --git a/package.json b/package.json index 23f3bd9f..597de2c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Liberama", - "version": "0.2.1", + "version": "0.2.2", "engines": { "node": ">=10.0.0" }, diff --git a/server/core/BookConverter/index.js b/server/core/BookConverter/index.js index c884a222..f8100915 100644 --- a/server/core/BookConverter/index.js +++ b/server/core/BookConverter/index.js @@ -43,7 +43,7 @@ class BookConverter { else { //может это чистый текст? if (textUtils.checkIfText(data)) { - await fs.writeFile(outputFile, this.convertHtml(data)); + await fs.writeFile(outputFile, this.convertHtml(data, true)); return; } @@ -167,7 +167,7 @@ class BookConverter { titleInfo['book-title'] = title; //подозрение на чистый текст, надо разбить на параграфы - if ((isText || pars.length < buf.length/2000) && spaceCounter.length) { + if (isText || pars.length < buf.length/2000) { let total = 0; for (let i = 0; i < spaceCounter.length; i++) { total += (spaceCounter[i] ? spaceCounter[i] : 0); @@ -176,41 +176,37 @@ class BookConverter { let i = spaceCounter.length - 1; while (i > 0 && (!spaceCounter[i] || spaceCounter[i] < total)) i--; - const parIndent = i; - if (parIndent > 0) {//нашли отступ параграфа + const parIndent = (i > 0 ? i : 0); - let newPars = []; - const newPar = () => { - newPars.push({_n: 'p', _t: ''}); - }; + let newPars = []; + const newPar = () => { + newPars.push({_n: 'p', _t: ''}); + }; - const growPar = (text) => { - const l = newPars.length; - if (l) { - newPars[l - 1]._t += text; - } + const growPar = (text) => { + const l = newPars.length; + if (l) { + newPars[l - 1]._t += text; } - - for (const par of pars) { - newPar(); - - const lines = par._t.split('\n'); - for (const line of lines) { - const sp = line.split(' '); - let l = 0; - while (l < sp.length && sp[l].trim() == '') { - l++; - } - if (l >= parIndent) - newPar(); - growPar(line.trim() + ' '); - } - } - - body.section._a[0] = newPars; - } else { - body.section._a[0] = pars; } + + for (const par of pars) { + newPar(); + + const lines = par._t.split('\n'); + for (const line of lines) { + const sp = line.split(' '); + let l = 0; + while (l < sp.length && sp[l].trim() == '') { + l++; + } + if (l >= parIndent) + newPar(); + growPar(line.trim() + ' '); + } + } + + body.section._a[0] = newPars; } else { body.section._a[0] = pars; } diff --git a/server/core/BookConverter/textUtils.js b/server/core/BookConverter/textUtils.js index 316f0ec7..5713d1a7 100644 --- a/server/core/BookConverter/textUtils.js +++ b/server/core/BookConverter/textUtils.js @@ -70,13 +70,22 @@ function getEncoding(buf) { function checkIfText(buf) { let spaceCount = 0; + let crCount = 0; + let lfCount = 0; for (let i = 0; i < buf.length; i++) { if (buf[i] == 32) spaceCount++; + if (buf[i] == 13) + crCount++; + if (buf[i] == 10) + lfCount++; } - const freq = spaceCount/(buf.length + 1); - return (freq > 0.1); + const spaceFreq = spaceCount/(buf.length + 1); + const crFreq = crCount/(buf.length + 1); + const lfFreq = lfCount/(buf.length + 1); + + return (spaceFreq > 0.1 || crFreq > 0.03 || lfFreq > 0.03); } module.exports = {