Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3920b71613 | ||
|
|
d661150665 | ||
|
|
ab29c80dab | ||
|
|
e5384e27e5 | ||
|
|
06cdc6eb63 | ||
|
|
da284c793e | ||
|
|
c2cef91eb3 | ||
|
|
19da1aff45 | ||
|
|
5f2206e766 | ||
|
|
e272308823 | ||
|
|
8491c40890 | ||
|
|
dfa7013cbd | ||
|
|
1a7ceb333d | ||
|
|
d3a30b87f4 | ||
|
|
dd61c04d63 | ||
|
|
5496e874c4 | ||
|
|
56d13288ff | ||
|
|
618111ab05 | ||
|
|
55d02495a3 | ||
|
|
83fc586e03 | ||
|
|
ae3dc9b22c | ||
|
|
12e0f9459b | ||
|
|
fd1dd54b99 | ||
|
|
32cbb2a82c | ||
|
|
048b7c08ca | ||
|
|
d98251e34a | ||
|
|
1eea4e8fc1 | ||
|
|
da330bc615 | ||
|
|
1134250954 | ||
|
|
d8fddd4128 | ||
|
|
42656cd690 | ||
|
|
746f9517d9 | ||
|
|
2a373de5f5 | ||
|
|
b507f00929 | ||
|
|
aea8a254bf | ||
|
|
4247665ba4 | ||
|
|
d59d0a6a42 | ||
|
|
8d40ed0bda | ||
|
|
67bc893e22 | ||
|
|
0f5d3b34a5 |
@@ -4,7 +4,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li><b>F1, H</b> - открыть справку</li>
|
<li><b>F1, H</b> - открыть справку</li>
|
||||||
<li><b>Escape</b> - показать/скрыть страницу загрузки</li>
|
<li><b>Escape</b> - показать/скрыть страницу загрузки</li>
|
||||||
<li><b>Tab</b> - показать/скрыть панель управления</li>
|
<li><b>Tab, Q</b> - показать/скрыть панель управления</li>
|
||||||
<li><b>PageUp, Left, Shift+Space, Backspace</b> - страницу назад</li>
|
<li><b>PageUp, Left, Shift+Space, Backspace</b> - страницу назад</li>
|
||||||
<li><b>PageDown, Right, Space</b> - страницу вперед</li>
|
<li><b>PageDown, Right, Space</b> - страницу вперед</li>
|
||||||
<li><b>Home</b> - в начало книги</li>
|
<li><b>Home</b> - в начало книги</li>
|
||||||
|
|||||||
@@ -103,6 +103,13 @@ class LoaderPage extends Vue {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.type == 'keydown' && (document.activeElement !== input && event.code == 'KeyQ')) {
|
||||||
|
this.$emit('tool-bar-toggle');
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -201,7 +201,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') {
|
||||||
|
|||||||
@@ -194,6 +194,35 @@
|
|||||||
<el-input-number v-model="addEmptyParagraphs" :min="0" :max="2"></el-input-number>
|
<el-input-number v-model="addEmptyParagraphs" :min="0" :max="2"></el-input-number>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="Изображения">
|
||||||
|
<el-col :span="11">
|
||||||
|
<el-checkbox v-model="showImages">Показывать</el-checkbox>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
|
<el-col :span="1">
|
||||||
|
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="11">
|
||||||
|
<el-tooltip :open-delay="500" effect="light" placement="top">
|
||||||
|
<template slot="content">
|
||||||
|
Выносить все изображения в центр экрана
|
||||||
|
</template>
|
||||||
|
<el-checkbox v-model="showInlineImagesInCenter" @change="needReload">Инлайн в центр</el-checkbox>
|
||||||
|
</el-tooltip>
|
||||||
|
</el-col>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="">
|
||||||
|
Размер изображения
|
||||||
|
<el-tooltip :open-delay="500" effect="light" placement="top">
|
||||||
|
<template slot="content">
|
||||||
|
Определяет высоту изображения количеством строк.<br>
|
||||||
|
В случае превышения высоты, изображение будет<br>
|
||||||
|
уменьшено с сохранением пропорций так, чтобы<br>
|
||||||
|
помещаться в указанное количество строк.
|
||||||
|
</template>
|
||||||
|
<el-input-number v-model="imageHeightLines" :min="1" :max="100"></el-input-number>
|
||||||
|
</el-tooltip>
|
||||||
|
</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>
|
||||||
|
|||||||
@@ -26,10 +26,11 @@ export default class DrawHelper {
|
|||||||
const font = this.fontByStyle({});
|
const font = this.fontByStyle({});
|
||||||
const justify = (this.textAlignJustify ? 'text-align: justify; text-align-last: justify;' : '');
|
const justify = (this.textAlignJustify ? 'text-align: justify; text-align-last: justify;' : '');
|
||||||
|
|
||||||
let out = `<div class="layout" style="width: ${this.w}px; height: ${this.h}px;` +
|
let out = `<div style="width: ${this.w}px; height: ${this.h}px;` +
|
||||||
` position: absolute; top: ${this.fontSize*this.textShift}px; color: ${this.textColor}; font: ${font}; ${justify}` +
|
` position: absolute; top: ${this.fontSize*this.textShift}px; color: ${this.textColor}; font: ${font}; ${justify}` +
|
||||||
` line-height: ${this.lineHeight}px;">`;
|
` line-height: ${this.lineHeight}px;">`;
|
||||||
|
|
||||||
|
let imageDrawn = new Set();
|
||||||
let len = lines.length;
|
let len = lines.length;
|
||||||
const lineCount = this.pageLineCount + (isScrolling ? 1 : 0);
|
const lineCount = this.pageLineCount + (isScrolling ? 1 : 0);
|
||||||
len = (len > lineCount ? lineCount : len);
|
len = (len > lineCount ? lineCount : len);
|
||||||
@@ -43,11 +44,13 @@ export default class DrawHelper {
|
|||||||
first: Boolean,
|
first: Boolean,
|
||||||
last: Boolean,
|
last: Boolean,
|
||||||
parts: array of {
|
parts: array of {
|
||||||
style: {bold: Boolean, italic: Boolean, center: Boolean}
|
style: {bold: Boolean, italic: Boolean, center: Boolean},
|
||||||
|
image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number},
|
||||||
text: String,
|
text: String,
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
let sel = new Set();
|
let sel = new Set();
|
||||||
|
//поиск
|
||||||
if (i == 0 && this.searching) {
|
if (i == 0 && this.searching) {
|
||||||
let pureText = '';
|
let pureText = '';
|
||||||
for (const part of line.parts) {
|
for (const part of line.parts) {
|
||||||
@@ -70,7 +73,9 @@ export default class DrawHelper {
|
|||||||
|
|
||||||
let lineText = '';
|
let lineText = '';
|
||||||
let center = false;
|
let center = false;
|
||||||
|
let space = 0;
|
||||||
let j = 0;
|
let j = 0;
|
||||||
|
//формируем строку
|
||||||
for (const part of line.parts) {
|
for (const part of line.parts) {
|
||||||
let tOpen = (part.style.bold ? '<b>' : '');
|
let tOpen = (part.style.bold ? '<b>' : '');
|
||||||
tOpen += (part.style.italic ? '<i>' : '');
|
tOpen += (part.style.italic ? '<i>' : '');
|
||||||
@@ -86,14 +91,64 @@ export default class DrawHelper {
|
|||||||
} else
|
} else
|
||||||
text = part.text;
|
text = part.text;
|
||||||
|
|
||||||
|
if (text.trim() == '')
|
||||||
|
text = `<span style="white-space: pre">${text}</span>`;
|
||||||
|
|
||||||
lineText += `${tOpen}${text}${tClose}`;
|
lineText += `${tOpen}${text}${tClose}`;
|
||||||
|
|
||||||
center = center || part.style.center;
|
center = center || part.style.center;
|
||||||
|
space = (part.style.space > 0 ? part.style.space : space);
|
||||||
|
|
||||||
|
//избражения
|
||||||
|
//image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number},
|
||||||
|
const img = part.image;
|
||||||
|
if (img && img.id && !img.inline && !imageDrawn.has(img.paraIndex)) {
|
||||||
|
const bin = this.parsed.binary[img.id];
|
||||||
|
if (bin) {
|
||||||
|
let imgH = img.lineCount*this.lineHeight;
|
||||||
|
imgH = (imgH <= bin.h ? imgH : bin.h);
|
||||||
|
let imgW = bin.w;
|
||||||
|
|
||||||
|
let resize = '';
|
||||||
|
if (bin.h > imgH) {
|
||||||
|
resize = `height: ${imgH}px`;
|
||||||
|
imgW = imgW*imgH/bin.h;
|
||||||
|
}
|
||||||
|
|
||||||
|
const left = (this.w - imgW)/2;
|
||||||
|
const top = ((img.lineCount*this.lineHeight - imgH)/2) + (i - img.imageLine)*this.lineHeight;
|
||||||
|
if (img.local) {
|
||||||
|
lineText += `<img src="data:${bin.type};base64,${bin.data}" style="position: absolute; left: ${left}px; top: ${top}px; ${resize}"/>`;
|
||||||
|
} else {
|
||||||
|
lineText += `<img src="${img.id}" style="position: absolute; left: ${left}px; top: ${top}px; ${resize}"/>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imageDrawn.add(img.paraIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (img && img.id && img.inline) {
|
||||||
|
if (img.local) {
|
||||||
|
const bin = this.parsed.binary[img.id];
|
||||||
|
if (bin) {
|
||||||
|
let resize = '';
|
||||||
|
if (bin.h > this.fontSize) {
|
||||||
|
resize = `height: ${this.fontSize - 3}px`;
|
||||||
|
}
|
||||||
|
lineText += `<img src="data:${bin.type};base64,${bin.data}" style="${resize}"/>`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const centerStyle = (center ? `text-align: center; text-align-last: center; width: ${this.w}px` : '')
|
const centerStyle = (center ? `text-align: center; text-align-last: center; width: ${this.w}px` : '')
|
||||||
if (line.first)
|
if ((line.first || space) && !center) {
|
||||||
lineText = `<span style="display: inline-block; margin-left: ${this.p}px"></span>${lineText}`;
|
let p = (line.first ? this.p : 0);
|
||||||
|
p = (space ? p + this.p*space : p);
|
||||||
|
lineText = `<span style="display: inline-block; margin-left: ${p}px"></span>${lineText}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (line.last || center)
|
if (line.last || center)
|
||||||
lineText = `<span style="display: inline-block; ${centerStyle}">${lineText}</span>`;
|
lineText = `<span style="display: inline-block; ${centerStyle}">${lineText}</span>`;
|
||||||
|
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ class TextPage extends Vue {
|
|||||||
this.parsed.p = this.p;
|
this.parsed.p = this.p;
|
||||||
this.parsed.w = this.w;// px, ширина текста
|
this.parsed.w = this.w;// px, ширина текста
|
||||||
this.parsed.font = this.font;
|
this.parsed.font = this.font;
|
||||||
|
this.parsed.fontSize = this.fontSize;
|
||||||
this.parsed.wordWrap = this.wordWrap;
|
this.parsed.wordWrap = this.wordWrap;
|
||||||
this.parsed.cutEmptyParagraphs = this.cutEmptyParagraphs;
|
this.parsed.cutEmptyParagraphs = this.cutEmptyParagraphs;
|
||||||
this.parsed.addEmptyParagraphs = this.addEmptyParagraphs;
|
this.parsed.addEmptyParagraphs = this.addEmptyParagraphs;
|
||||||
@@ -216,6 +217,10 @@ class TextPage extends Vue {
|
|||||||
while (this.drawHelper.measureText(t, {}) < this.w) t += 'Щ';
|
while (this.drawHelper.measureText(t, {}) < this.w) t += 'Щ';
|
||||||
this.parsed.maxWordLength = t.length - 1;
|
this.parsed.maxWordLength = t.length - 1;
|
||||||
this.parsed.measureText = this.drawHelper.measureText.bind(this.drawHelper);
|
this.parsed.measureText = this.drawHelper.measureText.bind(this.drawHelper);
|
||||||
|
this.parsed.lineHeight = this.lineHeight;
|
||||||
|
this.parsed.showImages = this.showImages;
|
||||||
|
this.parsed.showInlineImagesInCenter = this.showInlineImagesInCenter;
|
||||||
|
this.parsed.imageHeightLines = this.imageHeightLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
//statusBar
|
//statusBar
|
||||||
@@ -930,6 +935,7 @@ class TextPage extends Vue {
|
|||||||
this.$emit('full-screen-toogle');
|
this.$emit('full-screen-toogle');
|
||||||
break;
|
break;
|
||||||
case 'Tab':
|
case 'Tab':
|
||||||
|
case 'KeyQ':
|
||||||
this.doToolBarToggle();
|
this.doToolBarToggle();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|||||||
@@ -2,8 +2,14 @@ import he from 'he';
|
|||||||
import sax from '../../../../server/core/BookConverter/sax';
|
import sax from '../../../../server/core/BookConverter/sax';
|
||||||
import {sleep} from '../../../share/utils';
|
import {sleep} from '../../../share/utils';
|
||||||
|
|
||||||
|
const maxImageLineCount = 100;
|
||||||
|
|
||||||
export default class BookParser {
|
export default class BookParser {
|
||||||
constructor() {
|
constructor(settings) {
|
||||||
|
if (settings) {
|
||||||
|
this.showInlineImagesInCenter = settings.showInlineImagesInCenter;
|
||||||
|
}
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
this.p = 30;// px, отступ параграфа
|
this.p = 30;// px, отступ параграфа
|
||||||
this.w = 300;// px, ширина страницы
|
this.w = 300;// px, ширина страницы
|
||||||
@@ -37,6 +43,13 @@ export default class BookParser {
|
|||||||
let center = false;
|
let center = false;
|
||||||
let bold = false;
|
let bold = false;
|
||||||
let italic = false;
|
let italic = false;
|
||||||
|
let space = 0;
|
||||||
|
let inPara = false;
|
||||||
|
|
||||||
|
this.binary = {};
|
||||||
|
let binaryId = '';
|
||||||
|
let binaryType = '';
|
||||||
|
let dimPromises = [];
|
||||||
|
|
||||||
let paraIndex = -1;
|
let paraIndex = -1;
|
||||||
let paraOffset = 0;
|
let paraOffset = 0;
|
||||||
@@ -50,6 +63,56 @@ export default class BookParser {
|
|||||||
addIndex: Number, //индекс добавляемого пустого параграфа (addEmptyParagraphs)
|
addIndex: Number, //индекс добавляемого пустого параграфа (addEmptyParagraphs)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
const getImageDimensions = (binaryId, binaryType, data) => {
|
||||||
|
return new Promise (async(resolve, reject) => {
|
||||||
|
const i = new Image();
|
||||||
|
let resolved = false;
|
||||||
|
i.onload = () => {
|
||||||
|
resolved = true;
|
||||||
|
this.binary[binaryId] = {
|
||||||
|
w: i.width,
|
||||||
|
h: i.height,
|
||||||
|
type: binaryType,
|
||||||
|
data
|
||||||
|
};
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
i.onerror = (e) => {
|
||||||
|
reject(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
i.src = `data:${binaryType};base64,${data}`;
|
||||||
|
await sleep(30*1000);
|
||||||
|
if (!resolved)
|
||||||
|
reject('Не удалось получить размер изображения');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const getExternalImageDimensions = (src) => {
|
||||||
|
return new Promise (async(resolve, reject) => {
|
||||||
|
const i = new Image();
|
||||||
|
let resolved = false;
|
||||||
|
i.onload = () => {
|
||||||
|
resolved = true;
|
||||||
|
this.binary[src] = {
|
||||||
|
w: i.width,
|
||||||
|
h: i.height,
|
||||||
|
};
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
i.onerror = (e) => {
|
||||||
|
reject(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
i.src = src;
|
||||||
|
await sleep(30*1000);
|
||||||
|
if (!resolved)
|
||||||
|
reject('Не удалось получить размер изображения');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const newParagraph = (text, len, addIndex) => {
|
const newParagraph = (text, len, addIndex) => {
|
||||||
paraIndex++;
|
paraIndex++;
|
||||||
let p = {
|
let p = {
|
||||||
@@ -103,13 +166,38 @@ export default class BookParser {
|
|||||||
paraOffset += p.length;
|
paraOffset += p.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
const onStartNode = (elemName) => {// eslint-disable-line no-unused-vars
|
const onStartNode = (elemName, tail) => {// eslint-disable-line no-unused-vars
|
||||||
if (elemName == '?xml')
|
if (elemName == '?xml')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tag = elemName;
|
tag = elemName;
|
||||||
path += '/' + elemName;
|
path += '/' + elemName;
|
||||||
|
|
||||||
|
if (tag == 'binary') {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
binaryType = (attrs['content-type'] && attrs['content-type'].value ? attrs['content-type'].value : '');
|
||||||
|
if (binaryType == 'image/jpeg' || binaryType == 'image/png')
|
||||||
|
binaryId = (attrs.id.value ? attrs.id.value : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'image') {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
if (attrs.href && attrs.href.value) {
|
||||||
|
const href = attrs.href.value;
|
||||||
|
if (href[0] == '#') {//local
|
||||||
|
if (inPara && !this.showInlineImagesInCenter)
|
||||||
|
growParagraph(`<image-inline href="${href}"></image-inline>`, 0);
|
||||||
|
else
|
||||||
|
newParagraph(`<image href="${href}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
||||||
|
if (inPara && this.showInlineImagesInCenter)
|
||||||
|
newParagraph(' ', 1);
|
||||||
|
} else {//external
|
||||||
|
dimPromises.push(getExternalImageDimensions(href));
|
||||||
|
newParagraph(`<image href="${href}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (path.indexOf('/fictionbook/body') == 0) {
|
if (path.indexOf('/fictionbook/body') == 0) {
|
||||||
if (tag == 'title') {
|
if (tag == 'title') {
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
@@ -117,12 +205,18 @@ export default class BookParser {
|
|||||||
center = true;
|
center = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag == 'section') {
|
||||||
|
newParagraph(' ', 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (tag == 'emphasis' || tag == 'strong') {
|
if (tag == 'emphasis' || tag == 'strong') {
|
||||||
growParagraph(`<${tag}>`, 0);
|
growParagraph(`<${tag}>`, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tag == 'p' || tag == 'empty-line' || tag == 'v')) {
|
if ((tag == 'p' || tag == 'empty-line' || tag == 'v')) {
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
|
if (tag == 'p')
|
||||||
|
inPara = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'subtitle') {
|
if (tag == 'subtitle') {
|
||||||
@@ -132,6 +226,7 @@ export default class BookParser {
|
|||||||
|
|
||||||
if (tag == 'epigraph') {
|
if (tag == 'epigraph') {
|
||||||
italic = true;
|
italic = true;
|
||||||
|
space += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'poem') {
|
if (tag == 'poem') {
|
||||||
@@ -139,13 +234,18 @@ export default class BookParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'text-author') {
|
if (tag == 'text-author') {
|
||||||
newParagraph(' <s> <s> <s> ', 4);
|
newParagraph(' ', 1);
|
||||||
|
space += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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 == 'binary') {
|
||||||
|
binaryId = '';
|
||||||
|
}
|
||||||
|
|
||||||
if (path.indexOf('/fictionbook/body') == 0) {
|
if (path.indexOf('/fictionbook/body') == 0) {
|
||||||
if (tag == 'title') {
|
if (tag == 'title') {
|
||||||
bold = false;
|
bold = false;
|
||||||
@@ -156,17 +256,26 @@ export default class BookParser {
|
|||||||
growParagraph(`</${tag}>`, 0);
|
growParagraph(`</${tag}>`, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag == 'p') {
|
||||||
|
inPara = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (tag == 'subtitle') {
|
if (tag == 'subtitle') {
|
||||||
bold = false;
|
bold = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'epigraph') {
|
if (tag == 'epigraph') {
|
||||||
italic = false;
|
italic = false;
|
||||||
|
space -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'stanza') {
|
if (tag == 'stanza') {
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag == 'text-author') {
|
||||||
|
space -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
path = path.substr(0, path.length - tag.length - 1);
|
path = path.substr(0, path.length - tag.length - 1);
|
||||||
@@ -228,7 +337,9 @@ 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 = (italic ? '</emphasis>' : '');
|
tOpen += (space ? `<space w="${space}">` : '');
|
||||||
|
let tClose = (space ? '</space>' : '');
|
||||||
|
tClose += (italic ? '</emphasis>' : '');
|
||||||
tClose += (bold ? '</strong>' : '');
|
tClose += (bold ? '</strong>' : '');
|
||||||
tClose += (center ? '</center>' : '');
|
tClose += (center ? '</center>' : '');
|
||||||
|
|
||||||
@@ -245,6 +356,10 @@ export default class BookParser {
|
|||||||
growParagraph(`${tOpen}${text}${tClose}`, text.length);
|
growParagraph(`${tOpen}${text}${tClose}`, text.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (binaryId) {
|
||||||
|
dimPromises.push(getImageDimensions(binaryId, binaryType, text));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onProgress = async(prog) => {
|
const onProgress = async(prog) => {
|
||||||
@@ -256,6 +371,14 @@ export default class BookParser {
|
|||||||
onStartNode, onEndNode, onTextNode, onProgress
|
onStartNode, onEndNode, onTextNode, onProgress
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (dimPromises.length) {
|
||||||
|
try {
|
||||||
|
await Promise.all(dimPromises);
|
||||||
|
} catch (e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.fb2 = fb2;
|
this.fb2 = fb2;
|
||||||
this.para = para;
|
this.para = para;
|
||||||
|
|
||||||
@@ -291,19 +414,22 @@ export default class BookParser {
|
|||||||
|
|
||||||
splitToStyle(s) {
|
splitToStyle(s) {
|
||||||
let result = [];/*array of {
|
let result = [];/*array of {
|
||||||
style: {bold: Boolean, italic: Boolean, center: Boolean},
|
style: {bold: Boolean, italic: Boolean, center: Boolean, space: Number},
|
||||||
|
image: {local: Boolean, inline: Boolean, id: String},
|
||||||
text: String,
|
text: String,
|
||||||
}*/
|
}*/
|
||||||
let style = {};
|
let style = {};
|
||||||
|
let image = {};
|
||||||
|
|
||||||
const onTextNode = async(text) => {// eslint-disable-line no-unused-vars
|
const onTextNode = async(text) => {// eslint-disable-line no-unused-vars
|
||||||
result.push({
|
result.push({
|
||||||
style: Object.assign({}, style),
|
style: Object.assign({}, style),
|
||||||
text: text
|
image,
|
||||||
|
text
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onStartNode = async(elemName) => {// eslint-disable-line no-unused-vars
|
const onStartNode = async(elemName, tail) => {// eslint-disable-line no-unused-vars
|
||||||
switch (elemName) {
|
switch (elemName) {
|
||||||
case 'strong':
|
case 'strong':
|
||||||
style.bold = true;
|
style.bold = true;
|
||||||
@@ -314,6 +440,42 @@ export default class BookParser {
|
|||||||
case 'center':
|
case 'center':
|
||||||
style.center = true;
|
style.center = true;
|
||||||
break;
|
break;
|
||||||
|
case 'space': {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
if (attrs.w && attrs.w.value)
|
||||||
|
style.space = attrs.w.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'image': {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
if (attrs.href && attrs.href.value) {
|
||||||
|
let id = attrs.href.value;
|
||||||
|
let local = false;
|
||||||
|
if (id[0] == '#') {
|
||||||
|
id = id.substr(1);
|
||||||
|
local = true;
|
||||||
|
}
|
||||||
|
image = {local, inline: false, id};
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'image-inline': {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
if (attrs.href && attrs.href.value) {
|
||||||
|
let id = attrs.href.value;
|
||||||
|
let local = false;
|
||||||
|
if (id[0] == '#') {
|
||||||
|
id = id.substr(1);
|
||||||
|
local = true;
|
||||||
|
}
|
||||||
|
result.push({
|
||||||
|
style: Object.assign({}, style),
|
||||||
|
image: {local, inline: true, id},
|
||||||
|
text: ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -328,6 +490,14 @@ export default class BookParser {
|
|||||||
case 'center':
|
case 'center':
|
||||||
style.center = false;
|
style.center = false;
|
||||||
break;
|
break;
|
||||||
|
case 'space':
|
||||||
|
style.space = 0;
|
||||||
|
break;
|
||||||
|
case 'image':
|
||||||
|
image = {};
|
||||||
|
break;
|
||||||
|
case 'image-inline':
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -335,27 +505,28 @@ export default class BookParser {
|
|||||||
onStartNode, onEndNode, onTextNode
|
onStartNode, onEndNode, onTextNode
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//длинные слова (или белиберду без пробелов) тоже разобьем
|
//длинные слова (или белиберду без пробелов) тоже разобьем
|
||||||
const maxWordLength = this.maxWordLength;
|
const maxWordLength = this.maxWordLength;
|
||||||
const parts = result;
|
const parts = result;
|
||||||
result = [];
|
result = [];
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
let p = part;
|
let p = part;
|
||||||
let i = 0;
|
if (!p.image.id) {
|
||||||
let spaceIndex = -1;
|
let i = 0;
|
||||||
while (i < p.text.length) {
|
let spaceIndex = -1;
|
||||||
if (p.text[i] == ' ')
|
while (i < p.text.length) {
|
||||||
spaceIndex = i;
|
if (p.text[i] == ' ')
|
||||||
|
spaceIndex = i;
|
||||||
|
|
||||||
if (i - spaceIndex >= maxWordLength && i < p.text.length - 1 &&
|
if (i - spaceIndex >= maxWordLength && i < p.text.length - 1 &&
|
||||||
this.measureText(p.text.substr(spaceIndex + 1, i - spaceIndex), p.style) >= this.w - this.p) {
|
this.measureText(p.text.substr(spaceIndex + 1, i - spaceIndex), p.style) >= this.w - this.p) {
|
||||||
result.push({style: p.style, text: p.text.substr(0, i + 1)});
|
result.push({style: p.style, image: p.image, text: p.text.substr(0, i + 1)});
|
||||||
p = {style: p.style, text: p.text.substr(i + 1)};
|
p = {style: p.style, image: p.image, text: p.text.substr(i + 1)};
|
||||||
spaceIndex = -1;
|
spaceIndex = -1;
|
||||||
i = -1;
|
i = -1;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
result.push(p);
|
result.push(p);
|
||||||
}
|
}
|
||||||
@@ -424,7 +595,9 @@ export default class BookParser {
|
|||||||
para.parsed.maxWordLength === this.maxWordLength &&
|
para.parsed.maxWordLength === this.maxWordLength &&
|
||||||
para.parsed.font === this.font &&
|
para.parsed.font === this.font &&
|
||||||
para.parsed.cutEmptyParagraphs === this.cutEmptyParagraphs &&
|
para.parsed.cutEmptyParagraphs === this.cutEmptyParagraphs &&
|
||||||
para.parsed.addEmptyParagraphs === this.addEmptyParagraphs
|
para.parsed.addEmptyParagraphs === this.addEmptyParagraphs &&
|
||||||
|
para.parsed.showImages === this.showImages &&
|
||||||
|
para.parsed.imageHeightLines === this.imageHeightLines
|
||||||
)
|
)
|
||||||
return para.parsed;
|
return para.parsed;
|
||||||
|
|
||||||
@@ -436,6 +609,8 @@ export default class BookParser {
|
|||||||
font: this.font,
|
font: this.font,
|
||||||
cutEmptyParagraphs: this.cutEmptyParagraphs,
|
cutEmptyParagraphs: this.cutEmptyParagraphs,
|
||||||
addEmptyParagraphs: this.addEmptyParagraphs,
|
addEmptyParagraphs: this.addEmptyParagraphs,
|
||||||
|
showImages: this.showImages,
|
||||||
|
imageHeightLines: this.imageHeightLines,
|
||||||
visible: !(
|
visible: !(
|
||||||
(this.cutEmptyParagraphs && para.cut) ||
|
(this.cutEmptyParagraphs && para.cut) ||
|
||||||
(para.addIndex > this.addEmptyParagraphs)
|
(para.addIndex > this.addEmptyParagraphs)
|
||||||
@@ -451,6 +626,7 @@ export default class BookParser {
|
|||||||
last: Boolean,
|
last: Boolean,
|
||||||
parts: array of {
|
parts: array of {
|
||||||
style: {bold: Boolean, italic: Boolean, center: Boolean},
|
style: {bold: Boolean, italic: Boolean, center: Boolean},
|
||||||
|
image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number},
|
||||||
text: String,
|
text: String,
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
@@ -461,16 +637,63 @@ export default class BookParser {
|
|||||||
|
|
||||||
let str = '';//измеряемая строка
|
let str = '';//измеряемая строка
|
||||||
let prevStr = '';//строка без крайнего слова
|
let prevStr = '';//строка без крайнего слова
|
||||||
let prevW = 0;
|
|
||||||
let j = 0;//номер строки
|
let j = 0;//номер строки
|
||||||
let style = {};
|
let style = {};
|
||||||
let ofs = 0;//смещение от начала параграфа para.offset
|
let ofs = 0;//смещение от начала параграфа para.offset
|
||||||
|
let imgW = 0;
|
||||||
|
|
||||||
// тут начинается самый замес, перенос по слогам и стилизация
|
// тут начинается самый замес, перенос по слогам и стилизация, а также изображения
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
const words = part.text.split(' ');
|
|
||||||
style = part.style;
|
style = part.style;
|
||||||
|
|
||||||
|
//изображения
|
||||||
|
if (part.image.id && !part.image.inline) {
|
||||||
|
parsed.visible = this.showImages;
|
||||||
|
let bin = this.binary[part.image.id];
|
||||||
|
if (!bin)
|
||||||
|
bin = {h: 0, w: 0};
|
||||||
|
|
||||||
|
let lineCount = this.imageHeightLines;
|
||||||
|
const c = Math.ceil(bin.h/this.lineHeight);
|
||||||
|
lineCount = (c < lineCount ? c : lineCount);
|
||||||
|
let i = 0;
|
||||||
|
for (; i < lineCount - 1; i++) {
|
||||||
|
line.end = para.offset + ofs;
|
||||||
|
line.first = (j == 0);
|
||||||
|
line.last = false;
|
||||||
|
line.parts.push({style, text: ' ', image: {
|
||||||
|
local: part.image.local,
|
||||||
|
inline: false,
|
||||||
|
id: part.image.id,
|
||||||
|
imageLine: i,
|
||||||
|
lineCount,
|
||||||
|
paraIndex
|
||||||
|
}});
|
||||||
|
lines.push(line);
|
||||||
|
line = {begin: line.end + 1, parts: []};
|
||||||
|
ofs++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
line.first = (j == 0);
|
||||||
|
line.last = true;
|
||||||
|
line.parts.push({style, text: ' ',
|
||||||
|
image: {local: part.image.local, inline: false, id: part.image.id, imageLine: i, lineCount, paraIndex}});
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (part.image.id && part.image.inline && this.showImages) {
|
||||||
|
const bin = this.binary[part.image.id];
|
||||||
|
if (bin) {
|
||||||
|
let imgH = (bin.h > this.fontSize ? this.fontSize : bin.h);
|
||||||
|
imgW += bin.w*imgH/bin.h;
|
||||||
|
line.parts.push({style, text: '',
|
||||||
|
image: {local: part.image.local, inline: true, id: part.image.id}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let words = part.text.split(' ');
|
||||||
|
|
||||||
let sp1 = '';
|
let sp1 = '';
|
||||||
let sp2 = '';
|
let sp2 = '';
|
||||||
for (let i = 0; i < words.length; i++) {
|
for (let i = 0; i < words.length; i++) {
|
||||||
@@ -482,7 +705,8 @@ export default class BookParser {
|
|||||||
|
|
||||||
str += sp1 + word;
|
str += sp1 + word;
|
||||||
|
|
||||||
let p = (j == 0 ? parsed.p : 0);
|
let p = (j == 0 ? parsed.p : 0) + imgW;
|
||||||
|
p = (style.space ? p + parsed.p*style.space : p);
|
||||||
let w = this.measureText(str, style) + p;
|
let w = this.measureText(str, style) + p;
|
||||||
let wordTail = word;
|
let wordTail = word;
|
||||||
if (w > parsed.w && prevStr != '') {
|
if (w > parsed.w && prevStr != '') {
|
||||||
@@ -508,7 +732,6 @@ export default class BookParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pw) {
|
if (pw) {
|
||||||
prevW = pw;
|
|
||||||
partText += ss + (ss[ss.length - 1] == '-' ? '' : '-');
|
partText += ss + (ss[ss.length - 1] == '-' ? '' : '-');
|
||||||
wordTail = slogi.join('');
|
wordTail = slogi.join('');
|
||||||
}
|
}
|
||||||
@@ -522,7 +745,6 @@ export default class BookParser {
|
|||||||
let t = line.parts[line.parts.length - 1].text;
|
let t = line.parts[line.parts.length - 1].text;
|
||||||
if (t[t.length - 1] == ' ') {
|
if (t[t.length - 1] == ' ') {
|
||||||
line.parts[line.parts.length - 1].text = t.trimRight();
|
line.parts[line.parts.length - 1].text = t.trimRight();
|
||||||
prevW -= this.measureText(' ', style);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -530,7 +752,6 @@ export default class BookParser {
|
|||||||
if (line.end - line.begin < 0)
|
if (line.end - line.begin < 0)
|
||||||
console.error(`Parse error, empty line in paragraph ${paraIndex}`);
|
console.error(`Parse error, empty line in paragraph ${paraIndex}`);
|
||||||
|
|
||||||
line.width = prevW;
|
|
||||||
line.first = (j == 0);
|
line.first = (j == 0);
|
||||||
line.last = false;
|
line.last = false;
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
@@ -539,6 +760,7 @@ export default class BookParser {
|
|||||||
partText = '';
|
partText = '';
|
||||||
sp2 = '';
|
sp2 = '';
|
||||||
str = wordTail;
|
str = wordTail;
|
||||||
|
imgW = 0;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,7 +768,6 @@ export default class BookParser {
|
|||||||
partText += sp2 + wordTail;
|
partText += sp2 + wordTail;
|
||||||
sp1 = ' ';
|
sp1 = ' ';
|
||||||
sp2 = ' ';
|
sp2 = ' ';
|
||||||
prevW = w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partText != '')
|
if (partText != '')
|
||||||
@@ -558,14 +779,12 @@ export default class BookParser {
|
|||||||
let t = line.parts[line.parts.length - 1].text;
|
let t = line.parts[line.parts.length - 1].text;
|
||||||
if (t[t.length - 1] == ' ') {
|
if (t[t.length - 1] == ' ') {
|
||||||
line.parts[line.parts.length - 1].text = t.trimRight();
|
line.parts[line.parts.length - 1].text = t.trimRight();
|
||||||
prevW -= this.measureText(' ', style);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
line.end = para.offset + para.length - 1;
|
line.end = para.offset + para.length - 1;
|
||||||
if (line.end - line.begin < 0)
|
if (line.end - line.begin < 0)
|
||||||
console.error(`Parse error, empty line in paragraph ${paraIndex}`);
|
console.error(`Parse error, empty line in paragraph ${paraIndex}`);
|
||||||
|
|
||||||
line.width = prevW;
|
|
||||||
line.first = (j == 0);
|
line.first = (j == 0);
|
||||||
line.last = true;
|
line.last = true;
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
|
|||||||
@@ -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.recentChanged1 = true;
|
this.recentChanged1 = true;
|
||||||
@@ -131,7 +132,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, {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import Vue from 'vue';
|
|
||||||
|
|
||||||
const fonts = [
|
const fonts = [
|
||||||
{name: 'ReaderDefault', label: 'По-умолчанию', fontVertShift: 0},
|
{name: 'ReaderDefault', label: 'По-умолчанию', fontVertShift: 0},
|
||||||
{name: 'GEO_1', label: 'BPG Arial', fontVertShift: 10},
|
{name: 'GEO_1', label: 'BPG Arial', fontVertShift: 10},
|
||||||
@@ -163,6 +161,9 @@ const settingDefaults = {
|
|||||||
cutEmptyParagraphs: false,
|
cutEmptyParagraphs: false,
|
||||||
addEmptyParagraphs: 0,
|
addEmptyParagraphs: 0,
|
||||||
blinkCachedLoad: true,
|
blinkCachedLoad: true,
|
||||||
|
showImages: true,
|
||||||
|
showInlineImagesInCenter: false,
|
||||||
|
imageHeightLines: 100,
|
||||||
|
|
||||||
fontShifts: {},
|
fontShifts: {},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
siteroot = 'http://omnireader.ru:11080/';
|
siteroot = 'http://old.omnireader.ru/';
|
||||||
doRedirect = '';
|
doRedirect = '';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
$siteroot = 'http://omnireader.ru:11080/';
|
$siteroot = 'http://old.omnireader.ru/';
|
||||||
$use_gzip = false;
|
$use_gzip = false;
|
||||||
$tmp_dir = '/tmp';
|
$tmp_dir = '/tmp';
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -156,7 +156,7 @@
|
|||||||
Ïîääåðæèâàåìûå ôîðìàòû: <strong>html, txt, fb2, fb2.zip</strong>
|
Ïîääåðæèâàåìûå ôîðìàòû: <strong>html, txt, fb2, fb2.zip</strong>
|
||||||
|
|
||||||
<br><br>Âû ìîæåòå äîáàâèòü â ñâîé áðàóçåð çàêëàäêó, óêàçàâ â åå ñâîéñòâàõ âìåñòî àäðåñà ñëåäóþùèé êîä:
|
<br><br>Âû ìîæåòå äîáàâèòü â ñâîé áðàóçåð çàêëàäêó, óêàçàâ â åå ñâîéñòâàõ âìåñòî àäðåñà ñëåäóþùèé êîä:
|
||||||
<br><p><strong>javascript:location.href='http://omnireader.ru:11080/?url='+location.href;</strong>
|
<br><p><strong>javascript:location.href='http://old.omnireader.ru/?url='+location.href;</strong>
|
||||||
<br>Òîãäà, íàæàâ íà ïîëó÷èâøóþñÿ êíîïêó íà ëþáîé ñòðàíèöå èíòåðíåòà, âû àâòîìàòè÷åñêè îòêðîåòå åå â Omni Reader.
|
<br>Òîãäà, íàæàâ íà ïîëó÷èâøóþñÿ êíîïêó íà ëþáîé ñòðàíèöå èíòåðíåòà, âû àâòîìàòè÷åñêè îòêðîåòå åå â Omni Reader.
|
||||||
|
|
||||||
<br><br>Äëÿ Chrome íà Android ìîæíî âûçûâàòü çàêëàäêó ïî åå èìåíè (èìÿ ñòîèò ñäåëàòü ïîïðîùå) â àäðåñíîé ñòðîêå áðàóçåðà, ïîñêîëüêó ñòàíäàðòíûé âûçîâ òàêîé çàêëàäêè íå ðàáîòàåò.
|
<br><br>Äëÿ Chrome íà Android ìîæíî âûçûâàòü çàêëàäêó ïî åå èìåíè (èìÿ ñòîèò ñäåëàòü ïîïðîùå) â àäðåñíîé ñòðîêå áðàóçåðà, ïîñêîëüêó ñòàíäàðòíûé âûçîâ òàêîé çàêëàäêè íå ðàáîòàåò.
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 11080;
|
listen 80;
|
||||||
server_name omnireader.ru;
|
server_name old.omnireader.ru;
|
||||||
|
|
||||||
client_max_body_size 50m;
|
client_max_body_size 50m;
|
||||||
|
|
||||||
|
|||||||
26
package-lock.json
generated
26
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.2.0",
|
"version": "0.3.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -3095,6 +3095,30 @@
|
|||||||
"strip-dirs": "^2.0.0"
|
"strip-dirs": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"decompress-bzip2": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/decompress-bzip2/-/decompress-bzip2-4.0.0.tgz",
|
||||||
|
"integrity": "sha1-0SVMlJ4F6vYol1QoawY/3Hz/AT8=",
|
||||||
|
"requires": {
|
||||||
|
"file-type": "^4.3.0",
|
||||||
|
"seek-bzip": "^1.0.5"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"file-type": {
|
||||||
|
"version": "4.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/file-type/-/file-type-4.4.0.tgz",
|
||||||
|
"integrity": "sha1-G2AOX8ofvcboDApwxxyNul95BsU="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"decompress-gz": {
|
||||||
|
"version": "0.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/decompress-gz/-/decompress-gz-0.0.1.tgz",
|
||||||
|
"integrity": "sha512-YMdCWdxHvPplsTbV1tvr2oFJOtAFNxqVMFnKWEmePBXl+LKG5z5bFrowzc12Jzd7O29nnzI/D1M95Asx0Qa1fg==",
|
||||||
|
"requires": {
|
||||||
|
"file-type": "^5.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"decompress-response": {
|
"decompress-response": {
|
||||||
"version": "3.3.0",
|
"version": "3.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.3.1",
|
"version": "0.4.2",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
},
|
},
|
||||||
@@ -60,6 +60,8 @@
|
|||||||
"chardet": "^0.7.0",
|
"chardet": "^0.7.0",
|
||||||
"compression": "^1.7.3",
|
"compression": "^1.7.3",
|
||||||
"decompress": "^4.2.0",
|
"decompress": "^4.2.0",
|
||||||
|
"decompress-bzip2": "^4.0.0",
|
||||||
|
"decompress-gz": "0.0.1",
|
||||||
"detect-file-type": "^0.2.0",
|
"detect-file-type": "^0.2.0",
|
||||||
"element-ui": "^2.4.11",
|
"element-ui": "^2.4.11",
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const textUtils = require('./textUtils');
|
|||||||
const FileDetector = require('../FileDetector');
|
const FileDetector = require('../FileDetector');
|
||||||
|
|
||||||
const repSpaces = (text) => text.replace(/ |[\t\n\r]/g, ' ');
|
const repSpaces = (text) => text.replace(/ |[\t\n\r]/g, ' ');
|
||||||
|
const repSpaces2 = (text) => text.replace(/[\n\r]/g, '');
|
||||||
|
|
||||||
class BookConverter {
|
class BookConverter {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -31,7 +32,7 @@ class BookConverter {
|
|||||||
if (parsedUrl.hostname == 'samlib.ru' ||
|
if (parsedUrl.hostname == 'samlib.ru' ||
|
||||||
parsedUrl.hostname == 'budclub.ru' ||
|
parsedUrl.hostname == 'budclub.ru' ||
|
||||||
parsedUrl.hostname == 'zhurnal.lib.ru') {
|
parsedUrl.hostname == 'zhurnal.lib.ru') {
|
||||||
await fs.writeFile(outputFile, this.convertSamlib(data));
|
await fs.writeFile(outputFile, this.convertSamlib(data, parsedUrl.hostname));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,18 +54,16 @@ class BookConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
decode(data) {
|
decode(data) {
|
||||||
const charsetAll = chardet.detectAll(data.slice(0, 20000));
|
let selected = textUtils.getEncoding(data);
|
||||||
|
|
||||||
let selected = 'ISO-8859-5';
|
|
||||||
for (const charset of charsetAll) {
|
|
||||||
if (charset.name.indexOf('ISO-8859') < 0) {
|
|
||||||
selected = charset.name;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selected == 'ISO-8859-5') {
|
if (selected == 'ISO-8859-5') {
|
||||||
selected = textUtils.getEncoding(data);
|
const charsetAll = chardet.detectAll(data.slice(0, 20000));
|
||||||
|
for (const charset of charsetAll) {
|
||||||
|
if (charset.name.indexOf('ISO-8859') < 0) {
|
||||||
|
selected = charset.name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return iconv.decode(data, selected);
|
return iconv.decode(data, selected);
|
||||||
@@ -218,7 +217,7 @@ class BookConverter {
|
|||||||
return this.formatFb2(fb2);
|
return this.formatFb2(fb2);
|
||||||
}
|
}
|
||||||
|
|
||||||
convertSamlib(data) {
|
convertSamlib(data, hostname) {
|
||||||
let titleInfo = {};
|
let titleInfo = {};
|
||||||
let desc = {_n: 'description', 'title-info': titleInfo};
|
let desc = {_n: 'description', 'title-info': titleInfo};
|
||||||
let pars = [];
|
let pars = [];
|
||||||
@@ -227,20 +226,22 @@ class BookConverter {
|
|||||||
|
|
||||||
let inSubtitle = false;
|
let inSubtitle = false;
|
||||||
let inJustify = true;
|
let inJustify = true;
|
||||||
|
let inImage = false;
|
||||||
let path = '';
|
let path = '';
|
||||||
let tag = '';// eslint-disable-line no-unused-vars
|
let tag = '';// eslint-disable-line no-unused-vars
|
||||||
|
|
||||||
let inText = false;
|
let inText = false;
|
||||||
|
let textFound = false;
|
||||||
let node = {_a: pars};
|
let node = {_a: pars};
|
||||||
|
|
||||||
let inPara = false;
|
let inPara = false;
|
||||||
let italic = false;
|
let italic = false;
|
||||||
let bold = false;
|
let bold = false;
|
||||||
|
|
||||||
const openTag = (name) => {
|
const openTag = (name, attrs) => {
|
||||||
if (name == 'p')
|
if (name == 'p')
|
||||||
inPara = true;
|
inPara = true;
|
||||||
let n = {_n: name, _a: [], _p: node};
|
let n = {_n: name, _attrs: attrs, _a: [], _p: node};
|
||||||
node._a.push(n);
|
node._a.push(n);
|
||||||
node = n;
|
node = n;
|
||||||
};
|
};
|
||||||
@@ -271,7 +272,7 @@ class BookConverter {
|
|||||||
path += '/' + elemName;
|
path += '/' + elemName;
|
||||||
tag = elemName;
|
tag = elemName;
|
||||||
} else {
|
} else {
|
||||||
if (inPara && elemName != 'i' && elemName != 'b')
|
if (inPara && elemName != 'i' && elemName != 'b' && elemName != 'em' && elemName != 'strong' && elemName != 'img')
|
||||||
closeTag('p');
|
closeTag('p');
|
||||||
|
|
||||||
switch (elemName) {
|
switch (elemName) {
|
||||||
@@ -281,12 +282,15 @@ class BookConverter {
|
|||||||
case 'h1':
|
case 'h1':
|
||||||
case 'h2':
|
case 'h2':
|
||||||
case 'h3':
|
case 'h3':
|
||||||
|
case 'br':
|
||||||
openTag('p');
|
openTag('p');
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
|
case 'em':
|
||||||
italic = true;
|
italic = true;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
|
case 'strong':
|
||||||
bold = true;
|
bold = true;
|
||||||
break;
|
break;
|
||||||
case 'div':
|
case 'div':
|
||||||
@@ -301,6 +305,17 @@ class BookConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
case 'img': {
|
||||||
|
const attrs = sax.getAttrsSync(tail);
|
||||||
|
if (attrs.src && attrs.src.value) {
|
||||||
|
let href = attrs.src.value;
|
||||||
|
if (href[0] == '/')
|
||||||
|
href = `http://${hostname}${href}`;
|
||||||
|
openTag('image', {href});
|
||||||
|
inImage = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -332,9 +347,11 @@ class BookConverter {
|
|||||||
closeTag('p');
|
closeTag('p');
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
|
case 'em':
|
||||||
italic = false;
|
italic = false;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
|
case 'strong':
|
||||||
bold = false;
|
bold = false;
|
||||||
break;
|
break;
|
||||||
case 'div':
|
case 'div':
|
||||||
@@ -348,13 +365,20 @@ class BookConverter {
|
|||||||
inJustify = false;
|
inJustify = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'img':
|
||||||
|
if (inImage)
|
||||||
|
closeTag('image');
|
||||||
|
inImage = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onComment = (text) => {// eslint-disable-line no-unused-vars
|
const onComment = (text) => {// eslint-disable-line no-unused-vars
|
||||||
if (text == '--------- Собственно произведение -------------')
|
if (text == '--------- Собственно произведение -------------') {
|
||||||
inText = true;
|
inText = true;
|
||||||
|
textFound = true;
|
||||||
|
}
|
||||||
if (text == '-----------------------------------------------')
|
if (text == '-----------------------------------------------')
|
||||||
inText = false;
|
inText = false;
|
||||||
};
|
};
|
||||||
@@ -392,11 +416,15 @@ class BookConverter {
|
|||||||
growParagraph(`${tOpen}${text}${tClose}`);
|
growParagraph(`${tOpen}${text}${tClose}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
sax.parseSync(repSpaces(this.decode(data).toString()), {
|
sax.parseSync(repSpaces(repSpaces2(this.decode(data).toString())), {
|
||||||
onStartNode, onEndNode, onTextNode, onComment,
|
onStartNode, onEndNode, onTextNode, onComment,
|
||||||
innerCut: new Set(['head', 'script', 'style'])
|
innerCut: new Set(['head', 'script', 'style'])
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//текст не найден на странице, обрабатываем как html
|
||||||
|
if (!textFound)
|
||||||
|
return this.convertHtml(data);
|
||||||
|
|
||||||
const title = (titleInfo['book-title'] ? titleInfo['book-title'] : '');
|
const title = (titleInfo['book-title'] ? titleInfo['book-title'] : '');
|
||||||
let author = '';
|
let author = '';
|
||||||
if (titleInfo.author) {
|
if (titleInfo.author) {
|
||||||
@@ -439,8 +467,15 @@ class BookConverter {
|
|||||||
if (node._n)
|
if (node._n)
|
||||||
name = node._n;
|
name = node._n;
|
||||||
|
|
||||||
|
let attrs = '';
|
||||||
|
if (node._attrs) {
|
||||||
|
for (let attrName in node._attrs) {
|
||||||
|
attrs += ` ${attrName}="${node._attrs[attrName]}"`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
out += `<${name}>`;
|
out += `<${name}${attrs}>`;
|
||||||
if (node.hasOwnProperty('_t'))
|
if (node.hasOwnProperty('_t'))
|
||||||
out += repSpaces(node._t);
|
out += repSpaces(node._t);
|
||||||
|
|
||||||
|
|||||||
@@ -276,7 +276,84 @@ async function parse(xstr, options) {
|
|||||||
await _onProgress(100);
|
await _onProgress(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAttrsSync(tail) {
|
||||||
|
let result = {};
|
||||||
|
let name = '';
|
||||||
|
let value = '';
|
||||||
|
let vOpen = '';
|
||||||
|
let inName = false;
|
||||||
|
let inValue = false;
|
||||||
|
let waitValue = false;
|
||||||
|
let waitEq = false;
|
||||||
|
|
||||||
|
const pushResult = () => {
|
||||||
|
if (name != '') {
|
||||||
|
let ns = '';
|
||||||
|
if (name.indexOf(':') >= 0) {
|
||||||
|
[ns, name] = name.split(':');
|
||||||
|
}
|
||||||
|
|
||||||
|
result[name] = {value, ns};
|
||||||
|
}
|
||||||
|
name = '';
|
||||||
|
value = '';
|
||||||
|
vOpen = '';
|
||||||
|
inName = false;
|
||||||
|
inValue = false;
|
||||||
|
waitValue = false;
|
||||||
|
waitEq = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
tail = tail.replace(/[\t\n\r]/g, ' ');
|
||||||
|
for (let i = 0; i < tail.length; i++) {
|
||||||
|
const c = tail.charAt(i);
|
||||||
|
if (c == ' ') {
|
||||||
|
if (inValue) {
|
||||||
|
if (vOpen == '"')
|
||||||
|
value += c;
|
||||||
|
else
|
||||||
|
pushResult();
|
||||||
|
} else if (inName) {
|
||||||
|
waitEq = true;
|
||||||
|
inName = false;
|
||||||
|
}
|
||||||
|
} else if (!inValue && c == '=') {
|
||||||
|
waitEq = false;
|
||||||
|
waitValue = true;
|
||||||
|
inName = false;
|
||||||
|
} else if (c == '"') {
|
||||||
|
if (inValue) {
|
||||||
|
pushResult();
|
||||||
|
} else if (waitValue) {
|
||||||
|
inValue = true;
|
||||||
|
vOpen = '"';
|
||||||
|
}
|
||||||
|
} else if (inValue) {
|
||||||
|
value += c;
|
||||||
|
} else if (inName) {
|
||||||
|
name += c;
|
||||||
|
} else if (waitEq) {
|
||||||
|
pushResult();
|
||||||
|
inName = true;
|
||||||
|
name = c;
|
||||||
|
} else if (waitValue) {
|
||||||
|
waitValue = false;
|
||||||
|
inValue = true;
|
||||||
|
vOpen = ' ';
|
||||||
|
value = c;
|
||||||
|
} else {
|
||||||
|
inName = true;
|
||||||
|
name = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (name != '')
|
||||||
|
pushResult();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
parseSync,
|
parseSync,
|
||||||
|
getAttrsSync,
|
||||||
parse
|
parse
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ function checkIfText(buf) {
|
|||||||
const crFreq = crCount/(buf.length + 1);
|
const crFreq = crCount/(buf.length + 1);
|
||||||
const lfFreq = lfCount/(buf.length + 1);
|
const lfFreq = lfCount/(buf.length + 1);
|
||||||
|
|
||||||
return (spaceFreq > 0.1 || crFreq > 0.03 || lfFreq > 0.03);
|
return (buf.length < 1000 || spaceFreq > 0.1 || crFreq > 0.03 || lfFreq > 0.03);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
const path = require('path');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const decompress = require('decompress');
|
const decompress = require('decompress');
|
||||||
|
const decompressGz = require('decompress-gz');
|
||||||
|
const decompressBzip2 = require('decompress-bzip2');
|
||||||
|
|
||||||
const FileDetector = require('./FileDetector');
|
const FileDetector = require('./FileDetector');
|
||||||
|
|
||||||
class FileDecompressor {
|
class FileDecompressor {
|
||||||
@@ -13,11 +17,33 @@ class FileDecompressor {
|
|||||||
async decompressFile(filename, outputDir) {
|
async decompressFile(filename, outputDir) {
|
||||||
const fileType = await this.detector.detectFile(filename);
|
const fileType = await this.detector.detectFile(filename);
|
||||||
|
|
||||||
if (!fileType || !(fileType.ext == 'zip' || fileType.ext == 'bz2'))
|
if (!fileType || !(fileType.ext == 'zip' || fileType.ext == 'bz2' || fileType.ext == 'gz'))
|
||||||
return filename;
|
return filename;
|
||||||
|
|
||||||
const files = await decompress(filename, outputDir);
|
//дурной decompress, поэтому в 2 этапа
|
||||||
|
//этап 1
|
||||||
|
let files = [];
|
||||||
|
try {
|
||||||
|
files = await decompress(filename, outputDir);
|
||||||
|
} catch (e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//этап 2
|
||||||
|
if (files.length == 0) {
|
||||||
|
try {
|
||||||
|
files = await decompress(filename, outputDir, {
|
||||||
|
inputFile: filename,
|
||||||
|
plugins: [
|
||||||
|
decompressGz(),
|
||||||
|
decompressBzip2({path: path.basename(filename)}),
|
||||||
|
]
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let result = filename;
|
let result = filename;
|
||||||
let max = 0;
|
let max = 0;
|
||||||
if (files.length) {
|
if (files.length) {
|
||||||
@@ -29,6 +55,9 @@ class FileDecompressor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//дурной decompress
|
||||||
|
if (result != filename)
|
||||||
|
await fs.chmod(result, 0o664);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,14 @@ class FileDownloader {
|
|||||||
|
|
||||||
async load(url, callback) {
|
async load(url, callback) {
|
||||||
let errMes = '';
|
let errMes = '';
|
||||||
|
const options = {
|
||||||
|
encoding: null,
|
||||||
|
headers: {
|
||||||
|
'user-agent': 'Mozilla/5.0 (X11; HasCodingOs 1.0; Linux x64) AppleWebKit/637.36 (KHTML, like Gecko) Chrome/70.0.3112.101 Safari/637.36 HasBrowser/5.0'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const response = await got(url, {method: 'HEAD'});
|
const response = await got(url, Object.assign({}, options, {method: 'HEAD'}));
|
||||||
|
|
||||||
let estSize = 0;
|
let estSize = 0;
|
||||||
if (response.headers['content-length']) {
|
if (response.headers['content-length']) {
|
||||||
@@ -17,7 +23,7 @@ class FileDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let prevProg = 0;
|
let prevProg = 0;
|
||||||
const request = got(url, {encoding: null}).on('downloadProgress', progress => {
|
const request = got(url, options).on('downloadProgress', progress => {
|
||||||
if (progress.transferred > maxDownloadSize) {
|
if (progress.transferred > maxDownloadSize) {
|
||||||
errMes = 'file too big';
|
errMes = 'file too big';
|
||||||
request.cancel();
|
request.cancel();
|
||||||
|
|||||||
Reference in New Issue
Block a user