Compare commits

...

34 Commits
0.1.2 ... 0.1.7

Author SHA1 Message Date
Book Pauk
9d8507a1e4 Merge branch 'hotfix/0.1.7' 2019-02-14 21:52:41 +07:00
Book Pauk
50042aa36d Убрал редирект на последнюю открытую книгу, если не задан явно url 2019-02-14 21:51:22 +07:00
Book Pauk
b0709abfa2 Merge branch 'hotfix/0.1.6' 2019-02-14 19:00:02 +07:00
Book Pauk
dedb729dfe Увеличил верхние границы отступов, добавил возможность сброса настроек 2019-02-14 18:59:20 +07:00
Book Pauk
ae30c3865d Merge branch 'release/0.1.5' 2019-02-14 18:27:39 +07:00
Book Pauk
b3453af0fe Версия 0.1.5 2019-02-14 18:27:20 +07:00
Book Pauk
550dcbc081 Добавлена настройка addEmptyParagraphs 2019-02-14 18:25:18 +07:00
Book Pauk
5af1f81bc3 Добавил настройку cutEmptyParagraphs 2019-02-14 17:34:52 +07:00
Book Pauk
d306f972cc Добавил настройку clickControl 2019-02-14 17:10:14 +07:00
Book Pauk
0f6747f2db Увеличил граничные значения сверху 2019-02-14 16:33:47 +07:00
Book Pauk
559b96d56f Добавил реакцию на нажатие "R", мелкий рефакторинг 2019-02-13 18:30:48 +07:00
Book Pauk
69606429b8 Merge tag '0.1.4' into develop
0.1.4
2019-02-13 18:05:27 +07:00
Book Pauk
824fe68194 Merge branch 'release/0.1.4' 2019-02-13 18:05:16 +07:00
Book Pauk
b056feda59 Версия 0.1.4 2019-02-13 18:04:54 +07:00
Book Pauk
32635dedb0 Добавил сохранение нужных настроек 2019-02-13 18:02:08 +07:00
Book Pauk
835f9374f6 Добавил использование на клиенте настройки maxUploadFileSize 2019-02-13 17:58:44 +07:00
Book Pauk
edece5e17f Вынес ограничения размеров файлов и директорий в настройки 2019-02-13 17:54:41 +07:00
Book Pauk
298317d352 Подправил дефолтный конфиг 2019-02-13 17:45:22 +07:00
Book Pauk
c7637eb941 Добавил сохранение и загрузку конфига 2019-02-13 17:43:13 +07:00
Book Pauk
c8f9e0ac9d Добавил пакет minimist 2019-02-13 17:41:41 +07:00
Book Pauk
3e3f259920 Поправка бага 2019-02-13 16:41:30 +07:00
Book Pauk
c88baf3c2c Улучшение парсинга fb2 2019-02-13 14:56:54 +07:00
Book Pauk
0d27dabd62 Улучшение парсинга fb2 2019-02-13 14:49:51 +07:00
Book Pauk
5c29594b3d Добавил распознавание тега text-author 2019-02-13 14:14:34 +07:00
Book Pauk
1e71d0ae2f Merge tag '0.1.3' into develop
0.1.3
2019-02-13 13:46:07 +07:00
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
20 changed files with 339 additions and 156 deletions

View File

@@ -6,7 +6,7 @@ const api = axios.create({
class Misc {
async loadConfig() {
const response = await api.post('/config', {params: ['name', 'version', 'mode']});
const response = await api.post('/config', {params: ['name', 'version', 'mode', 'maxUploadFileSize']});
return response.data;
}
}

View File

@@ -1,7 +1,6 @@
import axios from 'axios';
import {sleep} from '../share/utils';
const maxFileUploadSize = 50*1024*1024;
const api = axios.create({
baseURL: '/api/reader'
});
@@ -75,9 +74,11 @@ class Reader {
return await axios.get(url, options);
}
async uploadFile(file, callback) {
if (file.size > maxFileUploadSize)
throw new Error(`Размер файла превышает ${maxFileUploadSize} байт`);
async uploadFile(file, maxUploadFileSize, callback) {
if (!maxUploadFileSize)
maxUploadFileSize = 10*1024*1024;
if (file.size > maxUploadFileSize)
throw new Error(`Размер файла превышает ${maxUploadFileSize} байт`);
let formData = new FormData();
formData.append('file', file);

View File

@@ -9,6 +9,7 @@
<li><b>ПКМ</b> - показать/скрыть панель управления</li>
<li><b>СКМ</b> - вкл./выкл. плавный скроллинг текста</li>
</ul>
* Для управления с помощью мыши/тачпада необходимо установить галочку "Включить управление кликом" в настройках
</div>
</template>

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

@@ -139,6 +139,12 @@ export default @Component({
this.showClickMapPage = newValue.showClickMapPage;
this.updateRoute();
},
loaderActive: function(newValue) {
const recent = this.mostRecentBook();
if (!newValue && !this.loading && recent && !bookManager.hasBookParsed(recent)) {
this.loadBook(recent);
}
},
},
})
class Reader extends Vue {
@@ -168,6 +174,7 @@ class Reader extends Vue {
this.commit = this.$store.commit;
this.dispatch = this.$store.dispatch;
this.reader = this.$store.state.reader;
this.config = this.$store.state.config;
this.$root.addKeyHook(this.keyHook);
@@ -179,7 +186,7 @@ class Reader extends Vue {
this.debouncedSetRecentBook = _.debounce(async(newValue) => {
const recent = this.mostRecentBook();
if (recent && recent.bookPos != newValue) {
if (recent && (recent.bookPos != newValue || recent.bookPosSeen !== this.bookPosSeen)) {
await bookManager.setRecentBook(Object.assign({}, recent, {bookPos: newValue, bookPosSeen: this.bookPosSeen}));
if (this.actionCur < 0 || (this.actionCur >= 0 && this.actionList[this.actionCur] != newValue))
@@ -198,14 +205,12 @@ class Reader extends Vue {
mounted() {
(async() => {
await bookManager.init();
await bookManager.init(this.settings);
await restoreOldSettings(this.settings, bookManager, this.commit);
if (this.$root.rootRoute == '/reader') {
if (this.routeParamUrl) {
this.loadBook({url: this.routeParamUrl, bookPos: this.routeParamPos});
} else if (this.mostRecentBook()) {
this.loadBook({url: this.mostRecentBook().url});
} else {
this.loaderActive = true;
}
@@ -438,53 +443,61 @@ class Reader extends Vue {
}
}
refreshBook() {
if (this.mostRecentBook()) {
this.loadBook({url: this.mostRecentBook().url, force: true});
}
}
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':
this.refreshBook();
break;
case 'settings':
this.settingsToggle();
break;
}
}
buttonActiveClass(button) {
@@ -591,14 +604,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 +633,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 +644,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 +680,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;
@@ -704,7 +722,7 @@ class Reader extends Vue {
progress.show();
progress.setState({state: 'upload'});
const url = await readerApi.uploadFile(opts.file, (state) => {
const url = await readerApi.uploadFile(opts.file, this.config.maxUploadFileSize, (state) => {
progress.setState(state);
});
@@ -780,6 +798,9 @@ class Reader extends Vue {
event.preventDefault();
event.stopPropagation();
break;
case 'KeyZ':
this.scrollingToggle();
break;
case 'KeyP':
this.setPositionToggle();
break;
@@ -797,8 +818,8 @@ class Reader extends Vue {
event.stopPropagation();
}
break;
case 'KeyZ':
this.scrollingToggle();
case 'KeyR':
this.refreshBook();
break;
case 'KeyX':
this.historyToggle();

View File

@@ -81,7 +81,7 @@
</el-form-item>
<el-form-item label="Размер">
<el-col :span="17">
<el-input-number v-model="fontSize" :min="5" :max="100"></el-input-number>
<el-input-number v-model="fontSize" :min="5" :max="200"></el-input-number>
</el-col>
<el-col :span="1">
<a href="https://fonts.google.com/?subset=cyrillic" target="_blank">Примеры</a>
@@ -112,10 +112,10 @@
<div class="partHeader">Текст</div>
<el-form-item label="Интервал">
<el-input-number v-model="lineInterval" :min="0" :max="100"></el-input-number>
<el-input-number v-model="lineInterval" :min="0" :max="200"></el-input-number>
</el-form-item>
<el-form-item label="Параграф">
<el-input-number v-model="p" :min="0" :max="200"></el-input-number>
<el-input-number v-model="p" :min="0" :max="2000"></el-input-number>
</el-form-item>
<el-form-item label="Отступ">
<el-col :span="11">
@@ -123,7 +123,7 @@
<template slot="content">
Слева/справа
</template>
<el-input-number v-model="indentLR" :min="0" :max="200"></el-input-number>
<el-input-number v-model="indentLR" :min="0" :max="2000"></el-input-number>
</el-tooltip>
</el-col>
<el-col :span="1">
@@ -134,7 +134,7 @@
<template slot="content">
Сверху/снизу
</template>
<el-input-number v-model="indentTB" :min="0" :max="200"></el-input-number>
<el-input-number v-model="indentTB" :min="0" :max="2000"></el-input-number>
</el-tooltip>
</el-col>
</el-form-item>
@@ -184,6 +184,16 @@
<el-checkbox v-model="textAlignJustify">По ширине</el-checkbox>
<el-checkbox v-model="wordWrap">Перенос по слогам</el-checkbox>
</el-form-item>
<el-form-item label="Обработка">
<el-checkbox v-model="cutEmptyParagraphs" @change="needReload">Убирать пустые параграфы</el-checkbox>
</el-form-item>
<el-form-item label="">
<el-col :span="12">
Добавлять пустые
</el-col>
<el-input-number v-model="addEmptyParagraphs" :min="0" :max="2" @change="needReload"></el-input-number>
</el-form-item>
</el-form>
<el-form :model="form" size="mini" label-width="120px" @submit.native.prevent>
@@ -194,7 +204,7 @@
<el-checkbox v-model="statusBarTop" :disabled="!showStatusBar">Вверху/внизу</el-checkbox>
</el-form-item>
<el-form-item label="Высота">
<el-input-number v-model="statusBarHeight" :min="5" :max="50" :disabled="!showStatusBar"></el-input-number>
<el-input-number v-model="statusBarHeight" :min="5" :max="100" :disabled="!showStatusBar"></el-input-number>
</el-form-item>
<el-form-item label="Прозрачность">
<el-input-number v-model="statusBarColorAlpha" :min="0" :max="1" :precision="2" :step="0.1" :disabled="!showStatusBar"></el-input-number>
@@ -234,6 +244,9 @@
<!--------------------------------------------------------------------------->
<el-tab-pane label="Прочее">
<el-form :model="form" size="mini" label-width="120px" @submit.native.prevent>
<el-form-item label="Управление">
<el-checkbox v-model="clickControl">Включить управление кликом</el-checkbox>
</el-form-item>
<el-form-item label="Подсказка">
<el-tooltip :open-delay="500" effect="light">
<template slot="content">
@@ -241,7 +254,7 @@
</template>
<el-checkbox v-model="showClickMapPage">Показывать области управления кликом</el-checkbox>
</el-tooltip>
</el-form-item>
</el-form-item>
<el-form-item label="URL">
<el-tooltip :open-delay="500" effect="light">
<template slot="content">
@@ -274,9 +287,11 @@
<el-checkbox v-model="copyFullText">Загружать весь текст</el-checkbox>
</el-tooltip>
</el-form-item>
</el-form>
</el-tab-pane>
<!--------------------------------------------------------------------------->
<el-tab-pane label="Сброс">
<el-button @click="setDefaults">Установить по-умолчанию</el-button>
</el-tab-pane>
</el-tabs>
@@ -384,10 +399,31 @@ class SettingsPage extends Vue {
];
}
needReload() {
this.$notify.warning({message: 'Необходимо обновить страницу (F5), чтобы изменения возымели эффект'});
}
close() {
this.$emit('settings-toggle');
}
async setDefaults() {
try {
if (await this.$confirm('Подтвердите установку настроек по-умолчанию', '', {
confirmButtonText: 'OK',
cancelButtonText: 'Отмена',
type: 'warning'
})) {
this.form = Object.assign({}, rstore.settingDefaults);
for (let prop in rstore.settingDefaults) {
this[prop] = this.form[prop];
}
}
} catch (e) {
//
}
}
keyHook(event) {
if (event.type == 'keydown' && event.code == 'Escape') {
this.close();

View File

@@ -4,18 +4,18 @@
<div v-html="background"></div>
<!-- img -->
</div>
<div ref="scrollBox1" class="layout" style="overflow: hidden">
<div ref="scrollBox1" class="layout" style="overflow: hidden" @wheel.prevent.stop="onMouseWheel">
<div ref="scrollingPage" class="layout" @transitionend="onScrollingTransitionEnd">
<div v-html="page1"></div>
</div>
</div>
<div ref="scrollBox2" class="layout" style="overflow: hidden">
<div ref="scrollBox2" class="layout" style="overflow: hidden" @wheel.prevent.stop="onMouseWheel">
<div v-html="page2"></div>
</div>
<div v-show="showStatusBar" ref="statusBar" class="layout">
<div v-html="statusBar"></div>
</div>
<div ref="layoutEvents" class="layout events" @mousedown.prevent.stop="onMouseDown" @mouseup.prevent.stop="onMouseUp"
<div v-show="clickControl" ref="layoutEvents" class="layout events" @mousedown.prevent.stop="onMouseDown" @mouseup.prevent.stop="onMouseUp"
@wheel.prevent.stop="onMouseWheel"
@touchstart.stop="onTouchStart" @touchend.stop="onTouchEnd" @touchcancel.prevent.stop="onTouchCancel"
oncontextmenu="return false;">
@@ -23,6 +23,8 @@
@click.prevent.stop="onStatusBarClick"></div>
<div v-show="fontsLoading" ref="fontsLoading"></div>
</div>
<div v-show="!clickControl && showStatusBar" class="layout" v-html="statusBarClickable" @mousedown.prevent.stop @touchstart.stop
@click.prevent.stop="onStatusBarClick"></div>
<!-- невидимым делать нельзя, вовремя не подгружаютя шрифты -->
<canvas ref="offscreenCanvas" class="layout" style="width: 0px; height: 0px"></canvas>
</div>
@@ -45,10 +47,13 @@ const minLayoutWidth = 100;
export default @Component({
watch: {
bookPos: function(newValue) {
this.$emit('book-pos-changed', {bookPos: newValue, bookPosSeen: this.bookPosSeen});
bookPos: function() {
this.$emit('book-pos-changed', {bookPos: this.bookPos, bookPosSeen: this.bookPosSeen});
this.draw();
},
bookPosSeen: function() {
this.$emit('book-pos-changed', {bookPos: this.bookPos, bookPosSeen: this.bookPosSeen});
},
settings: function() {
this.debouncedLoadSettings();
},
@@ -60,6 +65,8 @@ export default @Component({
class TextPage extends Vue {
toggleLayout = false;
showStatusBar = false;
clickControl = true;
background = null;
page1 = null;
page2 = null;
@@ -69,6 +76,7 @@ class TextPage extends Vue {
lastBook = null;
bookPos = 0;
bookPosSeen = null;
fontStyle = null;
fontSize = null;

View File

@@ -3,7 +3,7 @@ import sax from '../../../../server/core/BookConverter/sax';
import {sleep} from '../../../share/utils';
export default class BookParser {
constructor() {
constructor(settings) {
// defaults
this.p = 30;// px, отступ параграфа
this.w = 300;// px, ширина страницы
@@ -13,6 +13,12 @@ export default class BookParser {
this.measureText = (text, style) => {// eslint-disable-line no-unused-vars
return text.length*20;
};
//настройки
if (settings) {
this.cutEmptyParagraphs = settings.cutEmptyParagraphs;
this.addEmptyParagraphs = settings.addEmptyParagraphs;
}
}
async parse(data, callback) {
@@ -48,7 +54,14 @@ export default class BookParser {
text: String //текст параграфа (или title или epigraph и т.д) с вложенными тегами
}
*/
const newParagraph = (text, len) => {
const newParagraph = (text, len, noCut) => {
//схлопывание пустых параграфов
if (!noCut && this.cutEmptyParagraphs && paraIndex >= 0 && len == 1 && text[0] == ' ') {
let p = para[paraIndex];
if (p.length == 1 && p.text[0] == ' ')
return;
}
paraIndex++;
let p = {
index: paraIndex,
@@ -63,12 +76,23 @@ export default class BookParser {
const growParagraph = (text, len) => {
if (paraIndex < 0) {
newParagraph(text, len);
newParagraph(' ', 1);
growParagraph(text, len);
return;
}
let p = para[paraIndex];
if (p) {
//добавление пустых параграфов
if (this.addEmptyParagraphs && p.length == 1 && p.text[0] == ' ' && len > 0) {
let i = this.addEmptyParagraphs;
while (i > 0) {
newParagraph(' ', 1, true);
i--;
}
p = para[paraIndex];
}
paraOffset -= p.length;
if (p.length == 1 && p.text[0] == ' ' && len > 0) {
p.length = 0;
@@ -96,55 +120,63 @@ export default class BookParser {
tag = elemName;
path += '/' + elemName;
if ((tag == 'p' || tag == 'empty-line' || tag == 'v') && path.indexOf('/fictionbook/body/section') == 0) {
newParagraph(' ', 1);
}
if (path.indexOf('/fictionbook/body') == 0) {
if (tag == 'title') {
newParagraph(' ', 1);
bold = true;
center = true;
}
if (tag == 'emphasis' || tag == 'strong') {
growParagraph(`<${tag}>`, 0);
}
if (tag == 'emphasis' || tag == 'strong') {
growParagraph(`<${tag}>`, 0);
}
if (tag == 'title') {
newParagraph(' ', 1);
bold = true;
center = true;
}
if ((tag == 'p' || tag == 'empty-line' || tag == 'v')) {
newParagraph(' ', 1);
}
if (tag == 'subtitle') {
newParagraph(' ', 1);
bold = true;
}
if (tag == 'subtitle') {
newParagraph(' ', 1);
bold = true;
}
if (tag == 'epigraph') {
italic = true;
}
if (tag == 'epigraph') {
italic = true;
}
if (tag == 'stanza') {
newParagraph(' ', 1);
if (tag == 'poem') {
newParagraph(' ', 1);
}
if (tag == 'text-author') {
newParagraph(' <s> <s> <s> ', 4);
}
}
};
const onEndNode = (elemName) => {// eslint-disable-line no-unused-vars
if (tag == elemName) {
if (tag == 'emphasis' || tag == 'strong') {
growParagraph(`</${tag}>`, 0);
}
if (path.indexOf('/fictionbook/body') == 0) {
if (tag == 'title') {
bold = false;
center = false;
}
if (tag == 'title') {
bold = false;
center = false;
}
if (tag == 'emphasis' || tag == 'strong') {
growParagraph(`</${tag}>`, 0);
}
if (tag == 'subtitle') {
bold = false;
}
if (tag == 'subtitle') {
bold = false;
}
if (tag == 'epigraph') {
italic = false;
}
if (tag == 'epigraph') {
italic = false;
}
if (tag == 'stanza') {
newParagraph(' ', 1);
if (tag == 'stanza') {
newParagraph(' ', 1);
}
}
path = path.substr(0, path.length - tag.length - 1);
@@ -206,12 +238,12 @@ export default class BookParser {
let tOpen = (center ? '<center>' : '');
tOpen += (bold ? '<strong>' : '');
tOpen += (italic ? '<emphasis>' : '');
let tClose = (center ? '</center>' : '');
let tClose = (italic ? '</emphasis>' : '');
tClose += (bold ? '</strong>' : '');
tClose += (italic ? '</emphasis>' : '');
tClose += (center ? '</center>' : '');
if (path.indexOf('/fictionbook/body/title') == 0) {
newParagraph(`${tOpen}${text}${tClose}`, text.length, true);
growParagraph(`${tOpen}${text}${tClose}`, text.length, true);
}
if (path.indexOf('/fictionbook/body/section') == 0) {

View File

@@ -18,7 +18,8 @@ const bmRecentStore = localForage.createInstance({
});
class BookManager {
async init() {
async init(settings) {
this.settings = settings;
this.books = {};
this.recent = {};
this.recentChanged = true;
@@ -130,7 +131,7 @@ class BookManager {
async parseBook(meta, data, callback) {
if (!this.books)
await this.init();
const parsed = new BookParser();
const parsed = new BookParser(this.settings);
const parsedMeta = await parsed.parse(data, callback);
const result = Object.assign({}, meta, parsedMeta, {

View File

@@ -159,6 +159,10 @@ const settingDefaults = {
lazyParseEnabled: false,
copyFullText: false,
showClickMapPage: true,
clickControl: true,
cutEmptyParagraphs: false,
addEmptyParagraphs: 0,
fontShifts: {},
};

15
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "Liberama",
"version": "0.1.0",
"version": "0.1.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -6501,9 +6501,9 @@
}
},
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
},
"minipass": {
"version": "2.3.5",
@@ -6567,6 +6567,13 @@
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"requires": {
"minimist": "0.0.8"
},
"dependencies": {
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
}
}
},
"move-concurrently": {

View File

@@ -1,6 +1,6 @@
{
"name": "Liberama",
"version": "0.1.2",
"version": "0.1.7",
"engines": {
"node": ">=10.0.0"
},
@@ -70,6 +70,7 @@
"iconv-lite": "^0.4.24",
"localforage": "^1.7.3",
"lodash": "^4.17.11",
"minimist": "^1.2.0",
"multer": "^1.4.1",
"path-browserify": "^1.0.0",
"sql-template-strings": "^2.2.2",

View File

@@ -17,6 +17,10 @@ module.exports = {
dbFileName: 'db.sqlite',
loggingEnabled: true,
maxUploadFileSize: 50*1024*1024,//50Мб
maxTempPublicDirSize: 512*1024*1024,//512Мб
maxUploadPublicDirSize: 200*1024*1024,//100Мб
servers: [
{
serverName: '1',
@@ -24,12 +28,6 @@ module.exports = {
ip: '0.0.0.0',
port: '33080',
},
{
serverName: '2',
mode: 'omnireader',
ip: '0.0.0.0',
port: '33081',
},
],
};

View File

@@ -0,0 +1,36 @@
const fs = require('fs-extra');
const _ = require('lodash');
const propsToSave = [
'maxUploadFileSize',
'maxTempPublicDirSize',
'maxUploadPublicDirSize',
'servers',
];
async function load(config, configFilename) {
if (!configFilename) {
configFilename = `${config.dataDir}/config.json`;
if (!await fs.pathExists(configFilename)) {
save(config);
return;
}
}
const data = await fs.readFile(configFilename, 'utf8');
Object.assign(config, JSON.parse(data));
}
async function save(config) {
const configFilename = `${config.dataDir}/config.json`;
const dataToSave = _.pick(config, propsToSave);
await fs.writeFile(configFilename, JSON.stringify(dataToSave, null, 4));
}
module.exports = {
load,
save
};

View File

@@ -19,12 +19,6 @@ module.exports = Object.assign({}, base, {
ip: '0.0.0.0',
port: '44080',
},
{
serverName: '2',
mode: 'omnireader',
ip: '0.0.0.0',
port: '44081',
},
],
}

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) {

View File

@@ -8,8 +8,6 @@ const FileDecompressor = require('./FileDecompressor');
const BookConverter = require('./BookConverter');
const utils = require('./utils');
const maxTempPublicDirSize = 512*1024*1024;//512Мб
const maxUploadDirSize = 200*1024*1024;//100Мб
let singleCleanExecute = false;
class ReaderWorker {
@@ -27,8 +25,8 @@ class ReaderWorker {
this.bookConverter = new BookConverter();
if (!singleCleanExecute) {
this.periodicCleanDir(this.config.tempPublicDir, maxTempPublicDirSize, 60*60*1000);//1 раз в час
this.periodicCleanDir(this.config.uploadDir, maxUploadDirSize, 60*60*1000);//1 раз в час
this.periodicCleanDir(this.config.tempPublicDir, this.config.maxTempPublicDirSize, 60*60*1000);//1 раз в час
this.periodicCleanDir(this.config.uploadDir, this.config.maxUploadPublicDirSize, 60*60*1000);//1 раз в час
singleCleanExecute = true;
}
}

View File

@@ -1,9 +1,11 @@
const config = require('./config');
const {initLogger, getLog} = require('./core/getLogger');
initLogger(config);
const log = getLog();
const configSaver = require('./config/configSaver');
const argv = require('minimist')(process.argv.slice(2));
const fs = require('fs-extra');
const path = require('path');
const express = require('express');
@@ -23,15 +25,17 @@ async function init() {
await fs.remove(appDir);
await fs.move(appNewDir, appDir);
}
//загружаем конфиг из файла
await configSaver.load(config, argv.config);
}
async function main() {
const connPool = new SqliteConnectionPool(20, config);
log('Initializing');
await init();
log('Opening database');
const connPool = new SqliteConnectionPool(20, config);
await connPool.init();
//servers
@@ -42,7 +46,7 @@ async function main() {
let devModule = undefined;
if (serverConfig.branch == 'development') {
const devFileName = './dev.js'; //ignored by pkg -50Mb executable size
const devFileName = './dev.js'; //require ignored by pkg -50Mb executable size
devModule = require(devFileName);
devModule.webpackDevMiddleware(app);
}
@@ -80,4 +84,12 @@ async function main() {
}
}
main();
(async() => {
try {
await main();
} catch (e) {
console.error(e.message);
process.exit(1);
}
})();

View File

@@ -2,8 +2,6 @@ const c = require('./controllers');
const utils = require('./core/utils');
const multer = require('multer');
const maxUploadSize = 50*1024*1024;
function initRoutes(app, connPool, config) {
const misc = new c.MiscController(connPool, config);
const reader = new c.ReaderController(connPool, config);
@@ -22,7 +20,7 @@ function initRoutes(app, connPool, config) {
cb(null, utils.randomHexString(30));
}
});
const upload = multer({ storage, limits: {fileSize: maxUploadSize} });
const upload = multer({ storage, limits: {fileSize: config.maxUploadFileSize} });
//routes
const routes = [