Compare commits

...

9 Commits
0.1.2 ... 0.1.3

Author SHA1 Message Date
Book Pauk
a4c72481d1 Merge branch 'release/0.1.3' 2019-02-13 13:45:53 +07:00
Book Pauk
23ecb433fb Версия 0.1.3 2019-02-13 13:45:34 +07:00
Book Pauk
6b9ad4a947 К предыдущему 2019-02-13 13:44:34 +07:00
Book Pauk
9a44f53e5f Добавил распознавание кодировки fb2 и конвертирование в utf8 2019-02-13 13:39:53 +07:00
Book Pauk
bce31df7e6 Улучшение отображения автора и названия 2019-02-13 13:12:26 +07:00
Book Pauk
4bdd33b44f Мелкий рефакторинг 2019-02-13 13:01:41 +07:00
Book Pauk
7ab5d4e113 Добавляем в url протокол http, если не указан 2019-02-13 12:57:59 +07:00
Book Pauk
92c454b3e9 Мелкая поправка 2019-02-12 23:21:14 +07:00
Book Pauk
a7f588b724 Merge tag '0.1.2' into develop
0.1.2
2019-02-12 22:56:03 +07:00
5 changed files with 103 additions and 59 deletions

View File

@@ -141,17 +141,27 @@ class HistoryPage extends Vue {
}
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({
touchDateTime: book.touchTime,
touchDate: t[0],
touchTime: t[1],
desc: {
title: `"${fb2.bookTitle}"${perc}${textLen}`,
author: _.compact([
fb2.lastName,
fb2.firstName,
fb2.middleName
]).join(' '),
title: `${title}${perc}${textLen}`,
author,
},
url: book.url,
path: book.path,

View File

@@ -440,51 +440,55 @@ class Reader extends Vue {
buttonClick(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();
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) {
@@ -591,14 +595,19 @@ class Reader extends Vue {
}
loadBook(opts) {
if (!opts) {
if (!opts || !opts.url) {
this.mostRecentBook();
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);
if (!opts.force && lastBook && lastBook.url == opts.url && bookManager.hasBookParsed(lastBook)) {
if (!opts.force && lastBook && lastBook.url == url && bookManager.hasBookParsed(lastBook)) {
this.loaderActive = false;
return;
}
@@ -615,7 +624,7 @@ class Reader extends Vue {
progress.setState({state: 'parse'});
// есть ли среди недавних
const key = bookManager.keyFromUrl(opts.url);
const key = bookManager.keyFromUrl(url);
let wasOpened = await bookManager.getRecentBook({key});
wasOpened = (wasOpened ? wasOpened : {});
const bookPos = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos);
@@ -626,7 +635,7 @@ class Reader extends Vue {
if (!opts.force) {
// пытаемся загрузить и распарсить книгу в менеджере из локального кэша
const bookParsed = await bookManager.getBook({url: opts.url}, (prog) => {
const bookParsed = await bookManager.getBook({url}, (prog) => {
progress.setState({progress: prog});
});
@@ -662,7 +671,7 @@ class Reader extends Vue {
// не удалось, скачиваем книгу полностью с конвертацией
let loadCached = true;
if (!book) {
book = await readerApi.loadBook(opts.url, (state) => {
book = await readerApi.loadBook(url, (state) => {
progress.setState(state);
});
loadCached = false;

View File

@@ -1,6 +1,6 @@
{
"name": "Liberama",
"version": "0.1.2",
"version": "0.1.3",
"engines": {
"node": ">=10.0.0"
},

View File

@@ -22,8 +22,8 @@ class BookConverter {
callback(100);
if (fileType && (fileType.ext == 'html' || fileType.ext == 'xml')) {
if (data.toString().indexOf('<FictionBook') >= 0) {
await fs.writeFile(outputFile, data);
if (data.toString().indexOf('<FictionBook') >= 0) {
await fs.writeFile(outputFile, this.checkEncoding(data));
return;
}
@@ -69,6 +69,28 @@ class BookConverter {
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) {
let titleInfo = {};
let desc = {_n: 'description', 'title-info': titleInfo};

View File

@@ -62,7 +62,10 @@ function getEncoding(buf) {
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) {