Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4c72481d1 | ||
|
|
23ecb433fb | ||
|
|
6b9ad4a947 | ||
|
|
9a44f53e5f | ||
|
|
bce31df7e6 | ||
|
|
4bdd33b44f | ||
|
|
7ab5d4e113 | ||
|
|
92c454b3e9 | ||
|
|
a7f588b724 |
@@ -141,17 +141,27 @@ class HistoryPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fb2 = (book.fb2 ? book.fb2 : {});
|
const fb2 = (book.fb2 ? book.fb2 : {});
|
||||||
|
|
||||||
|
let title = fb2.bookTitle;
|
||||||
|
if (title)
|
||||||
|
title = `"${title}"`;
|
||||||
|
else
|
||||||
|
title = '';
|
||||||
|
|
||||||
|
let author = _.compact([
|
||||||
|
fb2.lastName,
|
||||||
|
fb2.firstName,
|
||||||
|
fb2.middleName
|
||||||
|
]).join(' ');
|
||||||
|
author = (author ? author : (fb2.bookTitle ? fb2.bookTitle : book.url));
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
touchDateTime: book.touchTime,
|
touchDateTime: book.touchTime,
|
||||||
touchDate: t[0],
|
touchDate: t[0],
|
||||||
touchTime: t[1],
|
touchTime: t[1],
|
||||||
desc: {
|
desc: {
|
||||||
title: `"${fb2.bookTitle}"${perc}${textLen}`,
|
title: `${title}${perc}${textLen}`,
|
||||||
author: _.compact([
|
author,
|
||||||
fb2.lastName,
|
|
||||||
fb2.firstName,
|
|
||||||
fb2.middleName
|
|
||||||
]).join(' '),
|
|
||||||
},
|
},
|
||||||
url: book.url,
|
url: book.url,
|
||||||
path: book.path,
|
path: book.path,
|
||||||
|
|||||||
@@ -440,51 +440,55 @@ class Reader extends Vue {
|
|||||||
|
|
||||||
buttonClick(button) {
|
buttonClick(button) {
|
||||||
const activeClass = this.buttonActiveClass(button);
|
const activeClass = this.buttonActiveClass(button);
|
||||||
if (!activeClass['tool-button-disabled'])
|
|
||||||
switch (button) {
|
|
||||||
case 'loader':
|
|
||||||
this.loaderToggle();
|
|
||||||
break;
|
|
||||||
case 'undoAction':
|
|
||||||
if (this.actionCur > 0) {
|
|
||||||
this.actionCur--;
|
|
||||||
this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'redoAction':
|
|
||||||
if (this.actionCur < this.actionList.length - 1) {
|
|
||||||
this.actionCur++;
|
|
||||||
this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'fullScreen':
|
|
||||||
this.fullScreenToggle();
|
|
||||||
break;
|
|
||||||
case 'setPosition':
|
|
||||||
this.setPositionToggle();
|
|
||||||
break;
|
|
||||||
case 'scrolling':
|
|
||||||
this.scrollingToggle();
|
|
||||||
break;
|
|
||||||
case 'search':
|
|
||||||
this.searchToggle();
|
|
||||||
break;
|
|
||||||
case 'copyText':
|
|
||||||
this.copyTextToggle();
|
|
||||||
break;
|
|
||||||
case 'history':
|
|
||||||
this.historyToggle();
|
|
||||||
break;
|
|
||||||
case 'refresh':
|
|
||||||
if (this.mostRecentBook()) {
|
|
||||||
this.loadBook({url: this.mostRecentBook().url, force: true});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'settings':
|
|
||||||
this.settingsToggle();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
this.$refs[button].$el.blur();
|
this.$refs[button].$el.blur();
|
||||||
|
|
||||||
|
if (activeClass['tool-button-disabled'])
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (button) {
|
||||||
|
case 'loader':
|
||||||
|
this.loaderToggle();
|
||||||
|
break;
|
||||||
|
case 'undoAction':
|
||||||
|
if (this.actionCur > 0) {
|
||||||
|
this.actionCur--;
|
||||||
|
this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'redoAction':
|
||||||
|
if (this.actionCur < this.actionList.length - 1) {
|
||||||
|
this.actionCur++;
|
||||||
|
this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'fullScreen':
|
||||||
|
this.fullScreenToggle();
|
||||||
|
break;
|
||||||
|
case 'setPosition':
|
||||||
|
this.setPositionToggle();
|
||||||
|
break;
|
||||||
|
case 'scrolling':
|
||||||
|
this.scrollingToggle();
|
||||||
|
break;
|
||||||
|
case 'search':
|
||||||
|
this.searchToggle();
|
||||||
|
break;
|
||||||
|
case 'copyText':
|
||||||
|
this.copyTextToggle();
|
||||||
|
break;
|
||||||
|
case 'history':
|
||||||
|
this.historyToggle();
|
||||||
|
break;
|
||||||
|
case 'refresh':
|
||||||
|
if (this.mostRecentBook()) {
|
||||||
|
this.loadBook({url: this.mostRecentBook().url, force: true});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'settings':
|
||||||
|
this.settingsToggle();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonActiveClass(button) {
|
buttonActiveClass(button) {
|
||||||
@@ -591,14 +595,19 @@ class Reader extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadBook(opts) {
|
loadBook(opts) {
|
||||||
if (!opts) {
|
if (!opts || !opts.url) {
|
||||||
this.mostRecentBook();
|
this.mostRecentBook();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let url = opts.url;
|
||||||
|
if ((url.indexOf('http://') != 0) && (url.indexOf('https://') != 0) &&
|
||||||
|
(url.indexOf('file://') != 0))
|
||||||
|
url = 'http://' + url;
|
||||||
|
|
||||||
// уже просматривается сейчас
|
// уже просматривается сейчас
|
||||||
const lastBook = (this.$refs.page ? this.$refs.page.lastBook : null);
|
const lastBook = (this.$refs.page ? this.$refs.page.lastBook : null);
|
||||||
if (!opts.force && lastBook && lastBook.url == opts.url && bookManager.hasBookParsed(lastBook)) {
|
if (!opts.force && lastBook && lastBook.url == url && bookManager.hasBookParsed(lastBook)) {
|
||||||
this.loaderActive = false;
|
this.loaderActive = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -615,7 +624,7 @@ class Reader extends Vue {
|
|||||||
progress.setState({state: 'parse'});
|
progress.setState({state: 'parse'});
|
||||||
|
|
||||||
// есть ли среди недавних
|
// есть ли среди недавних
|
||||||
const key = bookManager.keyFromUrl(opts.url);
|
const key = bookManager.keyFromUrl(url);
|
||||||
let wasOpened = await bookManager.getRecentBook({key});
|
let wasOpened = await bookManager.getRecentBook({key});
|
||||||
wasOpened = (wasOpened ? wasOpened : {});
|
wasOpened = (wasOpened ? wasOpened : {});
|
||||||
const bookPos = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos);
|
const bookPos = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos);
|
||||||
@@ -626,7 +635,7 @@ class Reader extends Vue {
|
|||||||
|
|
||||||
if (!opts.force) {
|
if (!opts.force) {
|
||||||
// пытаемся загрузить и распарсить книгу в менеджере из локального кэша
|
// пытаемся загрузить и распарсить книгу в менеджере из локального кэша
|
||||||
const bookParsed = await bookManager.getBook({url: opts.url}, (prog) => {
|
const bookParsed = await bookManager.getBook({url}, (prog) => {
|
||||||
progress.setState({progress: prog});
|
progress.setState({progress: prog});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -662,7 +671,7 @@ class Reader extends Vue {
|
|||||||
// не удалось, скачиваем книгу полностью с конвертацией
|
// не удалось, скачиваем книгу полностью с конвертацией
|
||||||
let loadCached = true;
|
let loadCached = true;
|
||||||
if (!book) {
|
if (!book) {
|
||||||
book = await readerApi.loadBook(opts.url, (state) => {
|
book = await readerApi.loadBook(url, (state) => {
|
||||||
progress.setState(state);
|
progress.setState(state);
|
||||||
});
|
});
|
||||||
loadCached = false;
|
loadCached = false;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.1.2",
|
"version": "0.1.3",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ class BookConverter {
|
|||||||
callback(100);
|
callback(100);
|
||||||
|
|
||||||
if (fileType && (fileType.ext == 'html' || fileType.ext == 'xml')) {
|
if (fileType && (fileType.ext == 'html' || fileType.ext == 'xml')) {
|
||||||
if (data.toString().indexOf('<FictionBook') >= 0) {
|
if (data.toString().indexOf('<FictionBook') >= 0) {
|
||||||
await fs.writeFile(outputFile, data);
|
await fs.writeFile(outputFile, this.checkEncoding(data));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +69,28 @@ class BookConverter {
|
|||||||
return iconv.decode(data, selected);
|
return iconv.decode(data, selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEncoding(data) {
|
||||||
|
let result = data;
|
||||||
|
|
||||||
|
const left = data.indexOf('<?xml version="1.0"');
|
||||||
|
if (left >= 0) {
|
||||||
|
const right = data.indexOf('?>', left);
|
||||||
|
if (right >= 0) {
|
||||||
|
const head = data.slice(left, right + 2).toString();
|
||||||
|
const m = head.match(/encoding="(.*)"/);
|
||||||
|
if (m) {
|
||||||
|
let encoding = m[1].toLowerCase();
|
||||||
|
if (encoding != 'utf-8') {
|
||||||
|
result = iconv.decode(data, encoding);
|
||||||
|
result = Buffer.from(result.toString().replace(m[0], 'encoding="utf-8"'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
convertHtml(data, isText) {
|
convertHtml(data, isText) {
|
||||||
let titleInfo = {};
|
let titleInfo = {};
|
||||||
let desc = {_n: 'description', 'title-info': titleInfo};
|
let desc = {_n: 'description', 'title-info': titleInfo};
|
||||||
|
|||||||
@@ -62,7 +62,10 @@ function getEncoding(buf) {
|
|||||||
|
|
||||||
sorted.sort((a, b) => b.c - a.c);
|
sorted.sort((a, b) => b.c - a.c);
|
||||||
|
|
||||||
return sorted[0].codePage;
|
if (sorted[0].c > 0)
|
||||||
|
return sorted[0].codePage;
|
||||||
|
else
|
||||||
|
return 'ISO-8859-5';
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkIfText(buf) {
|
function checkIfText(buf) {
|
||||||
|
|||||||
Reference in New Issue
Block a user