Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae30c3865d | ||
|
|
b3453af0fe | ||
|
|
550dcbc081 | ||
|
|
5af1f81bc3 | ||
|
|
d306f972cc | ||
|
|
0f6747f2db | ||
|
|
559b96d56f | ||
|
|
69606429b8 | ||
|
|
824fe68194 | ||
|
|
b056feda59 | ||
|
|
32635dedb0 | ||
|
|
835f9374f6 | ||
|
|
edece5e17f | ||
|
|
298317d352 | ||
|
|
c7637eb941 | ||
|
|
c8f9e0ac9d | ||
|
|
3e3f259920 | ||
|
|
c88baf3c2c | ||
|
|
0d27dabd62 | ||
|
|
5c29594b3d | ||
|
|
1e71d0ae2f | ||
|
|
a4c72481d1 | ||
|
|
23ecb433fb | ||
|
|
6b9ad4a947 | ||
|
|
9a44f53e5f | ||
|
|
bce31df7e6 | ||
|
|
4bdd33b44f | ||
|
|
7ab5d4e113 | ||
|
|
92c454b3e9 | ||
|
|
a7f588b724 | ||
|
|
2ca7d2b7fc | ||
|
|
fe60956362 | ||
|
|
9c20df510d | ||
|
|
7dab3bfb1e | ||
|
|
b281f19344 | ||
|
|
d25cc64152 | ||
|
|
a1b0ffe2c9 | ||
|
|
17dcd9458e | ||
|
|
e2d645d414 | ||
|
|
d4b7f44987 |
@@ -6,7 +6,7 @@ const api = axios.create({
|
|||||||
|
|
||||||
class Misc {
|
class Misc {
|
||||||
async loadConfig() {
|
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;
|
return response.data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import {sleep} from '../share/utils';
|
import {sleep} from '../share/utils';
|
||||||
|
|
||||||
const maxFileUploadSize = 50*1024*1024;
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
baseURL: '/api/reader'
|
baseURL: '/api/reader'
|
||||||
});
|
});
|
||||||
@@ -75,9 +74,11 @@ class Reader {
|
|||||||
return await axios.get(url, options);
|
return await axios.get(url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async uploadFile(file, callback) {
|
async uploadFile(file, maxUploadFileSize, callback) {
|
||||||
if (file.size > maxFileUploadSize)
|
if (!maxUploadFileSize)
|
||||||
throw new Error(`Размер файла превышает ${maxFileUploadSize} байт`);
|
maxUploadFileSize = 10*1024*1024;
|
||||||
|
if (file.size > maxUploadFileSize)
|
||||||
|
throw new Error(`Размер файла превышает ${maxUploadFileSize} байт`);
|
||||||
|
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
|
|||||||
3
client/assets/robots.txt
Normal file
3
client/assets/robots.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
User-agent: *
|
||||||
|
Disallow: /?*url=
|
||||||
|
Disallow: /#/
|
||||||
@@ -208,6 +208,22 @@ class App extends Vue {
|
|||||||
this.$router.replace('/reader');
|
this.$router.replace('/reader');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//yandex-метрика для omnireader
|
||||||
|
if (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
|
||||||
|
|
||||||
|
ym(52347334, "init", {// eslint-disable-line no-undef
|
||||||
|
id:52347334,
|
||||||
|
clickmap:true,
|
||||||
|
trackLinks:true,
|
||||||
|
accurateTrackBounce:true
|
||||||
|
});
|
||||||
|
|
||||||
|
this.yaMetricsDone = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<li><b>ПКМ</b> - показать/скрыть панель управления</li>
|
<li><b>ПКМ</b> - показать/скрыть панель управления</li>
|
||||||
<li><b>СКМ</b> - вкл./выкл. плавный скроллинг текста</li>
|
<li><b>СКМ</b> - вкл./выкл. плавный скроллинг текста</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
* Для управления с помощью мыши/тачпада необходимо установить галочку "Включить управление кликом" в настройках
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ class LoaderPage extends Vue {
|
|||||||
|
|
||||||
loadFile() {
|
loadFile() {
|
||||||
const file = this.$refs.file.files[0];
|
const file = this.$refs.file.files[0];
|
||||||
|
this.$refs.file.value = '';
|
||||||
if (file)
|
if (file)
|
||||||
this.$emit('load-file', {file});
|
this.$emit('load-file', {file});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ class Reader extends Vue {
|
|||||||
this.commit = this.$store.commit;
|
this.commit = this.$store.commit;
|
||||||
this.dispatch = this.$store.dispatch;
|
this.dispatch = this.$store.dispatch;
|
||||||
this.reader = this.$store.state.reader;
|
this.reader = this.$store.state.reader;
|
||||||
|
this.config = this.$store.state.config;
|
||||||
|
|
||||||
this.$root.addKeyHook(this.keyHook);
|
this.$root.addKeyHook(this.keyHook);
|
||||||
|
|
||||||
@@ -179,7 +180,7 @@ class Reader extends Vue {
|
|||||||
|
|
||||||
this.debouncedSetRecentBook = _.debounce(async(newValue) => {
|
this.debouncedSetRecentBook = _.debounce(async(newValue) => {
|
||||||
const recent = this.mostRecentBook();
|
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}));
|
await bookManager.setRecentBook(Object.assign({}, recent, {bookPos: newValue, bookPosSeen: this.bookPosSeen}));
|
||||||
|
|
||||||
if (this.actionCur < 0 || (this.actionCur >= 0 && this.actionList[this.actionCur] != newValue))
|
if (this.actionCur < 0 || (this.actionCur >= 0 && this.actionList[this.actionCur] != newValue))
|
||||||
@@ -198,7 +199,7 @@ class Reader extends Vue {
|
|||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
(async() => {
|
(async() => {
|
||||||
await bookManager.init();
|
await bookManager.init(this.settings);
|
||||||
await restoreOldSettings(this.settings, bookManager, this.commit);
|
await restoreOldSettings(this.settings, bookManager, this.commit);
|
||||||
|
|
||||||
if (this.$root.rootRoute == '/reader') {
|
if (this.$root.rootRoute == '/reader') {
|
||||||
@@ -438,53 +439,61 @@ class Reader extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshBook() {
|
||||||
|
if (this.mostRecentBook()) {
|
||||||
|
this.loadBook({url: this.mostRecentBook().url, force: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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':
|
||||||
|
this.refreshBook();
|
||||||
|
break;
|
||||||
|
case 'settings':
|
||||||
|
this.settingsToggle();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonActiveClass(button) {
|
buttonActiveClass(button) {
|
||||||
@@ -591,14 +600,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 +629,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 +640,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 +676,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;
|
||||||
@@ -704,7 +718,7 @@ class Reader extends Vue {
|
|||||||
progress.show();
|
progress.show();
|
||||||
progress.setState({state: 'upload'});
|
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);
|
progress.setState(state);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -780,6 +794,9 @@ class Reader extends Vue {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
|
case 'KeyZ':
|
||||||
|
this.scrollingToggle();
|
||||||
|
break;
|
||||||
case 'KeyP':
|
case 'KeyP':
|
||||||
this.setPositionToggle();
|
this.setPositionToggle();
|
||||||
break;
|
break;
|
||||||
@@ -797,8 +814,8 @@ class Reader extends Vue {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'KeyZ':
|
case 'KeyR':
|
||||||
this.scrollingToggle();
|
this.refreshBook();
|
||||||
break;
|
break;
|
||||||
case 'KeyX':
|
case 'KeyX':
|
||||||
this.historyToggle();
|
this.historyToggle();
|
||||||
|
|||||||
@@ -81,7 +81,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Размер">
|
<el-form-item label="Размер">
|
||||||
<el-col :span="17">
|
<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>
|
||||||
<el-col :span="1">
|
<el-col :span="1">
|
||||||
<a href="https://fonts.google.com/?subset=cyrillic" target="_blank">Примеры</a>
|
<a href="https://fonts.google.com/?subset=cyrillic" target="_blank">Примеры</a>
|
||||||
@@ -112,10 +112,10 @@
|
|||||||
<div class="partHeader">Текст</div>
|
<div class="partHeader">Текст</div>
|
||||||
|
|
||||||
<el-form-item label="Интервал">
|
<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>
|
||||||
<el-form-item label="Параграф">
|
<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="1000"></el-input-number>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Отступ">
|
<el-form-item label="Отступ">
|
||||||
<el-col :span="11">
|
<el-col :span="11">
|
||||||
@@ -123,7 +123,7 @@
|
|||||||
<template slot="content">
|
<template slot="content">
|
||||||
Слева/справа
|
Слева/справа
|
||||||
</template>
|
</template>
|
||||||
<el-input-number v-model="indentLR" :min="0" :max="200"></el-input-number>
|
<el-input-number v-model="indentLR" :min="0" :max="500"></el-input-number>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="1">
|
<el-col :span="1">
|
||||||
@@ -134,7 +134,7 @@
|
|||||||
<template slot="content">
|
<template slot="content">
|
||||||
Сверху/снизу
|
Сверху/снизу
|
||||||
</template>
|
</template>
|
||||||
<el-input-number v-model="indentTB" :min="0" :max="200"></el-input-number>
|
<el-input-number v-model="indentTB" :min="0" :max="500"></el-input-number>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@@ -184,6 +184,16 @@
|
|||||||
<el-checkbox v-model="textAlignJustify">По ширине</el-checkbox>
|
<el-checkbox v-model="textAlignJustify">По ширине</el-checkbox>
|
||||||
<el-checkbox v-model="wordWrap">Перенос по слогам</el-checkbox>
|
<el-checkbox v-model="wordWrap">Перенос по слогам</el-checkbox>
|
||||||
</el-form-item>
|
</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>
|
||||||
|
|
||||||
<el-form :model="form" size="mini" label-width="120px" @submit.native.prevent>
|
<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-checkbox v-model="statusBarTop" :disabled="!showStatusBar">Вверху/внизу</el-checkbox>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Высота">
|
<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>
|
||||||
<el-form-item label="Прозрачность">
|
<el-form-item label="Прозрачность">
|
||||||
<el-input-number v-model="statusBarColorAlpha" :min="0" :max="1" :precision="2" :step="0.1" :disabled="!showStatusBar"></el-input-number>
|
<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-tab-pane label="Прочее">
|
||||||
<el-form :model="form" size="mini" label-width="120px" @submit.native.prevent>
|
<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-form-item label="Подсказка">
|
||||||
<el-tooltip :open-delay="500" effect="light">
|
<el-tooltip :open-delay="500" effect="light">
|
||||||
<template slot="content">
|
<template slot="content">
|
||||||
@@ -241,7 +254,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<el-checkbox v-model="showClickMapPage">Показывать области управления кликом</el-checkbox>
|
<el-checkbox v-model="showClickMapPage">Показывать области управления кликом</el-checkbox>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="URL">
|
<el-form-item label="URL">
|
||||||
<el-tooltip :open-delay="500" effect="light">
|
<el-tooltip :open-delay="500" effect="light">
|
||||||
<template slot="content">
|
<template slot="content">
|
||||||
@@ -384,6 +397,10 @@ class SettingsPage extends Vue {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
needReload() {
|
||||||
|
this.$notify.warning({message: 'Необходимо обновить страницу (F5), чтобы изменения возымели эффект'});
|
||||||
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this.$emit('settings-toggle');
|
this.$emit('settings-toggle');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,18 @@
|
|||||||
<div v-html="background"></div>
|
<div v-html="background"></div>
|
||||||
<!-- img -->
|
<!-- img -->
|
||||||
</div>
|
</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 ref="scrollingPage" class="layout" @transitionend="onScrollingTransitionEnd">
|
||||||
<div v-html="page1"></div>
|
<div v-html="page1"></div>
|
||||||
</div>
|
</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 v-html="page2"></div>
|
||||||
</div>
|
</div>
|
||||||
<div v-show="showStatusBar" ref="statusBar" class="layout">
|
<div v-show="showStatusBar" ref="statusBar" class="layout">
|
||||||
<div v-html="statusBar"></div>
|
<div v-html="statusBar"></div>
|
||||||
</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"
|
@wheel.prevent.stop="onMouseWheel"
|
||||||
@touchstart.stop="onTouchStart" @touchend.stop="onTouchEnd" @touchcancel.prevent.stop="onTouchCancel"
|
@touchstart.stop="onTouchStart" @touchend.stop="onTouchEnd" @touchcancel.prevent.stop="onTouchCancel"
|
||||||
oncontextmenu="return false;">
|
oncontextmenu="return false;">
|
||||||
@@ -23,6 +23,8 @@
|
|||||||
@click.prevent.stop="onStatusBarClick"></div>
|
@click.prevent.stop="onStatusBarClick"></div>
|
||||||
<div v-show="fontsLoading" ref="fontsLoading"></div>
|
<div v-show="fontsLoading" ref="fontsLoading"></div>
|
||||||
</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>
|
<canvas ref="offscreenCanvas" class="layout" style="width: 0px; height: 0px"></canvas>
|
||||||
</div>
|
</div>
|
||||||
@@ -45,10 +47,13 @@ const minLayoutWidth = 100;
|
|||||||
|
|
||||||
export default @Component({
|
export default @Component({
|
||||||
watch: {
|
watch: {
|
||||||
bookPos: function(newValue) {
|
bookPos: function() {
|
||||||
this.$emit('book-pos-changed', {bookPos: newValue, bookPosSeen: this.bookPosSeen});
|
this.$emit('book-pos-changed', {bookPos: this.bookPos, bookPosSeen: this.bookPosSeen});
|
||||||
this.draw();
|
this.draw();
|
||||||
},
|
},
|
||||||
|
bookPosSeen: function() {
|
||||||
|
this.$emit('book-pos-changed', {bookPos: this.bookPos, bookPosSeen: this.bookPosSeen});
|
||||||
|
},
|
||||||
settings: function() {
|
settings: function() {
|
||||||
this.debouncedLoadSettings();
|
this.debouncedLoadSettings();
|
||||||
},
|
},
|
||||||
@@ -60,6 +65,8 @@ export default @Component({
|
|||||||
class TextPage extends Vue {
|
class TextPage extends Vue {
|
||||||
toggleLayout = false;
|
toggleLayout = false;
|
||||||
showStatusBar = false;
|
showStatusBar = false;
|
||||||
|
clickControl = true;
|
||||||
|
|
||||||
background = null;
|
background = null;
|
||||||
page1 = null;
|
page1 = null;
|
||||||
page2 = null;
|
page2 = null;
|
||||||
@@ -69,6 +76,7 @@ class TextPage extends Vue {
|
|||||||
|
|
||||||
lastBook = null;
|
lastBook = null;
|
||||||
bookPos = 0;
|
bookPos = 0;
|
||||||
|
bookPosSeen = null;
|
||||||
|
|
||||||
fontStyle = null;
|
fontStyle = null;
|
||||||
fontSize = null;
|
fontSize = null;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import sax from '../../../../server/core/BookConverter/sax';
|
|||||||
import {sleep} from '../../../share/utils';
|
import {sleep} from '../../../share/utils';
|
||||||
|
|
||||||
export default class BookParser {
|
export default class BookParser {
|
||||||
constructor() {
|
constructor(settings) {
|
||||||
// defaults
|
// defaults
|
||||||
this.p = 30;// px, отступ параграфа
|
this.p = 30;// px, отступ параграфа
|
||||||
this.w = 300;// px, ширина страницы
|
this.w = 300;// px, ширина страницы
|
||||||
@@ -13,6 +13,12 @@ export default class BookParser {
|
|||||||
this.measureText = (text, style) => {// eslint-disable-line no-unused-vars
|
this.measureText = (text, style) => {// eslint-disable-line no-unused-vars
|
||||||
return text.length*20;
|
return text.length*20;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//настройки
|
||||||
|
if (settings) {
|
||||||
|
this.cutEmptyParagraphs = settings.cutEmptyParagraphs;
|
||||||
|
this.addEmptyParagraphs = settings.addEmptyParagraphs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async parse(data, callback) {
|
async parse(data, callback) {
|
||||||
@@ -48,7 +54,14 @@ export default class BookParser {
|
|||||||
text: String //текст параграфа (или title или epigraph и т.д) с вложенными тегами
|
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++;
|
paraIndex++;
|
||||||
let p = {
|
let p = {
|
||||||
index: paraIndex,
|
index: paraIndex,
|
||||||
@@ -63,12 +76,23 @@ export default class BookParser {
|
|||||||
|
|
||||||
const growParagraph = (text, len) => {
|
const growParagraph = (text, len) => {
|
||||||
if (paraIndex < 0) {
|
if (paraIndex < 0) {
|
||||||
newParagraph(text, len);
|
newParagraph(' ', 1);
|
||||||
|
growParagraph(text, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let p = para[paraIndex];
|
let p = para[paraIndex];
|
||||||
if (p) {
|
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;
|
paraOffset -= p.length;
|
||||||
if (p.length == 1 && p.text[0] == ' ' && len > 0) {
|
if (p.length == 1 && p.text[0] == ' ' && len > 0) {
|
||||||
p.length = 0;
|
p.length = 0;
|
||||||
@@ -96,55 +120,63 @@ export default class BookParser {
|
|||||||
tag = elemName;
|
tag = elemName;
|
||||||
path += '/' + elemName;
|
path += '/' + elemName;
|
||||||
|
|
||||||
if ((tag == 'p' || tag == 'empty-line' || tag == 'v') && path.indexOf('/fictionbook/body/section') == 0) {
|
if (path.indexOf('/fictionbook/body') == 0) {
|
||||||
newParagraph(' ', 1);
|
if (tag == 'title') {
|
||||||
}
|
newParagraph(' ', 1);
|
||||||
|
bold = true;
|
||||||
|
center = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (tag == 'emphasis' || tag == 'strong') {
|
if (tag == 'emphasis' || tag == 'strong') {
|
||||||
growParagraph(`<${tag}>`, 0);
|
growParagraph(`<${tag}>`, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'title') {
|
if ((tag == 'p' || tag == 'empty-line' || tag == 'v')) {
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
bold = true;
|
}
|
||||||
center = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tag == 'subtitle') {
|
if (tag == 'subtitle') {
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
bold = true;
|
bold = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'epigraph') {
|
if (tag == 'epigraph') {
|
||||||
italic = true;
|
italic = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'stanza') {
|
if (tag == 'poem') {
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'text-author') {
|
||||||
|
newParagraph(' <s> <s> <s> ', 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onEndNode = (elemName) => {// eslint-disable-line no-unused-vars
|
const onEndNode = (elemName) => {// eslint-disable-line no-unused-vars
|
||||||
if (tag == elemName) {
|
if (tag == elemName) {
|
||||||
if (tag == 'emphasis' || tag == 'strong') {
|
if (path.indexOf('/fictionbook/body') == 0) {
|
||||||
growParagraph(`</${tag}>`, 0);
|
if (tag == 'title') {
|
||||||
}
|
bold = false;
|
||||||
|
center = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (tag == 'title') {
|
if (tag == 'emphasis' || tag == 'strong') {
|
||||||
bold = false;
|
growParagraph(`</${tag}>`, 0);
|
||||||
center = false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (tag == 'subtitle') {
|
if (tag == 'subtitle') {
|
||||||
bold = false;
|
bold = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'epigraph') {
|
if (tag == 'epigraph') {
|
||||||
italic = false;
|
italic = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'stanza') {
|
if (tag == 'stanza') {
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
path = path.substr(0, path.length - tag.length - 1);
|
path = path.substr(0, path.length - tag.length - 1);
|
||||||
@@ -206,12 +238,12 @@ export default class BookParser {
|
|||||||
let tOpen = (center ? '<center>' : '');
|
let tOpen = (center ? '<center>' : '');
|
||||||
tOpen += (bold ? '<strong>' : '');
|
tOpen += (bold ? '<strong>' : '');
|
||||||
tOpen += (italic ? '<emphasis>' : '');
|
tOpen += (italic ? '<emphasis>' : '');
|
||||||
let tClose = (center ? '</center>' : '');
|
let tClose = (italic ? '</emphasis>' : '');
|
||||||
tClose += (bold ? '</strong>' : '');
|
tClose += (bold ? '</strong>' : '');
|
||||||
tClose += (italic ? '</emphasis>' : '');
|
tClose += (center ? '</center>' : '');
|
||||||
|
|
||||||
if (path.indexOf('/fictionbook/body/title') == 0) {
|
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) {
|
if (path.indexOf('/fictionbook/body/section') == 0) {
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ const bmRecentStore = localForage.createInstance({
|
|||||||
});
|
});
|
||||||
|
|
||||||
class BookManager {
|
class BookManager {
|
||||||
async init() {
|
async init(settings) {
|
||||||
|
this.settings = settings;
|
||||||
this.books = {};
|
this.books = {};
|
||||||
this.recent = {};
|
this.recent = {};
|
||||||
this.recentChanged = true;
|
this.recentChanged = true;
|
||||||
@@ -130,7 +131,7 @@ class BookManager {
|
|||||||
async parseBook(meta, data, callback) {
|
async parseBook(meta, data, callback) {
|
||||||
if (!this.books)
|
if (!this.books)
|
||||||
await this.init();
|
await this.init();
|
||||||
const parsed = new BookParser();
|
const parsed = new BookParser(this.settings);
|
||||||
|
|
||||||
const parsedMeta = await parsed.parse(data, callback);
|
const parsedMeta = await parsed.parse(data, callback);
|
||||||
const result = Object.assign({}, meta, parsedMeta, {
|
const result = Object.assign({}, meta, parsedMeta, {
|
||||||
|
|||||||
@@ -159,6 +159,10 @@ const settingDefaults = {
|
|||||||
lazyParseEnabled: false,
|
lazyParseEnabled: false,
|
||||||
copyFullText: false,
|
copyFullText: false,
|
||||||
showClickMapPage: true,
|
showClickMapPage: true,
|
||||||
|
clickControl: true,
|
||||||
|
cutEmptyParagraphs: false,
|
||||||
|
addEmptyParagraphs: 0,
|
||||||
|
|
||||||
fontShifts: {},
|
fontShifts: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
15
package-lock.json
generated
15
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.1.0",
|
"version": "0.1.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -6501,9 +6501,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "0.0.8",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||||
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
|
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
|
||||||
},
|
},
|
||||||
"minipass": {
|
"minipass": {
|
||||||
"version": "2.3.5",
|
"version": "2.3.5",
|
||||||
@@ -6567,6 +6567,13 @@
|
|||||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"minimist": "0.0.8"
|
"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": {
|
"move-concurrently": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.1.0",
|
"version": "0.1.5",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
},
|
},
|
||||||
@@ -70,6 +70,7 @@
|
|||||||
"iconv-lite": "^0.4.24",
|
"iconv-lite": "^0.4.24",
|
||||||
"localforage": "^1.7.3",
|
"localforage": "^1.7.3",
|
||||||
"lodash": "^4.17.11",
|
"lodash": "^4.17.11",
|
||||||
|
"minimist": "^1.2.0",
|
||||||
"multer": "^1.4.1",
|
"multer": "^1.4.1",
|
||||||
"path-browserify": "^1.0.0",
|
"path-browserify": "^1.0.0",
|
||||||
"sql-template-strings": "^2.2.2",
|
"sql-template-strings": "^2.2.2",
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ module.exports = {
|
|||||||
dbFileName: 'db.sqlite',
|
dbFileName: 'db.sqlite',
|
||||||
loggingEnabled: true,
|
loggingEnabled: true,
|
||||||
|
|
||||||
|
maxUploadFileSize: 50*1024*1024,//50Мб
|
||||||
|
maxTempPublicDirSize: 512*1024*1024,//512Мб
|
||||||
|
maxUploadPublicDirSize: 200*1024*1024,//100Мб
|
||||||
|
|
||||||
servers: [
|
servers: [
|
||||||
{
|
{
|
||||||
serverName: '1',
|
serverName: '1',
|
||||||
@@ -24,12 +28,6 @@ module.exports = {
|
|||||||
ip: '0.0.0.0',
|
ip: '0.0.0.0',
|
||||||
port: '33080',
|
port: '33080',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
serverName: '2',
|
|
||||||
mode: 'omnireader',
|
|
||||||
ip: '0.0.0.0',
|
|
||||||
port: '33081',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
36
server/config/configSaver.js
Normal file
36
server/config/configSaver.js
Normal 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
|
||||||
|
};
|
||||||
@@ -19,12 +19,6 @@ module.exports = Object.assign({}, base, {
|
|||||||
ip: '0.0.0.0',
|
ip: '0.0.0.0',
|
||||||
port: '44080',
|
port: '44080',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
serverName: '2',
|
|
||||||
mode: 'omnireader',
|
|
||||||
ip: '0.0.0.0',
|
|
||||||
port: '44081',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
function getEncoding(buf) {
|
|
||||||
const lowerCase = 3;
|
|
||||||
const upperCase = 1;
|
|
||||||
|
|
||||||
const codePage = {
|
|
||||||
'k': 'koi8-r',
|
|
||||||
'w': 'Windows-1251',
|
|
||||||
'd': 'cp866',
|
|
||||||
'i': 'ISO-8859-5',
|
|
||||||
'm': 'maccyrillic',
|
|
||||||
};
|
|
||||||
|
|
||||||
let charsets = {
|
|
||||||
'k': 0,
|
|
||||||
'w': 0,
|
|
||||||
'd': 0,
|
|
||||||
'i': 0,
|
|
||||||
'm': 0
|
|
||||||
};
|
|
||||||
|
|
||||||
const len = buf.length;
|
|
||||||
const blockSize = (len > 5*3000 ? 3000 : len);
|
|
||||||
let counter = 0;
|
|
||||||
let i = 0;
|
|
||||||
while (i < len) {
|
|
||||||
const char = buf[i];
|
|
||||||
i++;
|
|
||||||
//non-russian characters
|
|
||||||
if (char < 128 || char > 256)
|
|
||||||
continue;
|
|
||||||
//CP866
|
|
||||||
if ((char > 159 && char < 176) || (char > 223 && char < 242)) charsets['d'] += lowerCase;
|
|
||||||
if ((char > 127 && char < 160)) charsets['d'] += upperCase;
|
|
||||||
|
|
||||||
//KOI8-R
|
|
||||||
if ((char > 191 && char < 223)) charsets['k'] += lowerCase;
|
|
||||||
if ((char > 222 && char < 256)) charsets['k'] += upperCase;
|
|
||||||
|
|
||||||
//WIN-1251
|
|
||||||
if (char > 223 && char < 256) charsets['w'] += lowerCase;
|
|
||||||
if (char > 191 && char < 224) charsets['w'] += upperCase;
|
|
||||||
|
|
||||||
//MAC
|
|
||||||
if (char > 221 && char < 255) charsets['m'] += lowerCase;
|
|
||||||
if (char > 127 && char < 160) charsets['m'] += upperCase;
|
|
||||||
|
|
||||||
//ISO-8859-5
|
|
||||||
if (char > 207 && char < 240) charsets['i'] += lowerCase;
|
|
||||||
if (char > 175 && char < 208) charsets['i'] += upperCase;
|
|
||||||
|
|
||||||
counter++;
|
|
||||||
|
|
||||||
if (counter > blockSize) {
|
|
||||||
counter = 0;
|
|
||||||
i += Math.round(len/2 - 2*blockSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sorted = Object.keys(charsets).map(function(key) {
|
|
||||||
return { codePage: codePage[key], c: charsets[key] };
|
|
||||||
});
|
|
||||||
|
|
||||||
sorted.sort((a, b) => b.c - a.c);
|
|
||||||
|
|
||||||
return sorted[0].codePage;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = getEncoding;
|
|
||||||
@@ -4,7 +4,7 @@ const iconv = require('iconv-lite');
|
|||||||
const chardet = require('chardet');
|
const chardet = require('chardet');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const sax = require('./sax');
|
const sax = require('./sax');
|
||||||
const getEncoding = require('./getEncoding');
|
const textUtils = require('./textUtils');
|
||||||
|
|
||||||
const FileDetector = require('../FileDetector');
|
const FileDetector = require('../FileDetector');
|
||||||
|
|
||||||
@@ -18,11 +18,12 @@ class BookConverter {
|
|||||||
async convertToFb2(inputFile, outputFile, url, callback) {
|
async convertToFb2(inputFile, outputFile, url, callback) {
|
||||||
const fileType = await this.detector.detectFile(inputFile);
|
const fileType = await this.detector.detectFile(inputFile);
|
||||||
|
|
||||||
if (fileType && (fileType.ext == 'html' || fileType.ext == 'xml')) {
|
const data = await fs.readFile(inputFile);
|
||||||
const data = await fs.readFile(inputFile);
|
callback(100);
|
||||||
|
|
||||||
if (data.toString().indexOf('<FictionBook') >= 0) {
|
if (fileType && (fileType.ext == 'html' || fileType.ext == 'xml')) {
|
||||||
await fs.writeFile(outputFile, data);
|
if (data.toString().indexOf('<FictionBook') >= 0) {
|
||||||
|
await fs.writeFile(outputFile, this.checkEncoding(data));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,12 +35,19 @@ class BookConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await fs.writeFile(outputFile, this.convertHtml(data));
|
await fs.writeFile(outputFile, this.convertHtml(data));
|
||||||
callback(100);
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (fileType)
|
if (fileType)
|
||||||
throw new Error(`unknown file format: ${fileType.mime}`);
|
throw new Error(`Этот формат файла не поддерживается: ${fileType.mime}`);
|
||||||
else
|
else {
|
||||||
throw new Error(`unsupported file format: ${url}`);
|
//может это чистый текст?
|
||||||
|
if (textUtils.checkIfText(data)) {
|
||||||
|
await fs.writeFile(outputFile, this.convertHtml(data));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Не удалось определить формат файла: ${url}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,12 +63,34 @@ class BookConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (selected == 'ISO-8859-5') {
|
if (selected == 'ISO-8859-5') {
|
||||||
selected = getEncoding(data);
|
selected = textUtils.getEncoding(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
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};
|
||||||
|
|||||||
85
server/core/BookConverter/textUtils.js
Normal file
85
server/core/BookConverter/textUtils.js
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
function getEncoding(buf) {
|
||||||
|
const lowerCase = 3;
|
||||||
|
const upperCase = 1;
|
||||||
|
|
||||||
|
const codePage = {
|
||||||
|
'k': 'koi8-r',
|
||||||
|
'w': 'Windows-1251',
|
||||||
|
'd': 'cp866',
|
||||||
|
'i': 'ISO-8859-5',
|
||||||
|
'm': 'maccyrillic',
|
||||||
|
};
|
||||||
|
|
||||||
|
let charsets = {
|
||||||
|
'k': 0,
|
||||||
|
'w': 0,
|
||||||
|
'd': 0,
|
||||||
|
'i': 0,
|
||||||
|
'm': 0
|
||||||
|
};
|
||||||
|
|
||||||
|
const len = buf.length;
|
||||||
|
const blockSize = (len > 5*3000 ? 3000 : len);
|
||||||
|
let counter = 0;
|
||||||
|
let i = 0;
|
||||||
|
while (i < len) {
|
||||||
|
const char = buf[i];
|
||||||
|
i++;
|
||||||
|
//non-russian characters
|
||||||
|
if (char < 128 || char > 256)
|
||||||
|
continue;
|
||||||
|
//CP866
|
||||||
|
if ((char > 159 && char < 176) || (char > 223 && char < 242)) charsets['d'] += lowerCase;
|
||||||
|
if ((char > 127 && char < 160)) charsets['d'] += upperCase;
|
||||||
|
|
||||||
|
//KOI8-R
|
||||||
|
if ((char > 191 && char < 223)) charsets['k'] += lowerCase;
|
||||||
|
if ((char > 222 && char < 256)) charsets['k'] += upperCase;
|
||||||
|
|
||||||
|
//WIN-1251
|
||||||
|
if (char > 223 && char < 256) charsets['w'] += lowerCase;
|
||||||
|
if (char > 191 && char < 224) charsets['w'] += upperCase;
|
||||||
|
|
||||||
|
//MAC
|
||||||
|
if (char > 221 && char < 255) charsets['m'] += lowerCase;
|
||||||
|
if (char > 127 && char < 160) charsets['m'] += upperCase;
|
||||||
|
|
||||||
|
//ISO-8859-5
|
||||||
|
if (char > 207 && char < 240) charsets['i'] += lowerCase;
|
||||||
|
if (char > 175 && char < 208) charsets['i'] += upperCase;
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
|
||||||
|
if (counter > blockSize) {
|
||||||
|
counter = 0;
|
||||||
|
i += Math.round(len/2 - 2*blockSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sorted = Object.keys(charsets).map(function(key) {
|
||||||
|
return { codePage: codePage[key], c: charsets[key] };
|
||||||
|
});
|
||||||
|
|
||||||
|
sorted.sort((a, b) => b.c - a.c);
|
||||||
|
|
||||||
|
if (sorted[0].c > 0)
|
||||||
|
return sorted[0].codePage;
|
||||||
|
else
|
||||||
|
return 'ISO-8859-5';
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkIfText(buf) {
|
||||||
|
let spaceCount = 0;
|
||||||
|
for (let i = 0; i < buf.length; i++) {
|
||||||
|
if (buf[i] == 32)
|
||||||
|
spaceCount++;
|
||||||
|
}
|
||||||
|
const freq = spaceCount/(buf.length + 1);
|
||||||
|
|
||||||
|
return (freq > 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getEncoding,
|
||||||
|
checkIfText,
|
||||||
|
}
|
||||||
@@ -8,8 +8,6 @@ const FileDecompressor = require('./FileDecompressor');
|
|||||||
const BookConverter = require('./BookConverter');
|
const BookConverter = require('./BookConverter');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
|
||||||
const maxTempPublicDirSize = 512*1024*1024;//512Мб
|
|
||||||
const maxUploadDirSize = 200*1024*1024;//100Мб
|
|
||||||
let singleCleanExecute = false;
|
let singleCleanExecute = false;
|
||||||
|
|
||||||
class ReaderWorker {
|
class ReaderWorker {
|
||||||
@@ -27,8 +25,8 @@ class ReaderWorker {
|
|||||||
this.bookConverter = new BookConverter();
|
this.bookConverter = new BookConverter();
|
||||||
|
|
||||||
if (!singleCleanExecute) {
|
if (!singleCleanExecute) {
|
||||||
this.periodicCleanDir(this.config.tempPublicDir, maxTempPublicDirSize, 60*60*1000);//1 раз в час
|
this.periodicCleanDir(this.config.tempPublicDir, this.config.maxTempPublicDirSize, 60*60*1000);//1 раз в час
|
||||||
this.periodicCleanDir(this.config.uploadDir, maxUploadDirSize, 60*60*1000);//1 раз в час
|
this.periodicCleanDir(this.config.uploadDir, this.config.maxUploadPublicDirSize, 60*60*1000);//1 раз в час
|
||||||
singleCleanExecute = true;
|
singleCleanExecute = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
|
|
||||||
const {initLogger, getLog} = require('./core/getLogger');
|
const {initLogger, getLog} = require('./core/getLogger');
|
||||||
initLogger(config);
|
initLogger(config);
|
||||||
const log = getLog();
|
const log = getLog();
|
||||||
|
|
||||||
|
const configSaver = require('./config/configSaver');
|
||||||
|
const argv = require('minimist')(process.argv.slice(2));
|
||||||
|
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
@@ -23,15 +25,17 @@ async function init() {
|
|||||||
await fs.remove(appDir);
|
await fs.remove(appDir);
|
||||||
await fs.move(appNewDir, appDir);
|
await fs.move(appNewDir, appDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//загружаем конфиг из файла
|
||||||
|
await configSaver.load(config, argv.config);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const connPool = new SqliteConnectionPool(20, config);
|
|
||||||
|
|
||||||
log('Initializing');
|
log('Initializing');
|
||||||
await init();
|
await init();
|
||||||
|
|
||||||
log('Opening database');
|
log('Opening database');
|
||||||
|
const connPool = new SqliteConnectionPool(20, config);
|
||||||
await connPool.init();
|
await connPool.init();
|
||||||
|
|
||||||
//servers
|
//servers
|
||||||
@@ -42,7 +46,7 @@ async function main() {
|
|||||||
|
|
||||||
let devModule = undefined;
|
let devModule = undefined;
|
||||||
if (serverConfig.branch == 'development') {
|
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 = require(devFileName);
|
||||||
devModule.webpackDevMiddleware(app);
|
devModule.webpackDevMiddleware(app);
|
||||||
}
|
}
|
||||||
@@ -80,4 +84,12 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
|
||||||
|
(async() => {
|
||||||
|
try {
|
||||||
|
await main();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -2,8 +2,6 @@ const c = require('./controllers');
|
|||||||
const utils = require('./core/utils');
|
const utils = require('./core/utils');
|
||||||
const multer = require('multer');
|
const multer = require('multer');
|
||||||
|
|
||||||
const maxUploadSize = 50*1024*1024;
|
|
||||||
|
|
||||||
function initRoutes(app, connPool, config) {
|
function initRoutes(app, connPool, config) {
|
||||||
const misc = new c.MiscController(connPool, config);
|
const misc = new c.MiscController(connPool, config);
|
||||||
const reader = new c.ReaderController(connPool, config);
|
const reader = new c.ReaderController(connPool, config);
|
||||||
@@ -22,7 +20,7 @@ function initRoutes(app, connPool, config) {
|
|||||||
cb(null, utils.randomHexString(30));
|
cb(null, utils.randomHexString(30));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const upload = multer({ storage, limits: {fileSize: maxUploadSize} });
|
const upload = multer({ storage, limits: {fileSize: config.maxUploadFileSize} });
|
||||||
|
|
||||||
//routes
|
//routes
|
||||||
const routes = [
|
const routes = [
|
||||||
|
|||||||
Reference in New Issue
Block a user