Compare commits
53 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef12a84285 | ||
|
|
6a18ae3f27 | ||
|
|
a250e95950 | ||
|
|
b174ae452b | ||
|
|
0b63bce357 | ||
|
|
de0d10e792 | ||
|
|
b358b340b4 | ||
|
|
455aba7f4f | ||
|
|
fde0437157 | ||
|
|
480c95bd63 | ||
|
|
972f957685 | ||
|
|
40ff04e5dc | ||
|
|
b3c028bd7a | ||
|
|
51ec6a54fa | ||
|
|
7a29b16ee8 | ||
|
|
7af6fd8248 | ||
|
|
e1c93169b5 | ||
|
|
f4716d5a1e | ||
|
|
f5c06ce420 | ||
|
|
9492f85d80 | ||
|
|
b1303a3ba2 | ||
|
|
5c9cfe5e6f | ||
|
|
b89b5322b8 | ||
|
|
945feba6b2 | ||
|
|
c8af4b907b | ||
|
|
298e8928cf | ||
|
|
8cb67d2976 | ||
|
|
32b8382641 | ||
|
|
007e97463b | ||
|
|
e4f190698d | ||
|
|
b3be07b17e | ||
|
|
72f8977071 | ||
|
|
3dbf00344e | ||
|
|
ffdf0b12cd | ||
|
|
a51150c729 | ||
|
|
37e14b397c | ||
|
|
e48af7ee7d | ||
|
|
3eb3dd371a | ||
|
|
8ef6551560 | ||
|
|
b1f5f3dd28 | ||
|
|
6074c4b7bd | ||
|
|
9906dd43c7 | ||
|
|
17699f66f8 | ||
|
|
80a29e654d | ||
|
|
4184fda247 | ||
|
|
7460ff7055 | ||
|
|
3137b86cee | ||
|
|
b2ca84bb7e | ||
|
|
7d692dd730 | ||
|
|
8850a89aa7 | ||
|
|
57b01dd204 | ||
|
|
8aa1da36b6 | ||
|
|
2dbe29d632 |
@@ -2,7 +2,7 @@
|
|||||||
<div class="fit row">
|
<div class="fit row">
|
||||||
<Notify ref="notify"/>
|
<Notify ref="notify"/>
|
||||||
<StdDialog ref="stdDialog"/>
|
<StdDialog ref="stdDialog"/>
|
||||||
<keep-alive>
|
<keep-alive v-if="showPage">
|
||||||
<router-view class="col"></router-view>
|
<router-view class="col"></router-view>
|
||||||
</keep-alive>
|
</keep-alive>
|
||||||
</div>
|
</div>
|
||||||
@@ -12,8 +12,11 @@
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import Component from 'vue-class-component';
|
import Component from 'vue-class-component';
|
||||||
|
|
||||||
import Notify from './share/Notify.vue';
|
import Notify from './share/Notify.vue';
|
||||||
import StdDialog from './share/StdDialog.vue';
|
import StdDialog from './share/StdDialog.vue';
|
||||||
|
|
||||||
|
import miscApi from '../api/misc';
|
||||||
import * as utils from '../share/utils';
|
import * as utils from '../share/utils';
|
||||||
|
|
||||||
export default @Component({
|
export default @Component({
|
||||||
@@ -30,6 +33,8 @@ export default @Component({
|
|||||||
|
|
||||||
})
|
})
|
||||||
class App extends Vue {
|
class App extends Vue {
|
||||||
|
showPage = false;
|
||||||
|
|
||||||
itemRuText = {
|
itemRuText = {
|
||||||
'/cardindex': 'Картотека',
|
'/cardindex': 'Картотека',
|
||||||
'/reader': 'Читалка',
|
'/reader': 'Читалка',
|
||||||
@@ -42,7 +47,6 @@ class App extends Vue {
|
|||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.commit = this.$store.commit;
|
this.commit = this.$store.commit;
|
||||||
this.dispatch = this.$store.dispatch;
|
|
||||||
this.state = this.$store.state;
|
this.state = this.$store.state;
|
||||||
this.uistate = this.$store.state.uistate;
|
this.uistate = this.$store.state.uistate;
|
||||||
this.config = this.$store.state.config;
|
this.config = this.$store.state.config;
|
||||||
@@ -116,18 +120,24 @@ class App extends Vue {
|
|||||||
this.$root.notify = this.$refs.notify;
|
this.$root.notify = this.$refs.notify;
|
||||||
this.$root.stdDialog = this.$refs.stdDialog;
|
this.$root.stdDialog = this.$refs.stdDialog;
|
||||||
|
|
||||||
this.dispatch('config/loadConfig');
|
|
||||||
this.$watch('apiError', function(newError) {
|
|
||||||
if (newError) {
|
|
||||||
let mes = newError.message;
|
|
||||||
if (newError.response && newError.response.config)
|
|
||||||
mes = newError.response.config.url + '<br>' + newError.response.statusText;
|
|
||||||
this.$root.notify.error(mes, 'Ошибка API');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setAppTitle();
|
this.setAppTitle();
|
||||||
(async() => {
|
(async() => {
|
||||||
|
//загрузим конфиг сревера
|
||||||
|
try {
|
||||||
|
const config = await miscApi.loadConfig();
|
||||||
|
this.commit('config/setConfig', config);
|
||||||
|
this.showPage = true;
|
||||||
|
} catch(e) {
|
||||||
|
//проверим, не получен ли конфиг ранее
|
||||||
|
if (!this.mode) {
|
||||||
|
this.$root.notify.error(e.message, 'Ошибка API');
|
||||||
|
} else {
|
||||||
|
//вероятно, работаем в оффлайне
|
||||||
|
this.showPage = true;
|
||||||
|
}
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
//запросим persistent storage
|
//запросим persistent storage
|
||||||
if (navigator.storage && navigator.storage.persist) {
|
if (navigator.storage && navigator.storage.persist) {
|
||||||
navigator.storage.persist();
|
navigator.storage.persist();
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
class="no-mp bg-grey-4 text-grey-7"
|
class="no-mp bg-grey-4 text-grey-7"
|
||||||
>
|
>
|
||||||
<q-tab name="contents" icon="la la-list" label="Оглавление" />
|
<q-tab name="contents" icon="la la-list" label="Оглавление" />
|
||||||
|
<q-tab name="images" icon="la la-image" label="Изображения" />
|
||||||
<q-tab name="bookmarks" icon="la la-bookmark" label="Закладки" />
|
<q-tab name="bookmarks" icon="la la-bookmark" label="Закладки" />
|
||||||
</q-tabs>
|
</q-tabs>
|
||||||
</div>
|
</div>
|
||||||
@@ -25,7 +26,7 @@
|
|||||||
<div class="tab-panel" v-show="selectedTab == 'contents'">
|
<div class="tab-panel" v-show="selectedTab == 'contents'">
|
||||||
<div>
|
<div>
|
||||||
<div v-for="item in contents" :key="item.key" class="column" style="width: 540px">
|
<div v-for="item in contents" :key="item.key" class="column" style="width: 540px">
|
||||||
<div class="row item q-px-sm no-wrap">
|
<div class="row q-px-sm no-wrap" :class="{'item': !item.isBookPos, 'item-book-pos': item.isBookPos}">
|
||||||
<div v-if="item.list.length" class="row justify-center items-center expand-button clickable" @click="expandClick(item.key)">
|
<div v-if="item.list.length" class="row justify-center items-center expand-button clickable" @click="expandClick(item.key)">
|
||||||
<q-icon name="la la-caret-right" class="icon" :class="{'expanded-icon': item.expanded}" color="green-8" size="20px"/>
|
<q-icon name="la la-caret-right" class="icon" :class="{'expanded-icon': item.expanded}" color="green-8" size="20px"/>
|
||||||
</div>
|
</div>
|
||||||
@@ -40,7 +41,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="item.expanded" :ref="`subitem${item.key}`" class="subitems-transition">
|
<div v-if="item.expanded" :ref="`subitem${item.key}`" class="subitems-transition">
|
||||||
<div v-for="subitem in item.list" :key="subitem.key" class="row subitem q-px-sm no-wrap">
|
<div v-for="subitem in item.list" :key="subitem.key" class="row q-px-sm no-wrap" :class="{'subitem': !subitem.isBookPos, 'subitem-book-pos': subitem.isBookPos}">
|
||||||
<div class="col row clickable" @click="setBookPos(subitem.offset)">
|
<div class="col row clickable" @click="setBookPos(subitem.offset)">
|
||||||
<div class="no-expand-button"></div>
|
<div class="no-expand-button"></div>
|
||||||
<div :style="subitem.indentStyle"></div>
|
<div :style="subitem.indentStyle"></div>
|
||||||
@@ -56,6 +57,33 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-panel" v-show="selectedTab == 'images'">
|
||||||
|
<div>
|
||||||
|
<div v-for="item in images" :key="item.key" class="column" style="width: 540px">
|
||||||
|
<div class="row q-px-sm no-wrap" :class="{'item': !item.isBookPos, 'item-book-pos': item.isBookPos}">
|
||||||
|
<div class="col row clickable" @click="setBookPos(item.offset)">
|
||||||
|
<div class="image-thumb-box row justify-center items-center">
|
||||||
|
<div v-show="!imageLoaded[item.id]" class="image-thumb column justify-center"><i class="loading-img-icon la la-images"></i></div>
|
||||||
|
<img v-show="imageLoaded[item.id]" class="image-thumb" :src="imageSrc[item.id]"/>
|
||||||
|
</div>
|
||||||
|
<div class="no-expand-button column justify-center items-center">
|
||||||
|
<div class="image-num">{{ item.num }}</div>
|
||||||
|
<div v-show="item.type == 'image/jpeg'" class="image-type it-jpg-color row justify-center">JPG</div>
|
||||||
|
<div v-show="item.type == 'image/png'" class="image-type it-png-color row justify-center">PNG</div>
|
||||||
|
<div v-show="!item.local" class="image-type it-net-color row justify-center">INET</div>
|
||||||
|
</div>
|
||||||
|
<div :style="item.indentStyle"></div>
|
||||||
|
<div class="q-mr-sm col overflow-hidden column justify-center" :style="item.labelStyle" v-html="item.label"></div>
|
||||||
|
<div class="column justify-center">{{ item.perc }}%</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="!images.length" class="column justify-center items-center" style="height: 100px">
|
||||||
|
Изображения отсутствуют
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="tab-panel" v-show="selectedTab == 'bookmarks'">
|
<div class="tab-panel" v-show="selectedTab == 'bookmarks'">
|
||||||
<div class="column justify-center items-center" style="height: 100px">
|
<div class="column justify-center items-center" style="height: 100px">
|
||||||
Раздел находится в разработке
|
Раздел находится в разработке
|
||||||
@@ -74,16 +102,29 @@ import Component from 'vue-class-component';
|
|||||||
import Window from '../../share/Window.vue';
|
import Window from '../../share/Window.vue';
|
||||||
import * as utils from '../../../share/utils';
|
import * as utils from '../../../share/utils';
|
||||||
|
|
||||||
|
const ContentsPageProps = Vue.extend({
|
||||||
|
props: {
|
||||||
|
bookPos: Number,
|
||||||
|
isVisible: Boolean,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default @Component({
|
export default @Component({
|
||||||
components: {
|
components: {
|
||||||
Window,
|
Window,
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
bookPos: function() {
|
||||||
|
this.updateBookPosSelection();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
class ContentsPage extends Vue {
|
class ContentsPage extends ContentsPageProps {
|
||||||
selectedTab = 'contents';
|
selectedTab = 'contents';
|
||||||
contents = [];
|
contents = [];
|
||||||
|
images = [];
|
||||||
|
imageSrc = [];
|
||||||
|
imageLoaded = [];
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
}
|
}
|
||||||
@@ -93,16 +134,21 @@ class ContentsPage extends Vue {
|
|||||||
|
|
||||||
//закладки
|
//закладки
|
||||||
|
|
||||||
//далее формаирование оглавления
|
//проверим, надо ли обновлять списки
|
||||||
if (this.parsed == parsed)
|
if (this.parsed == parsed) {
|
||||||
|
this.updateBookPosSelection();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//далее формирование оглавления
|
||||||
this.parsed = parsed;
|
this.parsed = parsed;
|
||||||
this.contents = [];
|
this.contents = [];
|
||||||
await this.$nextTick();
|
await this.$nextTick();
|
||||||
|
|
||||||
const pc = parsed.contents;
|
const pc = parsed.contents;
|
||||||
|
const ims = parsed.images;
|
||||||
const newpc = [];
|
const newpc = [];
|
||||||
|
if (pc.length) {//если есть оглавление
|
||||||
//преобразуем все, кроме первого, разделы body в title-subtitle
|
//преобразуем все, кроме первого, разделы body в title-subtitle
|
||||||
let curSubtitles = [];
|
let curSubtitles = [];
|
||||||
let prevBodyIndex = -1;
|
let prevBodyIndex = -1;
|
||||||
@@ -123,6 +169,15 @@ class ContentsPage extends Vue {
|
|||||||
newpc.push(cont);
|
newpc.push(cont);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {//попробуем вытащить из images
|
||||||
|
for (let i = 0; i < ims.length; i++) {
|
||||||
|
const image = ims[i];
|
||||||
|
|
||||||
|
if (image.alt) {
|
||||||
|
newpc.push({paraIndex: image.paraIndex, title: image.alt, inset: 1, bodyIndex: 0, subtitles: []});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const prepareLabel = (title, bolder = false) => {
|
const prepareLabel = (title, bolder = false) => {
|
||||||
let titleParts = title.split('<p>');
|
let titleParts = title.split('<p>');
|
||||||
@@ -166,6 +221,90 @@ class ContentsPage extends Vue {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.contents = newContents;
|
this.contents = newContents;
|
||||||
|
|
||||||
|
//формируем newImages
|
||||||
|
const newImages = [];
|
||||||
|
for (i = 0; i < ims.length; i++) {
|
||||||
|
const image = ims[i];
|
||||||
|
const bin = parsed.binary[image.id];
|
||||||
|
const type = (bin ? bin.type : '');
|
||||||
|
|
||||||
|
const label = (image.alt ? image.alt : '<span style="font-size: 90%; color: #dddddd"><i>Без названия</i></span>');
|
||||||
|
const indentStyle = getIndentStyle(1);
|
||||||
|
const labelStyle = getLabelStyle(1);
|
||||||
|
|
||||||
|
const p = parsed.para[image.paraIndex];
|
||||||
|
newImages.push({perc: (p.offset/parsed.textLength*100).toFixed(0), label, key: i, offset: p.offset,
|
||||||
|
indentStyle, labelStyle, type, num: image.num, id: image.id, local: image.local});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.images = newImages;
|
||||||
|
|
||||||
|
if (this.selectedTab == 'contents' && !this.contents.length && this.images.length)
|
||||||
|
this.selectedTab = 'images';
|
||||||
|
|
||||||
|
//выделим на bookPos
|
||||||
|
this.updateBookPosSelection();
|
||||||
|
|
||||||
|
//асинхронная загрузка изображений
|
||||||
|
this.imageSrc = [];
|
||||||
|
this.imageLoaded = [];
|
||||||
|
await utils.sleep(50);
|
||||||
|
(async() => {
|
||||||
|
for (i = 0; i < ims.length; i++) {
|
||||||
|
const {id, local} = ims[i];
|
||||||
|
const bin = this.parsed.binary[id];
|
||||||
|
if (local)
|
||||||
|
this.$set(this.imageSrc, id, (bin ? `data:${bin.type};base64,${bin.data}` : ''));
|
||||||
|
else
|
||||||
|
this.$set(this.imageSrc, id, id);
|
||||||
|
this.imageLoaded[id] = true;
|
||||||
|
await utils.sleep(5);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateBookPosSelection() {
|
||||||
|
if (!this.isVisible)
|
||||||
|
return;
|
||||||
|
|
||||||
|
await utils.sleep(50);
|
||||||
|
const bp = this.bookPos;
|
||||||
|
|
||||||
|
for (let i = 0; i < this.contents.length; i++) {
|
||||||
|
const item = this.contents[i];
|
||||||
|
const nextOffset = (i < this.contents.length - 1 ? this.contents[i + 1].offset : this.parsed.textLength);
|
||||||
|
|
||||||
|
for (let j = 0; j < item.list.length; j++) {
|
||||||
|
const subitem = item.list[j];
|
||||||
|
const nextSubOffset = (j < item.list.length - 1 ? item.list[j + 1].offset : nextOffset);
|
||||||
|
|
||||||
|
if (bp >= subitem.offset && bp < nextSubOffset) {
|
||||||
|
subitem.isBookPos = true;
|
||||||
|
this.$set(this.contents, i, Object.assign(item, {list: item.list}));
|
||||||
|
} else if (subitem.isBookPos) {
|
||||||
|
subitem.isBookPos = false;
|
||||||
|
this.$set(this.contents, i, Object.assign(item, {list: item.list}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bp >= item.offset && bp < nextOffset) {
|
||||||
|
this.$set(this.contents, i, Object.assign(item, {isBookPos: true}));
|
||||||
|
} else if (item.isBookPos) {
|
||||||
|
this.$set(this.contents, i, Object.assign(item, {isBookPos: false}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < this.images.length; i++) {
|
||||||
|
const img = this.images[i];
|
||||||
|
const nextOffset = (i < this.images.length - 1 ? this.images[i + 1].offset : this.parsed.textLength);
|
||||||
|
|
||||||
|
if (bp >= img.offset && bp < nextOffset) {
|
||||||
|
this.$set(this.images, i, Object.assign(img, {isBookPos: true}));
|
||||||
|
} else if (img.isBookPos) {
|
||||||
|
this.$set(this.images, i, Object.assign(img, {isBookPos: false}));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async expandClick(key) {
|
async expandClick(key) {
|
||||||
@@ -219,7 +358,7 @@ class ContentsPage extends Vue {
|
|||||||
padding: 10px 0 10px 0;
|
padding: 10px 0 10px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item, .subitem {
|
.item, .subitem, .item-book-pos, .subitem-book-pos {
|
||||||
border-bottom: 1px solid #e0e0e0;
|
border-bottom: 1px solid #e0e0e0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,6 +366,22 @@ class ContentsPage extends Vue {
|
|||||||
background-color: #f0f0f0;
|
background-color: #f0f0f0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item-book-pos {
|
||||||
|
background-color: #b0f0b0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subitem-book-pos {
|
||||||
|
background-color: #d0f5d0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-book-pos:hover {
|
||||||
|
background-color: #b0e0b0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subitem-book-pos:hover {
|
||||||
|
background-color: #d0f0d0;
|
||||||
|
}
|
||||||
|
|
||||||
.expand-button, .no-expand-button {
|
.expand-button, .no-expand-button {
|
||||||
width: 40px;
|
width: 40px;
|
||||||
}
|
}
|
||||||
@@ -244,4 +399,38 @@ class ContentsPage extends Vue {
|
|||||||
.expanded-icon {
|
.expanded-icon {
|
||||||
transform: rotate(90deg);
|
transform: rotate(90deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.image-num {
|
||||||
|
font-size: 120%;
|
||||||
|
padding-bottom: 3px;
|
||||||
|
}
|
||||||
|
.image-type {
|
||||||
|
border: 1px solid black;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 80%;
|
||||||
|
padding: 2px 0 2px 0;
|
||||||
|
width: 34px;
|
||||||
|
}
|
||||||
|
.it-jpg-color {
|
||||||
|
background: linear-gradient(to right, #fabc3d, #ffec6d);
|
||||||
|
}
|
||||||
|
.it-png-color {
|
||||||
|
background: linear-gradient(to right, #4bc4e5, #6bf4ff);
|
||||||
|
}
|
||||||
|
.it-net-color {
|
||||||
|
background: linear-gradient(to right, #00c400, #00f400);
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-thumb-box {
|
||||||
|
width: 120px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-thumb {
|
||||||
|
height: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-img-icon {
|
||||||
|
font-size: 250%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -39,9 +39,9 @@
|
|||||||
<q-icon name="la la-copy" size="32px"/>
|
<q-icon name="la la-copy" size="32px"/>
|
||||||
<q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">{{ rstore.readerActions['copyText'] }}</q-tooltip>
|
<q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">{{ rstore.readerActions['copyText'] }}</q-tooltip>
|
||||||
</button>
|
</button>
|
||||||
<button ref="splitToPara" v-show="showToolButton['splitToPara']" class="tool-button" :class="buttonActiveClass('splitToPara')" @click="buttonClick('splitToPara')" v-ripple>
|
<button ref="convOptions" v-show="showToolButton['convOptions']" class="tool-button" :class="buttonActiveClass('convOptions')" @click="buttonClick('convOptions')" v-ripple>
|
||||||
<q-icon name="la la-retweet" size="32px"/>
|
<q-icon name="la la-magic" size="32px"/>
|
||||||
<q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">{{ rstore.readerActions['splitToPara'] }}</q-tooltip>
|
<q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">{{ rstore.readerActions['convOptions'] }}</q-tooltip>
|
||||||
</button>
|
</button>
|
||||||
<button ref="refresh" v-show="showToolButton['refresh']" class="tool-button" :class="buttonActiveClass('refresh')" @click="buttonClick('refresh')" v-ripple>
|
<button ref="refresh" v-show="showToolButton['refresh']" class="tool-button" :class="buttonActiveClass('refresh')" @click="buttonClick('refresh')" v-ripple>
|
||||||
<q-icon name="la la-sync" size="32px" :class="{clear: !showRefreshIcon}"/>
|
<q-icon name="la la-sync" size="32px" :class="{clear: !showRefreshIcon}"/>
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
<HelpPage v-if="helpActive" ref="helpPage" @do-action="doAction"></HelpPage>
|
<HelpPage v-if="helpActive" ref="helpPage" @do-action="doAction"></HelpPage>
|
||||||
<ClickMapPage v-show="clickMapActive" ref="clickMapPage"></ClickMapPage>
|
<ClickMapPage v-show="clickMapActive" ref="clickMapPage"></ClickMapPage>
|
||||||
<ServerStorage v-show="hidden" ref="serverStorage"></ServerStorage>
|
<ServerStorage v-show="hidden" ref="serverStorage"></ServerStorage>
|
||||||
<ContentsPage v-show="contentsActive" ref="contentsPage" @do-action="doAction" @book-pos-changed="bookPosChanged"></ContentsPage>
|
<ContentsPage v-show="contentsActive" ref="contentsPage" :book-pos="bookPos" :is-visible="contentsActive" @do-action="doAction" @book-pos-changed="bookPosChanged"></ContentsPage>
|
||||||
|
|
||||||
<ReaderDialogs ref="dialogs" @donate-toggle="donateToggle" @version-history-toggle="versionHistoryToggle"></ReaderDialogs>
|
<ReaderDialogs ref="dialogs" @donate-toggle="donateToggle" @version-history-toggle="versionHistoryToggle"></ReaderDialogs>
|
||||||
</div>
|
</div>
|
||||||
@@ -133,6 +133,9 @@ import ReaderDialogs from './ReaderDialogs/ReaderDialogs.vue';
|
|||||||
import bookManager from './share/bookManager';
|
import bookManager from './share/bookManager';
|
||||||
import rstore from '../../store/modules/reader';
|
import rstore from '../../store/modules/reader';
|
||||||
import readerApi from '../../api/reader';
|
import readerApi from '../../api/reader';
|
||||||
|
import miscApi from '../../api/misc';
|
||||||
|
|
||||||
|
import {versionHistory} from './versionHistory';
|
||||||
import * as utils from '../../share/utils';
|
import * as utils from '../../share/utils';
|
||||||
|
|
||||||
export default @Component({
|
export default @Component({
|
||||||
@@ -229,7 +232,6 @@ class Reader extends Vue {
|
|||||||
this.rstore = rstore;
|
this.rstore = rstore;
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.commit = this.$store.commit;
|
this.commit = this.$store.commit;
|
||||||
this.dispatch = this.$store.dispatch;
|
|
||||||
this.reader = this.$store.state.reader;
|
this.reader = this.$store.state.reader;
|
||||||
this.config = this.$store.state.config;
|
this.config = this.$store.state.config;
|
||||||
|
|
||||||
@@ -293,6 +295,16 @@ class Reader extends Vue {
|
|||||||
|
|
||||||
await this.$refs.dialogs.init();
|
await this.$refs.dialogs.init();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
(async() => {
|
||||||
|
this.isFirstNeedUpdateNotify = true;
|
||||||
|
//вечный цикл, запрашиваем периодически конфиг для проверки выхода новой версии читалки
|
||||||
|
while (true) {// eslint-disable-line no-constant-condition
|
||||||
|
await this.checkNewVersionAvailable();
|
||||||
|
await utils.sleep(3600*1000); //каждый час
|
||||||
|
}
|
||||||
|
//дальше кода нет
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadSettings() {
|
loadSettings() {
|
||||||
@@ -304,6 +316,11 @@ class Reader extends Vue {
|
|||||||
this.blinkCachedLoad = settings.blinkCachedLoad;
|
this.blinkCachedLoad = settings.blinkCachedLoad;
|
||||||
this.showToolButton = settings.showToolButton;
|
this.showToolButton = settings.showToolButton;
|
||||||
this.enableSitesFilter = settings.enableSitesFilter;
|
this.enableSitesFilter = settings.enableSitesFilter;
|
||||||
|
this.showNeedUpdateNotify = settings.showNeedUpdateNotify;
|
||||||
|
this.splitToPara = settings.splitToPara;
|
||||||
|
this.djvuQuality = settings.djvuQuality;
|
||||||
|
this.pdfAsText = settings.pdfAsText;
|
||||||
|
this.pdfQuality = settings.pdfQuality;
|
||||||
|
|
||||||
this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
|
this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
|
||||||
this.$root.readerActionByKeyEvent = (event) => {
|
this.$root.readerActionByKeyEvent = (event) => {
|
||||||
@@ -313,6 +330,30 @@ class Reader extends Vue {
|
|||||||
this.updateHeaderMinWidth();
|
this.updateHeaderMinWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async checkNewVersionAvailable() {
|
||||||
|
if (!this.checkingNewVersion && this.showNeedUpdateNotify) {
|
||||||
|
this.checkingNewVersion = true;
|
||||||
|
try {
|
||||||
|
await utils.sleep(15*1000); //подождем 15 секунд, чтобы прогрузился ServiceWorker при выходе новой версии
|
||||||
|
const config = await miscApi.loadConfig();
|
||||||
|
this.commit('config/setConfig', config);
|
||||||
|
|
||||||
|
let againMes = '';
|
||||||
|
if (this.isFirstNeedUpdateNotify) {
|
||||||
|
againMes = ' еще один раз';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.version != this.clientVersion)
|
||||||
|
this.$root.notify.info(`Вышла новая версия (v${this.version}) читалки.<br>Пожалуйста, обновите страницу${againMes}.`, 'Обновление');
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
this.checkingNewVersion = false;
|
||||||
|
}
|
||||||
|
this.isFirstNeedUpdateNotify = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateHeaderMinWidth() {
|
updateHeaderMinWidth() {
|
||||||
const showButtonCount = Object.values(this.showToolButton).reduce((a, b) => a + (b ? 1 : 0), 0);
|
const showButtonCount = Object.values(this.showToolButton).reduce((a, b) => a + (b ? 1 : 0), 0);
|
||||||
if (this.$refs.buttons)
|
if (this.$refs.buttons)
|
||||||
@@ -394,6 +435,16 @@ class Reader extends Vue {
|
|||||||
return this.$store.state.config.mode;
|
return this.$store.state.config.mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get version() {
|
||||||
|
return this.$store.state.config.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
get clientVersion() {
|
||||||
|
let v = versionHistory[0].header;
|
||||||
|
v = v.split(' ')[0];
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
get routeParamUrl() {
|
get routeParamUrl() {
|
||||||
let result = '';
|
let result = '';
|
||||||
const path = this.$route.fullPath;
|
const path = this.$route.fullPath;
|
||||||
@@ -656,6 +707,12 @@ class Reader extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convOptionsToggle() {
|
||||||
|
this.settingsToggle();
|
||||||
|
if (this.settingsActive)
|
||||||
|
this.$refs.settingsPage.selectedTab = 'convert';
|
||||||
|
}
|
||||||
|
|
||||||
helpToggle() {
|
helpToggle() {
|
||||||
this.helpActive = !this.helpActive;
|
this.helpActive = !this.helpActive;
|
||||||
if (this.helpActive) {
|
if (this.helpActive) {
|
||||||
@@ -682,16 +739,10 @@ class Reader extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshBook(mode) {
|
refreshBook() {
|
||||||
const mrb = this.mostRecentBook();
|
const mrb = this.mostRecentBook();
|
||||||
if (mrb) {
|
|
||||||
if (mode && mode == 'split') {
|
|
||||||
this.loadBook({url: mrb.url, uploadFileName: mrb.uploadFileName, skipCheck: true, isText: true, force: true});
|
|
||||||
} else {
|
|
||||||
this.loadBook({url: mrb.url, uploadFileName: mrb.uploadFileName, force: true});
|
this.loadBook({url: mrb.url, uploadFileName: mrb.uploadFileName, force: true});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
undoAction() {
|
undoAction() {
|
||||||
if (this.actionCur > 0) {
|
if (this.actionCur > 0) {
|
||||||
@@ -730,7 +781,7 @@ class Reader extends Vue {
|
|||||||
case 'scrolling':
|
case 'scrolling':
|
||||||
case 'search':
|
case 'search':
|
||||||
case 'copyText':
|
case 'copyText':
|
||||||
case 'splitToPara':
|
case 'convOptions':
|
||||||
case 'refresh':
|
case 'refresh':
|
||||||
case 'contents':
|
case 'contents':
|
||||||
case 'libs':
|
case 'libs':
|
||||||
@@ -764,7 +815,6 @@ class Reader extends Vue {
|
|||||||
case 'contents':
|
case 'contents':
|
||||||
classResult = classDisabled;
|
classResult = classDisabled;
|
||||||
break;
|
break;
|
||||||
case 'splitToPara':
|
|
||||||
case 'refresh':
|
case 'refresh':
|
||||||
case 'recentBooks':
|
case 'recentBooks':
|
||||||
if (!this.mostRecentBookReactive)
|
if (!this.mostRecentBookReactive)
|
||||||
@@ -926,10 +976,13 @@ class Reader extends Vue {
|
|||||||
if (!book) {
|
if (!book) {
|
||||||
book = await readerApi.loadBook({
|
book = await readerApi.loadBook({
|
||||||
url,
|
url,
|
||||||
skipCheck: (opts.skipCheck ? true : false),
|
uploadFileName,
|
||||||
isText: (opts.isText ? true : false),
|
|
||||||
enableSitesFilter: this.enableSitesFilter,
|
enableSitesFilter: this.enableSitesFilter,
|
||||||
uploadFileName
|
skipHtmlCheck: (this.splitToPara ? true : false),
|
||||||
|
isText: (this.splitToPara ? true : false),
|
||||||
|
djvuQuality: this.djvuQuality,
|
||||||
|
pdfAsText: this.pdfAsText,
|
||||||
|
pdfQuality: this.pdfQuality,
|
||||||
},
|
},
|
||||||
(state) => {
|
(state) => {
|
||||||
progress.setState(state);
|
progress.setState(state);
|
||||||
@@ -963,6 +1016,8 @@ class Reader extends Vue {
|
|||||||
progress.hide(); this.progressActive = false;
|
progress.hide(); this.progressActive = false;
|
||||||
this.loaderActive = true;
|
this.loaderActive = true;
|
||||||
this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
|
this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
|
||||||
|
} finally {
|
||||||
|
this.checkNewVersionAvailable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1053,8 +1108,8 @@ class Reader extends Vue {
|
|||||||
case 'copyText':
|
case 'copyText':
|
||||||
this.copyTextToggle();
|
this.copyTextToggle();
|
||||||
break;
|
break;
|
||||||
case 'splitToPara':
|
case 'convOptions':
|
||||||
this.refreshBook('split');
|
this.convOptionsToggle();
|
||||||
break;
|
break;
|
||||||
case 'refresh':
|
case 'refresh':
|
||||||
this.refreshBook();
|
this.refreshBook();
|
||||||
|
|||||||
@@ -57,37 +57,6 @@
|
|||||||
<q-btn class="q-px-sm" dense no-caps @click="donationDialogRemind">Напомнить позже</q-btn>
|
<q-btn class="q-px-sm" dense no-caps @click="donationDialogRemind">Напомнить позже</q-btn>
|
||||||
</span>
|
</span>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
<Dialog ref="dialog3" v-model="liberamaTopVisible">
|
|
||||||
<template slot="header">
|
|
||||||
Здравствуйте, уважаемые читатели!
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<div style="word-break: normal">
|
|
||||||
Создан новый ресурс:<br><br>
|
|
||||||
|
|
||||||
<a href="https://liberama.top" target="_blank">https://liberama.top</a>
|
|
||||||
<br><br>
|
|
||||||
Это клон читалки Omni Reader, но с некоторыми дополнениями, ориентированными в сторону более свободного обмена книгами:
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li>добавлено новое окно "Библиотека" для свободного доступа к Флибусте и другим ресурсам по желанию читателя</li>
|
|
||||||
<li>планируется добавить возможность создания подборок книг и обмена ими между пользователями</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
Легко мигрировать на новый сайт можно с помощью синхронизации с сервером.
|
|
||||||
О багах и предложениях просьба сообщать на почту <a href="mailto:bookpauk@gmail.com">bookpauk@gmail.com</a><br><br>
|
|
||||||
Спасибо, что вы с нами!
|
|
||||||
<br><br>
|
|
||||||
<div class="row justify-center">
|
|
||||||
<q-btn class="q-px-sm" color="primary" dense no-caps rounded @click="openDonate">Помочь проекту</q-btn>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<span slot="footer">
|
|
||||||
<q-btn class="q-px-sm" dense no-caps @click="liberamaTopDialogDisable">Больше не показывать</q-btn>
|
|
||||||
</span>
|
|
||||||
</Dialog>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -114,7 +83,6 @@ class ReaderDialogs extends Vue {
|
|||||||
whatsNewVisible = false;
|
whatsNewVisible = false;
|
||||||
whatsNewContent = '';
|
whatsNewContent = '';
|
||||||
donationVisible = false;
|
donationVisible = false;
|
||||||
liberamaTopVisible = false;
|
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.commit = this.$store.commit;
|
this.commit = this.$store.commit;
|
||||||
@@ -127,14 +95,12 @@ class ReaderDialogs extends Vue {
|
|||||||
async init() {
|
async init() {
|
||||||
await this.showWhatsNew();
|
await this.showWhatsNew();
|
||||||
await this.showDonation();
|
await this.showDonation();
|
||||||
await this.showLiberamaTop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadSettings() {
|
loadSettings() {
|
||||||
const settings = this.settings;
|
const settings = this.settings;
|
||||||
this.showWhatsNewDialog = settings.showWhatsNewDialog;
|
this.showWhatsNewDialog = settings.showWhatsNewDialog;
|
||||||
this.showDonationDialog2020 = settings.showDonationDialog2020;
|
this.showDonationDialog2020 = settings.showDonationDialog2020;
|
||||||
this.showLiberamaTopDialog2020 = settings.showLiberamaTopDialog2020;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async showWhatsNew() {
|
async showWhatsNew() {
|
||||||
@@ -171,7 +137,6 @@ class ReaderDialogs extends Vue {
|
|||||||
|
|
||||||
openDonate() {
|
openDonate() {
|
||||||
this.donationVisible = false;
|
this.donationVisible = false;
|
||||||
this.liberamaTopVisible = false;
|
|
||||||
this.$emit('donate-toggle');
|
this.$emit('donate-toggle');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,24 +175,8 @@ class ReaderDialogs extends Vue {
|
|||||||
return this.$store.state.reader.donationRemindDate;
|
return this.$store.state.reader.donationRemindDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
async showLiberamaTop() {
|
|
||||||
const today = utils.formatDate(new Date(), 'coDate');
|
|
||||||
|
|
||||||
if (this.mode == 'omnireader' && today < '2020-12-01' && this.showLiberamaTopDialog2020) {
|
|
||||||
await utils.sleep(3000);
|
|
||||||
this.liberamaTopVisible = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
liberamaTopDialogDisable() {
|
|
||||||
this.liberamaTopVisible = false;
|
|
||||||
if (this.showLiberamaTopDialog2020) {
|
|
||||||
this.commit('reader/setSettings', { showLiberamaTopDialog2020: false });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyHook() {
|
keyHook() {
|
||||||
if (this.$refs.dialog1.active || this.$refs.dialog2.active || this.$refs.dialog3.active)
|
if (this.$refs.dialog1.active || this.$refs.dialog2.active)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
<q-tab class="tab" name="buttons" icon="la la-grip-horizontal" label="Кнопки" />
|
<q-tab class="tab" name="buttons" icon="la la-grip-horizontal" label="Кнопки" />
|
||||||
<q-tab class="tab" name="keys" icon="la la-gamepad" label="Управление" />
|
<q-tab class="tab" name="keys" icon="la la-gamepad" label="Управление" />
|
||||||
<q-tab class="tab" name="pagemove" icon="la la-school" label="Листание" />
|
<q-tab class="tab" name="pagemove" icon="la la-school" label="Листание" />
|
||||||
|
<q-tab class="tab" name="convert" icon="la la-magic" label="Конвертир." />
|
||||||
<q-tab class="tab" name="others" icon="la la-list-ul" label="Прочее" />
|
<q-tab class="tab" name="others" icon="la la-list-ul" label="Прочее" />
|
||||||
<q-tab class="tab" name="reset" icon="la la-broom" label="Сброс" />
|
<q-tab class="tab" name="reset" icon="la la-broom" label="Сброс" />
|
||||||
<div v-show="tabsScrollable" class="q-pt-lg"/>
|
<div v-show="tabsScrollable" class="q-pt-lg"/>
|
||||||
@@ -53,6 +54,10 @@
|
|||||||
<div v-if="selectedTab == 'pagemove'" class="fit tab-panel">
|
<div v-if="selectedTab == 'pagemove'" class="fit tab-panel">
|
||||||
@@include('./include/PageMoveTab.inc');
|
@@include('./include/PageMoveTab.inc');
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Конвертирование ------------------------------------------------------------->
|
||||||
|
<div v-if="selectedTab == 'convert'" class="fit tab-panel">
|
||||||
|
@@include('./include/ConvertTab.inc');
|
||||||
|
</div>
|
||||||
<!-- Прочее ---------------------------------------------------------------------->
|
<!-- Прочее ---------------------------------------------------------------------->
|
||||||
<div v-if="selectedTab == 'others'" class="fit tab-panel">
|
<div v-if="selectedTab == 'others'" class="fit tab-panel">
|
||||||
@@include('./include/OthersTab.inc');
|
@@include('./include/OthersTab.inc');
|
||||||
@@ -218,6 +223,10 @@ class SettingsPage extends Vue {
|
|||||||
return this.$store.state.config.mode;
|
return this.$store.state.config.mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isExternalConverter() {
|
||||||
|
return this.$store.state.config.useExternalBookConverter;
|
||||||
|
}
|
||||||
|
|
||||||
get settings() {
|
get settings() {
|
||||||
return this.$store.state.reader.settings;
|
return this.$store.state.reader.settings;
|
||||||
}
|
}
|
||||||
@@ -544,7 +553,7 @@ class SettingsPage extends Vue {
|
|||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.label-1 {
|
.label-1, .label-7 {
|
||||||
width: 75px;
|
width: 75px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,7 +565,7 @@ class SettingsPage extends Vue {
|
|||||||
width: 100px;
|
width: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.label-1, .label-2, .label-3, .label-4, .label-5, .label-6 {
|
.label-1, .label-2, .label-3, .label-4, .label-5, .label-6, .label-7 {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
87
client/components/Reader/SettingsPage/include/ConvertTab.inc
Normal file
87
client/components/Reader/SettingsPage/include/ConvertTab.inc
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<!---------------------------------------------->
|
||||||
|
<div class="q-mt-sm column items-center">
|
||||||
|
<span>Настройки конвертирования применяются ко всем</span>
|
||||||
|
<span>вновь загружаемым или обновляемым файлам</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!---------------------------------------------->
|
||||||
|
<div class="part-header">HTML, XML, TXT</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-7">Текст</div>
|
||||||
|
<div class="col row">
|
||||||
|
<q-checkbox v-model="splitToPara" size="xs" label="Попытаться разбить текст на параграфы">
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Опция принудительно включает эвристику разбиения текста на<br>
|
||||||
|
параграфы в случае, если формат файла определен как html,<br>
|
||||||
|
xml или txt. Возможна нечитабельная разметка текста.
|
||||||
|
</q-tooltip>
|
||||||
|
</q-checkbox>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-7">Сайты</div>
|
||||||
|
<div class="col row">
|
||||||
|
<q-checkbox v-model="enableSitesFilter" size="xs" label="Включить html-фильтр для сайтов">
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Html-фильтр вырезает лишние элементы со<br>
|
||||||
|
страницы для определенных сайтов, таких как:<br>
|
||||||
|
samlib.ru<br>
|
||||||
|
www.fanfiction.net<br>
|
||||||
|
archiveofourown.org<br>
|
||||||
|
и других
|
||||||
|
</q-tooltip>
|
||||||
|
</q-checkbox>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!---------------------------------------------->
|
||||||
|
<div v-if="isExternalConverter">
|
||||||
|
<div class="part-header">PDF</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-7">Формат</div>
|
||||||
|
<div class="col row">
|
||||||
|
<q-checkbox v-model="pdfAsText" size="xs" label="Извлекать текст из PDF">
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Пытается извлечь текст из pdf-файла и переразбить на параграфы.<br>
|
||||||
|
Размер получаемого fb2-файла при этом относительно небольшой.<br>
|
||||||
|
При отключении этой опции, pdf будет представлен как набор<br>
|
||||||
|
изображений (аналогично ковертированию djvu).
|
||||||
|
</q-tooltip>
|
||||||
|
</q-checkbox>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-7">Качество</div>
|
||||||
|
<div class="col row">
|
||||||
|
<NumInput class="col-5" v-model="pdfQuality" :min="10" :max="100" :disable="pdfAsText" >
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Качество конвертирования Pdf в Fb2. Чем значение выше, тем больше<br>
|
||||||
|
размер итогового файла. Если сервер отказывается конвертировать<br>
|
||||||
|
слишком большой файл, то попробуйте понизить качество.
|
||||||
|
</q-tooltip>
|
||||||
|
</NumInput>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!---------------------------------------------->
|
||||||
|
<div v-if="isExternalConverter">
|
||||||
|
<div class="part-header">DJVU</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-7">Качество</div>
|
||||||
|
<div class="col row">
|
||||||
|
<NumInput class="col-5" v-model="djvuQuality" :min="10" :max="100">
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Качество конвертирования Djvu в Fb2. Чем значение выше, тем больше<br>
|
||||||
|
размер итогового файла. Если сервер отказывается конвертировать<br>
|
||||||
|
слишком большой файл, то попробуйте понизить качество.
|
||||||
|
</q-tooltip>
|
||||||
|
</NumInput>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -36,7 +36,18 @@
|
|||||||
Показывать уведомление "Что нового"
|
Показывать уведомление "Что нового"
|
||||||
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
Показывать уведомления "Что нового"<br>
|
Показывать уведомления "Что нового"<br>
|
||||||
при каждом выходе новой версии читалки
|
при появлении новой версии читалки
|
||||||
|
</q-tooltip>
|
||||||
|
</q-checkbox>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-6">Уведомление</div>
|
||||||
|
<q-checkbox size="xs" v-model="showNeedUpdateNotify">
|
||||||
|
Показывать уведомление о новой версии
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Напоминать о необходимости обновления страницы<br>
|
||||||
|
при появлении новой версии читалки
|
||||||
</q-tooltip>
|
</q-tooltip>
|
||||||
</q-checkbox>
|
</q-checkbox>
|
||||||
</div>
|
</div>
|
||||||
@@ -54,22 +65,6 @@
|
|||||||
<!---------------------------------------------->
|
<!---------------------------------------------->
|
||||||
<div class="part-header">Другое</div>
|
<div class="part-header">Другое</div>
|
||||||
|
|
||||||
<div class="item row">
|
|
||||||
<div class="label-6">Обработка</div>
|
|
||||||
<div class="col row">
|
|
||||||
<q-checkbox v-model="enableSitesFilter" @input="needTextReload" size="xs" label="Включить html-фильтр для сайтов">
|
|
||||||
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
|
||||||
Html-фильтр вырезает лишние элементы со<br>
|
|
||||||
страницы для определенных сайтов, таких как:<br>
|
|
||||||
samlib.ru<br>
|
|
||||||
www.fanfiction.net<br>
|
|
||||||
archiveofourown.org<br>
|
|
||||||
и других
|
|
||||||
</q-tooltip>
|
|
||||||
</q-checkbox>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="item row">
|
<div class="item row">
|
||||||
<div class="label-6">Обработка</div>
|
<div class="label-6">Обработка</div>
|
||||||
<q-checkbox size="xs" v-model="lazyParseEnabled" label="Предварительная подготовка текста">
|
<q-checkbox size="xs" v-model="lazyParseEnabled" label="Предварительная подготовка текста">
|
||||||
|
|||||||
@@ -160,12 +160,13 @@ export default class DrawHelper {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawPercentBar(x, y, w, h, font, fontSize, bookPos, textLength) {
|
drawPercentBar(x, y, w, h, font, fontSize, bookPos, textLength, imageNum, imageLength) {
|
||||||
const pad = 3;
|
const pad = 3;
|
||||||
const fh = h - 2*pad;
|
const fh = h - 2*pad;
|
||||||
const fh2 = fh/2;
|
const fh2 = fh/2;
|
||||||
|
|
||||||
const t1 = `${Math.floor((bookPos + 1)/1000)}/${Math.floor(textLength/1000)}`;
|
const tImg = (imageNum > 0 ? ` (${imageNum}/${imageLength})` : '');
|
||||||
|
const t1 = `${Math.floor((bookPos + 1)/1000)}/${Math.floor(textLength/1000)}${tImg}`;
|
||||||
const w1 = this.measureTextFont(t1, font) + fh2;
|
const w1 = this.measureTextFont(t1, font) + fh2;
|
||||||
const read = (bookPos + 1)/textLength;
|
const read = (bookPos + 1)/textLength;
|
||||||
const t2 = `${(read*100).toFixed(2)}%`;
|
const t2 = `${(read*100).toFixed(2)}%`;
|
||||||
@@ -188,7 +189,7 @@ export default class DrawHelper {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawStatusBar(statusBarTop, statusBarHeight, bookPos, textLength, title) {
|
drawStatusBar(statusBarTop, statusBarHeight, bookPos, textLength, title, imageNum, imageLength) {
|
||||||
|
|
||||||
let out = `<div class="layout" style="` +
|
let out = `<div class="layout" style="` +
|
||||||
`width: ${this.realWidth}px; height: ${statusBarHeight}px; ` +
|
`width: ${this.realWidth}px; height: ${statusBarHeight}px; ` +
|
||||||
@@ -206,7 +207,7 @@ export default class DrawHelper {
|
|||||||
|
|
||||||
out += this.fillTextShift(this.fittingString(title, this.realWidth/2 - fontSize - 3, font), fontSize, 2, font, fontSize);
|
out += this.fillTextShift(this.fittingString(title, this.realWidth/2 - fontSize - 3, font), fontSize, 2, font, fontSize);
|
||||||
|
|
||||||
out += this.drawPercentBar(this.realWidth/2, 2, this.realWidth/2 - timeW - 2*fontSize, statusBarHeight, font, fontSize, bookPos, textLength);
|
out += this.drawPercentBar(this.realWidth/2, 2, this.realWidth/2 - timeW - 2*fontSize, statusBarHeight, font, fontSize, bookPos, textLength, imageNum, imageLength);
|
||||||
|
|
||||||
out += '</div>';
|
out += '</div>';
|
||||||
return out;
|
return out;
|
||||||
|
|||||||
@@ -722,8 +722,24 @@ class TextPage extends Vue {
|
|||||||
message = this.statusBarMessage;
|
message = this.statusBarMessage;
|
||||||
if (!message)
|
if (!message)
|
||||||
message = this.title;
|
message = this.title;
|
||||||
|
|
||||||
|
//check image num
|
||||||
|
let imageNum = 0;
|
||||||
|
const len = (lines.length > 2 ? 2 : lines.length);
|
||||||
|
loop:
|
||||||
|
for (let j = 0; j < len; j++) {
|
||||||
|
const line = lines[j];
|
||||||
|
for (const part of line.parts) {
|
||||||
|
if (part.image) {
|
||||||
|
imageNum = part.image.num;
|
||||||
|
break loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//drawing
|
||||||
this.statusBar = this.drawHelper.drawStatusBar(this.statusBarTop, this.statusBarHeight,
|
this.statusBar = this.drawHelper.drawStatusBar(this.statusBarTop, this.statusBarHeight,
|
||||||
lines[i].end, this.parsed.textLength, message);
|
lines[i].end, this.parsed.textLength, message, imageNum, this.parsed.images.length);
|
||||||
|
|
||||||
this.bookPosSeen = lines[i].end;
|
this.bookPosSeen = lines[i].end;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -54,12 +54,14 @@ export default class BookParser {
|
|||||||
|
|
||||||
//оглавление
|
//оглавление
|
||||||
this.contents = [];
|
this.contents = [];
|
||||||
|
this.images = [];
|
||||||
let curTitle = {paraIndex: -1, title: '', subtitles: []};
|
let curTitle = {paraIndex: -1, title: '', subtitles: []};
|
||||||
let curSubtitle = {paraIndex: -1, title: ''};
|
let curSubtitle = {paraIndex: -1, title: ''};
|
||||||
let inTitle = false;
|
let inTitle = false;
|
||||||
let inSubtitle = false;
|
let inSubtitle = false;
|
||||||
let sectionLevel = 0;
|
let sectionLevel = 0;
|
||||||
let bodyIndex = 0;
|
let bodyIndex = 0;
|
||||||
|
let imageNum = 0;
|
||||||
|
|
||||||
let paraIndex = -1;
|
let paraIndex = -1;
|
||||||
let paraOffset = 0;
|
let paraOffset = 0;
|
||||||
@@ -194,6 +196,7 @@ export default class BookParser {
|
|||||||
if (tag == 'binary') {
|
if (tag == 'binary') {
|
||||||
let attrs = sax.getAttrsSync(tail);
|
let attrs = sax.getAttrsSync(tail);
|
||||||
binaryType = (attrs['content-type'] && attrs['content-type'].value ? attrs['content-type'].value : '');
|
binaryType = (attrs['content-type'] && attrs['content-type'].value ? attrs['content-type'].value : '');
|
||||||
|
binaryType = (binaryType == 'image/jpg' ? 'image/jpeg' : binaryType);
|
||||||
if (binaryType == 'image/jpeg' || binaryType == 'image/png' || binaryType == 'application/octet-stream')
|
if (binaryType == 'image/jpeg' || binaryType == 'image/png' || binaryType == 'application/octet-stream')
|
||||||
binaryId = (attrs.id.value ? attrs.id.value : '');
|
binaryId = (attrs.id.value ? attrs.id.value : '');
|
||||||
}
|
}
|
||||||
@@ -202,16 +205,27 @@ export default class BookParser {
|
|||||||
let attrs = sax.getAttrsSync(tail);
|
let attrs = sax.getAttrsSync(tail);
|
||||||
if (attrs.href && attrs.href.value) {
|
if (attrs.href && attrs.href.value) {
|
||||||
const href = attrs.href.value;
|
const href = attrs.href.value;
|
||||||
|
const alt = (attrs.alt && attrs.alt.value ? attrs.alt.value : '');
|
||||||
|
const {id, local} = this.imageHrefToId(href);
|
||||||
if (href[0] == '#') {//local
|
if (href[0] == '#') {//local
|
||||||
|
imageNum++;
|
||||||
|
|
||||||
if (inPara && !this.showInlineImagesInCenter && !center)
|
if (inPara && !this.showInlineImagesInCenter && !center)
|
||||||
growParagraph(`<image-inline href="${href}"></image-inline>`, 0);
|
growParagraph(`<image-inline href="${href}" num="${imageNum}"></image-inline>`, 0);
|
||||||
else
|
else
|
||||||
newParagraph(`<image href="${href}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
newParagraph(`<image href="${href}" num="${imageNum}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
||||||
|
|
||||||
|
this.images.push({paraIndex, num: imageNum, id, local, alt});
|
||||||
|
|
||||||
if (inPara && this.showInlineImagesInCenter)
|
if (inPara && this.showInlineImagesInCenter)
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
} else {//external
|
} else {//external
|
||||||
|
imageNum++;
|
||||||
|
|
||||||
dimPromises.push(getExternalImageDimensions(href));
|
dimPromises.push(getExternalImageDimensions(href));
|
||||||
newParagraph(`<image href="${href}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
newParagraph(`<image href="${href}" num="${imageNum}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
||||||
|
|
||||||
|
this.images.push({paraIndex, num: imageNum, id, local, alt});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,6 +318,11 @@ export default class BookParser {
|
|||||||
bold = true;
|
bold = true;
|
||||||
center = true;
|
center = true;
|
||||||
|
|
||||||
|
if (curTitle.paraIndex < 0) {
|
||||||
|
curTitle = {paraIndex, title: 'Оглавление', inset: sectionLevel, bodyIndex, subtitles: []};
|
||||||
|
this.contents.push(curTitle);
|
||||||
|
}
|
||||||
|
|
||||||
inSubtitle = true;
|
inSubtitle = true;
|
||||||
curSubtitle = {paraIndex, inset: sectionLevel, title: ''};
|
curSubtitle = {paraIndex, inset: sectionLevel, title: ''};
|
||||||
curTitle.subtitles.push(curSubtitle);
|
curTitle.subtitles.push(curSubtitle);
|
||||||
@@ -483,6 +502,15 @@ export default class BookParser {
|
|||||||
return {fb2};
|
return {fb2};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
imageHrefToId(id) {
|
||||||
|
let local = false;
|
||||||
|
if (id[0] == '#') {
|
||||||
|
id = id.substr(1);
|
||||||
|
local = true;
|
||||||
|
}
|
||||||
|
return {id, local};
|
||||||
|
}
|
||||||
|
|
||||||
findParaIndex(bookPos) {
|
findParaIndex(bookPos) {
|
||||||
let result = undefined;
|
let result = undefined;
|
||||||
//дихотомия
|
//дихотомия
|
||||||
@@ -548,28 +576,21 @@ export default class BookParser {
|
|||||||
case 'image': {
|
case 'image': {
|
||||||
let attrs = sax.getAttrsSync(tail);
|
let attrs = sax.getAttrsSync(tail);
|
||||||
if (attrs.href && attrs.href.value) {
|
if (attrs.href && attrs.href.value) {
|
||||||
let id = attrs.href.value;
|
image = this.imageHrefToId(attrs.href.value);
|
||||||
let local = false;
|
image.inline = false;
|
||||||
if (id[0] == '#') {
|
image.num = (attrs.num && attrs.num.value ? attrs.num.value : 0);
|
||||||
id = id.substr(1);
|
|
||||||
local = true;
|
|
||||||
}
|
|
||||||
image = {local, inline: false, id};
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'image-inline': {
|
case 'image-inline': {
|
||||||
let attrs = sax.getAttrsSync(tail);
|
let attrs = sax.getAttrsSync(tail);
|
||||||
if (attrs.href && attrs.href.value) {
|
if (attrs.href && attrs.href.value) {
|
||||||
let id = attrs.href.value;
|
const img = this.imageHrefToId(attrs.href.value);
|
||||||
let local = false;
|
img.inline = true;
|
||||||
if (id[0] == '#') {
|
img.num = (attrs.num && attrs.num.value ? attrs.num.value : 0);
|
||||||
id = id.substr(1);
|
|
||||||
local = true;
|
|
||||||
}
|
|
||||||
result.push({
|
result.push({
|
||||||
style: Object.assign({}, style),
|
style: Object.assign({}, style),
|
||||||
image: {local, inline: true, id},
|
image: img,
|
||||||
text: ''
|
text: ''
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -796,6 +817,7 @@ export default class BookParser {
|
|||||||
paraIndex,
|
paraIndex,
|
||||||
w: imageWidth,
|
w: imageWidth,
|
||||||
h: imageHeight,
|
h: imageHeight,
|
||||||
|
num: part.image.num
|
||||||
}});
|
}});
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
line = {begin: line.end + 1, parts: []};
|
line = {begin: line.end + 1, parts: []};
|
||||||
@@ -806,7 +828,7 @@ export default class BookParser {
|
|||||||
line.last = true;
|
line.last = true;
|
||||||
line.parts.push({style, text: ' ',
|
line.parts.push({style, text: ' ',
|
||||||
image: {local: part.image.local, inline: false, id: part.image.id,
|
image: {local: part.image.local, inline: false, id: part.image.id,
|
||||||
imageLine: i, lineCount, paraIndex, w: imageWidth, h: imageHeight}
|
imageLine: i, lineCount, paraIndex, w: imageWidth, h: imageHeight, num: part.image.num}
|
||||||
});
|
});
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -818,7 +840,7 @@ export default class BookParser {
|
|||||||
let imgH = (bin.h > this.fontSize ? this.fontSize : bin.h);
|
let imgH = (bin.h > this.fontSize ? this.fontSize : bin.h);
|
||||||
imgW += bin.w*imgH/bin.h;
|
imgW += bin.w*imgH/bin.h;
|
||||||
line.parts.push({style, text: '',
|
line.parts.push({style, text: '',
|
||||||
image: {local: part.image.local, inline: true, id: part.image.id}});
|
image: {local: part.image.local, inline: true, id: part.image.id, num: part.image.num}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -410,16 +410,12 @@ class BookManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setRecentBook(value) {
|
async setRecentBook(value) {
|
||||||
const result = this.metaOnly(value);
|
let result = this.metaOnly(value);
|
||||||
result.touchTime = Date.now();
|
result.touchTime = Date.now();
|
||||||
result.deleted = 0;
|
result.deleted = 0;
|
||||||
|
|
||||||
if (this.recent[result.key] && this.recent[result.key].deleted) {
|
if (this.recent[result.key]) {
|
||||||
//восстановим из небытия пользовательские данные
|
result = Object.assign({}, this.recent[result.key], result);
|
||||||
if (!result.bookPos)
|
|
||||||
result.bookPos = this.recent[result.key].bookPos;
|
|
||||||
if (!result.bookPosSeen)
|
|
||||||
result.bookPosSeen = this.recent[result.key].bookPosSeen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.recentSetLastKey(result.key);
|
await this.recentSetLastKey(result.key);
|
||||||
|
|||||||
@@ -1,4 +1,18 @@
|
|||||||
export const versionHistory = [
|
export const versionHistory = [
|
||||||
|
{
|
||||||
|
showUntil: '2020-12-17',
|
||||||
|
header: '0.9.12 (2020-12-18)',
|
||||||
|
content:
|
||||||
|
`
|
||||||
|
<ul>
|
||||||
|
<li>добавлена вкладка "Изображения" в окно оглавления</li>
|
||||||
|
<li>настройки конвертирования вынесены в отдельную вкладку</li>
|
||||||
|
<li>добавлена кнопка для быстрого доступа к настройкам конвертирования</li>
|
||||||
|
<li>улучшения работы конвертеров</li>
|
||||||
|
</ul>
|
||||||
|
`
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
showUntil: '2020-12-08',
|
showUntil: '2020-12-08',
|
||||||
header: '0.9.11 (2020-12-09)',
|
header: '0.9.11 (2020-12-09)',
|
||||||
|
|||||||
@@ -10,18 +10,7 @@ const state = {
|
|||||||
const getters = {};
|
const getters = {};
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
const actions = {
|
const actions = {};
|
||||||
async loadConfig({ commit, state }) {
|
|
||||||
commit('setApiError', null, { root: true });
|
|
||||||
commit('setConfig', {});
|
|
||||||
try {
|
|
||||||
const config = await miscApi.loadConfig();
|
|
||||||
commit('setConfig', config);
|
|
||||||
} catch (e) {
|
|
||||||
commit('setApiError', e, { root: true });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// mutations
|
// mutations
|
||||||
const mutations = {
|
const mutations = {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const readerActions = {
|
|||||||
'setPosition': 'Установить позицию',
|
'setPosition': 'Установить позицию',
|
||||||
'search': 'Найти в тексте',
|
'search': 'Найти в тексте',
|
||||||
'copyText': 'Скопировать текст со страницы',
|
'copyText': 'Скопировать текст со страницы',
|
||||||
'splitToPara': 'Обновить с разбиением на параграфы',
|
'convOptions': 'Настроить конвертирование',
|
||||||
'refresh': 'Принудительно обновить книгу',
|
'refresh': 'Принудительно обновить книгу',
|
||||||
'offlineMode': 'Автономный режим (без интернета)',
|
'offlineMode': 'Автономный режим (без интернета)',
|
||||||
'contents': 'Оглавление/закладки',
|
'contents': 'Оглавление/закладки',
|
||||||
@@ -41,7 +41,7 @@ const toolButtons = [
|
|||||||
{name: 'setPosition', show: true},
|
{name: 'setPosition', show: true},
|
||||||
{name: 'search', show: true},
|
{name: 'search', show: true},
|
||||||
{name: 'copyText', show: false},
|
{name: 'copyText', show: false},
|
||||||
{name: 'splitToPara', show: false},
|
{name: 'convOptions', show: true},
|
||||||
{name: 'refresh', show: true},
|
{name: 'refresh', show: true},
|
||||||
{name: 'contents', show: true},
|
{name: 'contents', show: true},
|
||||||
{name: 'libs', show: true},
|
{name: 'libs', show: true},
|
||||||
@@ -61,7 +61,7 @@ const hotKeys = [
|
|||||||
{name: 'setPosition', codes: ['P']},
|
{name: 'setPosition', codes: ['P']},
|
||||||
{name: 'search', codes: ['Ctrl+F']},
|
{name: 'search', codes: ['Ctrl+F']},
|
||||||
{name: 'copyText', codes: ['Ctrl+C']},
|
{name: 'copyText', codes: ['Ctrl+C']},
|
||||||
{name: 'splitToPara', codes: ['Shift+R']},
|
{name: 'convOptions', codes: ['Ctrl+M']},
|
||||||
{name: 'refresh', codes: ['R']},
|
{name: 'refresh', codes: ['R']},
|
||||||
{name: 'contents', codes: ['C']},
|
{name: 'contents', codes: ['C']},
|
||||||
{name: 'libs', codes: ['L']},
|
{name: 'libs', codes: ['L']},
|
||||||
@@ -251,11 +251,16 @@ const settingDefaults = {
|
|||||||
compactTextPerc: 0,
|
compactTextPerc: 0,
|
||||||
imageHeightLines: 100,
|
imageHeightLines: 100,
|
||||||
imageFitWidth: true,
|
imageFitWidth: true,
|
||||||
|
enableSitesFilter: true,
|
||||||
|
splitToPara: false,
|
||||||
|
djvuQuality: 20,
|
||||||
|
pdfAsText: true,
|
||||||
|
pdfQuality: 20,
|
||||||
|
|
||||||
showServerStorageMessages: true,
|
showServerStorageMessages: true,
|
||||||
showWhatsNewDialog: true,
|
showWhatsNewDialog: true,
|
||||||
showDonationDialog2020: true,
|
showDonationDialog2020: true,
|
||||||
showLiberamaTopDialog2020: true,
|
showNeedUpdateNotify: true,
|
||||||
enableSitesFilter: true,
|
|
||||||
|
|
||||||
fontShifts: {},
|
fontShifts: {},
|
||||||
showToolButton: {},
|
showToolButton: {},
|
||||||
|
|||||||
@@ -32,23 +32,11 @@ sudo -u www-data mkdir -p /home/liberama/data/calibre
|
|||||||
sudo -u www-data tar xvf calibre-5.5.0-x86_64.txz -C /home/liberama/data/calibre
|
sudo -u www-data tar xvf calibre-5.5.0-x86_64.txz -C /home/liberama/data/calibre
|
||||||
```
|
```
|
||||||
|
|
||||||
### external converter `pdfalto`, github https://github.com/kermitt2/pdfalto
|
|
||||||
```
|
|
||||||
git clone https://github.com/kermitt2/pdfalto
|
|
||||||
cd pdfalto
|
|
||||||
git submodule update --init --recursive
|
|
||||||
cmake ./
|
|
||||||
добавить в начало CMakeLists.txt строчку: set(CMAKE_EXE_LINKER_FLAGS "-no-pie")
|
|
||||||
make
|
|
||||||
|
|
||||||
sudo -u www-data mkdir -p /home/liberama/data/pdfalto
|
|
||||||
sudo -u www-data cp pdfalto /home/liberama/data/pdfalto
|
|
||||||
```
|
|
||||||
|
|
||||||
### external converters
|
### external converters
|
||||||
```
|
```
|
||||||
sudo apt install rar
|
sudo apt install rar
|
||||||
sudo apt install libreoffice
|
sudo apt install libreoffice
|
||||||
|
sudo apt install poppler-utils
|
||||||
sudo apt install djvulibre-bin
|
sudo apt install djvulibre-bin
|
||||||
sudo apt install libtiff-tools
|
sudo apt install libtiff-tools
|
||||||
sudo apt install graphicsmagick-imagemagick-compat
|
sudo apt install graphicsmagick-imagemagick-compat
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.9.11",
|
"version": "0.9.12",
|
||||||
"author": "Book Pauk <bookpauk@gmail.com>",
|
"author": "Book Pauk <bookpauk@gmail.com>",
|
||||||
"license": "CC0-1.0",
|
"license": "CC0-1.0",
|
||||||
"repository": "bookpauk/liberama",
|
"repository": "bookpauk/liberama",
|
||||||
|
|||||||
@@ -20,9 +20,12 @@ class ReaderController extends BaseController {
|
|||||||
const workerId = this.readerWorker.loadBookUrl({
|
const workerId = this.readerWorker.loadBookUrl({
|
||||||
url: request.url,
|
url: request.url,
|
||||||
enableSitesFilter: (request.hasOwnProperty('enableSitesFilter') ? request.enableSitesFilter : true),
|
enableSitesFilter: (request.hasOwnProperty('enableSitesFilter') ? request.enableSitesFilter : true),
|
||||||
skipCheck: (request.hasOwnProperty('skipCheck') ? request.skipCheck : false),
|
skipHtmlCheck: (request.hasOwnProperty('skipHtmlCheck') ? request.skipHtmlCheck : false),
|
||||||
isText: (request.hasOwnProperty('isText') ? request.isText : false),
|
isText: (request.hasOwnProperty('isText') ? request.isText : false),
|
||||||
uploadFileName: (request.hasOwnProperty('uploadFileName') ? request.uploadFileName : false),
|
uploadFileName: (request.hasOwnProperty('uploadFileName') ? request.uploadFileName : false),
|
||||||
|
djvuQuality: (request.hasOwnProperty('djvuQuality') ? request.djvuQuality : false),
|
||||||
|
pdfAsText: (request.hasOwnProperty('pdfAsText') ? request.pdfAsText : false),
|
||||||
|
pdfQuality: (request.hasOwnProperty('pdfQuality') ? request.pdfQuality : false),
|
||||||
});
|
});
|
||||||
const state = this.workerState.getState(workerId);
|
const state = this.workerState.getState(workerId);
|
||||||
return (state ? state : {});
|
return (state ? state : {});
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ class ConvertBase {
|
|||||||
const error = `${result.code}|FORLOG|, exec: ${path}, args: ${args.join(' ')}, stdout: ${result.stdout}, stderr: ${result.stderr}`;
|
const error = `${result.code}|FORLOG|, exec: ${path}, args: ${args.join(' ')}, stdout: ${result.stdout}, stderr: ${result.stderr}`;
|
||||||
throw new Error(`Внешний конвертер завершился с ошибкой: ${error}`);
|
throw new Error(`Внешний конвертер завершился с ошибкой: ${error}`);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if (e.status == 'killed') {
|
if (e.status == 'killed') {
|
||||||
throw new Error('Слишком долгое ожидание конвертера');
|
throw new Error('Слишком долгое ожидание конвертера');
|
||||||
@@ -102,6 +103,11 @@ class ConvertBase {
|
|||||||
return he.escape(he.decode(text.replace(/ /g, ' ')));
|
return he.escape(he.decode(text.replace(/ /g, ' ')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isDataXml(data) {
|
||||||
|
const str = data.slice(0, 100).toString().trim();
|
||||||
|
return (str.indexOf('<?xml version="1.0"') == 0 || str.indexOf('<?xml version=\'1.0\'') == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
formatFb2(fb2) {
|
formatFb2(fb2) {
|
||||||
const out = xmlParser.formatXml({
|
const out = xmlParser.formatXml({
|
||||||
FictionBook: {
|
FictionBook: {
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ const fs = require('fs-extra');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const utils = require('../../utils');
|
const utils = require('../../utils');
|
||||||
|
|
||||||
const ConvertBase = require('./ConvertBase');
|
const ConvertJpegPng = require('./ConvertJpegPng');
|
||||||
|
|
||||||
class ConvertDjvu extends ConvertBase {
|
class ConvertDjvu extends ConvertJpegPng {
|
||||||
check(data, opts) {
|
check(data, opts) {
|
||||||
const {inputFiles} = opts;
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
@@ -16,12 +16,21 @@ class ConvertDjvu extends ConvertBase {
|
|||||||
if (!this.check(data, opts))
|
if (!this.check(data, opts))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const {inputFiles, callback, abort, uploadFileName} = opts;
|
let {inputFiles, callback, abort, djvuQuality} = opts;
|
||||||
|
|
||||||
|
djvuQuality = (djvuQuality && djvuQuality <= 100 && djvuQuality >= 10 ? djvuQuality : 20);
|
||||||
|
let jpegQuality = djvuQuality;
|
||||||
|
let tiffQuality = djvuQuality + 30;
|
||||||
|
tiffQuality = (tiffQuality < 85 ? tiffQuality : 85);
|
||||||
|
|
||||||
const ddjvuPath = '/usr/bin/ddjvu';
|
const ddjvuPath = '/usr/bin/ddjvu';
|
||||||
if (!await fs.pathExists(ddjvuPath))
|
if (!await fs.pathExists(ddjvuPath))
|
||||||
throw new Error('Внешний конвертер ddjvu не найден');
|
throw new Error('Внешний конвертер ddjvu не найден');
|
||||||
|
|
||||||
|
const djvusedPath = '/usr/bin/djvused';
|
||||||
|
if (!await fs.pathExists(djvusedPath))
|
||||||
|
throw new Error('Внешний конвертер djvused не найден');
|
||||||
|
|
||||||
const tiffsplitPath = '/usr/bin/tiffsplit';
|
const tiffsplitPath = '/usr/bin/tiffsplit';
|
||||||
if (!await fs.pathExists(tiffsplitPath))
|
if (!await fs.pathExists(tiffsplitPath))
|
||||||
throw new Error('Внешний конвертер tiffsplitPath не найден');
|
throw new Error('Внешний конвертер tiffsplitPath не найден');
|
||||||
@@ -31,20 +40,20 @@ class ConvertDjvu extends ConvertBase {
|
|||||||
throw new Error('Внешний конвертер mogrifyPath не найден');
|
throw new Error('Внешний конвертер mogrifyPath не найден');
|
||||||
|
|
||||||
const dir = `${inputFiles.filesDir}/`;
|
const dir = `${inputFiles.filesDir}/`;
|
||||||
const inpFile = `${dir}${path.basename(inputFiles.sourceFile)}`;
|
const baseFile = `${dir}${path.basename(inputFiles.sourceFile)}`;
|
||||||
const tifFile = `${inpFile}.tif`;
|
const tifFile = `${baseFile}.tif`;
|
||||||
|
|
||||||
//конвертируем в tiff
|
//конвертируем в tiff
|
||||||
let perc = 0;
|
let perc = 0;
|
||||||
await this.execConverter(ddjvuPath, ['-format=tiff', '-quality=50', '-verbose', inputFiles.sourceFile, tifFile], () => {
|
await this.execConverter(ddjvuPath, ['-format=tiff', `-quality=${tiffQuality}`, '-verbose', inputFiles.sourceFile, tifFile], () => {
|
||||||
perc = (perc < 100 ? perc + 1 : 40);
|
perc = (perc < 100 ? perc + 1 : 40);
|
||||||
callback(perc);
|
callback(perc);
|
||||||
}, abort);
|
}, abort);
|
||||||
|
|
||||||
const tifFileSize = (await fs.stat(tifFile)).size;
|
const tifFileSize = (await fs.stat(tifFile)).size;
|
||||||
let limitSize = 3*this.config.maxUploadFileSize;
|
let limitSize = 4*this.config.maxUploadFileSize;
|
||||||
if (tifFileSize > limitSize) {
|
if (tifFileSize > limitSize) {
|
||||||
throw new Error(`Файл для конвертирования слишком большой|FORLOG| ${tifFileSize} > ${limitSize}`);
|
throw new Error(`Файл для конвертирования слишком большой|FORLOG| tifFileSize: ${tifFileSize} > ${limitSize}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//разбиваем на файлы
|
//разбиваем на файлы
|
||||||
@@ -53,66 +62,57 @@ class ConvertDjvu extends ConvertBase {
|
|||||||
await fs.remove(tifFile);
|
await fs.remove(tifFile);
|
||||||
|
|
||||||
//конвертируем в jpg
|
//конвертируем в jpg
|
||||||
await this.execConverter(mogrifyPath, ['-quality', '20', '-scale', '2048', '-verbose', '-format', 'jpg', `${dir}*.tif`], () => {
|
await this.execConverter(mogrifyPath, ['-quality', jpegQuality, '-scale', '2048>', '-verbose', '-format', 'jpg', `${dir}*.tif`], () => {
|
||||||
perc = (perc < 100 ? perc + 1 : 40);
|
perc = (perc < 100 ? perc + 1 : 40);
|
||||||
callback(perc);
|
callback(perc);
|
||||||
}, abort);
|
}, abort);
|
||||||
|
|
||||||
//читаем изображения
|
|
||||||
limitSize = 2*this.config.maxUploadFileSize;
|
limitSize = 2*this.config.maxUploadFileSize;
|
||||||
let imagesSize = 0;
|
let jpgFilesSize = 0;
|
||||||
|
//ищем изображения
|
||||||
const loadImage = async(image) => {
|
|
||||||
image.data = (await fs.readFile(image.file)).toString('base64');
|
|
||||||
image.name = path.basename(image.file);
|
|
||||||
|
|
||||||
imagesSize += image.data.length;
|
|
||||||
if (imagesSize > limitSize) {
|
|
||||||
throw new Error(`Файл для конвертирования слишком большой|FORLOG| imagesSize: ${imagesSize} > ${limitSize}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let files = [];
|
let files = [];
|
||||||
await utils.findFiles(async(file) => {
|
await utils.findFiles(async(file) => {
|
||||||
if (path.extname(file) == '.jpg')
|
if (path.extname(file) == '.jpg') {
|
||||||
|
jpgFilesSize += (await fs.stat(file)).size;
|
||||||
|
if (jpgFilesSize > limitSize) {
|
||||||
|
throw new Error(`Файл для конвертирования слишком большой|FORLOG| jpgFilesSize: ${jpgFilesSize} > ${limitSize}`);
|
||||||
|
}
|
||||||
|
|
||||||
files.push({name: file, base: path.basename(file)});
|
files.push({name: file, base: path.basename(file)});
|
||||||
|
}
|
||||||
}, dir);
|
}, dir);
|
||||||
|
|
||||||
files.sort((a, b) => a.base.localeCompare(b.base));
|
files.sort((a, b) => a.base.localeCompare(b.base));
|
||||||
|
|
||||||
let images = [];
|
//схема документа (outline)
|
||||||
let loading = [];
|
const djvusedResult = await this.execConverter(djvusedPath, ['-u', '-e', 'print-outline', inputFiles.sourceFile], null, abort);
|
||||||
files.forEach(f => {
|
|
||||||
const image = {file: f.name};
|
const outline = [];
|
||||||
images.push(image);
|
const lines = djvusedResult.stdout.match(/\(\s*".*"\s*?"#\d+"/g);
|
||||||
loading.push(loadImage(image));
|
if (lines) {
|
||||||
|
lines.forEach(l => {
|
||||||
|
const m = l.match(/"(.*)"\s*?"#(\d+)"/);
|
||||||
|
if (m) {
|
||||||
|
const pageNum = m[2];
|
||||||
|
let s = outline[pageNum];
|
||||||
|
if (!s)
|
||||||
|
s = m[1].trim();
|
||||||
|
else
|
||||||
|
s += `${(s[s.length - 1] != '.' ? '.' : '')} ${m[1].trim()}`;
|
||||||
|
|
||||||
|
outline[pageNum] = s;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(loading);
|
|
||||||
|
|
||||||
//формируем fb2
|
|
||||||
let titleInfo = {};
|
|
||||||
let desc = {_n: 'description', 'title-info': titleInfo};
|
|
||||||
let pars = [];
|
|
||||||
let body = {_n: 'body', section: {_a: [pars]}};
|
|
||||||
let binary = [];
|
|
||||||
let fb2 = [desc, body, binary];
|
|
||||||
|
|
||||||
let title = '';
|
|
||||||
if (uploadFileName)
|
|
||||||
title = uploadFileName;
|
|
||||||
|
|
||||||
titleInfo['book-title'] = title;
|
|
||||||
|
|
||||||
for (const image of images) {
|
|
||||||
const img = {_n: 'binary', _attrs: {id: image.name, 'content-type': 'image/jpeg'}, _t: image.data};
|
|
||||||
binary.push(img);
|
|
||||||
|
|
||||||
pars.push({_n: 'p', _t: ''});
|
|
||||||
pars.push({_n: 'image', _attrs: {'l:href': `#${image.name}`}});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.formatFb2(fb2);
|
await utils.sleep(100);
|
||||||
|
let i = 0;
|
||||||
|
const imageFiles = files.map(f => {
|
||||||
|
i++;
|
||||||
|
let alt = (outline[i] ? outline[i] : '');
|
||||||
|
return {src: f.name, alt};
|
||||||
|
});
|
||||||
|
return await super.run(data, Object.assign({}, opts, {imageFiles}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,21 +6,37 @@ class ConvertFb2 extends ConvertBase {
|
|||||||
check(data, opts) {
|
check(data, opts) {
|
||||||
const {dataType} = opts;
|
const {dataType} = opts;
|
||||||
|
|
||||||
return (dataType && dataType.ext == 'xml' && data.toString().indexOf('<FictionBook') >= 0);
|
return (
|
||||||
|
( (dataType && dataType.ext == 'xml') || this.isDataXml(data) ) &&
|
||||||
|
data.toString().indexOf('<FictionBook') >= 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(data, opts) {
|
async run(data, opts) {
|
||||||
let newData = data;
|
let newData = data.slice(0, 1024);
|
||||||
|
|
||||||
//Корректируем кодировку, 16-битные кодировки должны стать utf-8
|
//Корректируем кодировку для проверки, 16-битные кодировки должны стать utf-8
|
||||||
const encoding = textUtils.getEncoding(newData);
|
const encoding = textUtils.getEncoding(newData);
|
||||||
if (encoding.indexOf('UTF-16') == 0) {
|
if (encoding.indexOf('UTF-16') == 0) {
|
||||||
newData = Buffer.from(iconv.decode(newData, encoding));
|
newData = Buffer.from(iconv.decode(newData, encoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Проверяем
|
||||||
if (!this.check(newData, opts))
|
if (!this.check(newData, opts))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
//Корректируем кодировку всего объема
|
||||||
|
newData = data;
|
||||||
|
if (encoding.indexOf('UTF-16') == 0) {
|
||||||
|
newData = Buffer.from(iconv.decode(newData, encoding));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Корректируем пробелы, всякие файлы попадаются :(
|
||||||
|
if (newData[0] == 32) {
|
||||||
|
newData = Buffer.from(newData.toString().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Окончательно корректируем кодировку
|
||||||
return this.checkEncoding(newData);
|
return this.checkEncoding(newData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class ConvertFb3 extends ConvertHtml {
|
|||||||
.replace(/<subtitle>/g, '<br><br><fb2-subtitle>')
|
.replace(/<subtitle>/g, '<br><br><fb2-subtitle>')
|
||||||
.replace(/<\/subtitle>/g, '</fb2-subtitle>')
|
.replace(/<\/subtitle>/g, '</fb2-subtitle>')
|
||||||
;
|
;
|
||||||
return await super.run(Buffer.from(text), {skipCheck: true});
|
return await super.run(Buffer.from(text), {skipHtmlCheck: true});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class ConvertHtml extends ConvertBase {
|
|||||||
const {dataType} = opts;
|
const {dataType} = opts;
|
||||||
|
|
||||||
//html?
|
//html?
|
||||||
if (dataType && (dataType.ext == 'html' || dataType.ext == 'xml'))
|
if ( ( (dataType && (dataType.ext == 'html' || dataType.ext == 'xml')) ) || this.isDataXml(data) )
|
||||||
return {isText: false};
|
return {isText: false};
|
||||||
|
|
||||||
//может это чистый текст?
|
//может это чистый текст?
|
||||||
@@ -16,7 +16,7 @@ class ConvertHtml extends ConvertBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//из буфера обмена?
|
//из буфера обмена?
|
||||||
if (data.toString().indexOf('<buffer>') == 0) {
|
if (data.slice(0, 50).toString().indexOf('<buffer>') == 0) {
|
||||||
return {isText: false};
|
return {isText: false};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,15 +24,13 @@ class ConvertHtml extends ConvertBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(data, opts) {
|
async run(data, opts) {
|
||||||
let isText = false;
|
let {isText = false, uploadFileName = ''} = opts;
|
||||||
if (!opts.skipCheck) {
|
if (!opts.skipHtmlCheck) {
|
||||||
const checkResult = this.check(data, opts);
|
const checkResult = this.check(data, opts);
|
||||||
if (!checkResult)
|
if (!checkResult)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
isText = checkResult.isText;
|
isText = checkResult.isText;
|
||||||
} else {
|
|
||||||
isText = opts.isText;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let titleInfo = {};
|
let titleInfo = {};
|
||||||
@@ -242,6 +240,9 @@ class ConvertHtml extends ConvertBase {
|
|||||||
innerCut: new Set(['head', 'script', 'style', 'binary', 'fb2-image', 'fb2-title', 'fb2-author'])
|
innerCut: new Set(['head', 'script', 'style', 'binary', 'fb2-image', 'fb2-title', 'fb2-author'])
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!title)
|
||||||
|
title = uploadFileName;
|
||||||
|
|
||||||
titleInfo['book-title'] = title;
|
titleInfo['book-title'] = title;
|
||||||
if (author)
|
if (author)
|
||||||
titleInfo.author = {'last-name': author};
|
titleInfo.author = {'last-name': author};
|
||||||
|
|||||||
100
server/core/Reader/BookConverter/ConvertJpegPng.js
Normal file
100
server/core/Reader/BookConverter/ConvertJpegPng.js
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
//const utils = require('../../utils');
|
||||||
|
|
||||||
|
const ConvertBase = require('./ConvertBase');
|
||||||
|
|
||||||
|
class ConvertJpegPng extends ConvertBase {
|
||||||
|
check(data, opts) {
|
||||||
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
|
return this.config.useExternalBookConverter &&
|
||||||
|
inputFiles.sourceFileType &&
|
||||||
|
(inputFiles.sourceFileType.ext == 'jpg' || inputFiles.sourceFileType.ext == 'png' );
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
const {inputFiles, uploadFileName, imageFiles} = opts;
|
||||||
|
|
||||||
|
if (!imageFiles) {
|
||||||
|
if (!this.check(data, opts))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let files = [];
|
||||||
|
if (imageFiles) {
|
||||||
|
files = imageFiles;
|
||||||
|
} else {
|
||||||
|
const imageFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}.${inputFiles.sourceFileType.ext}`;
|
||||||
|
await fs.copy(inputFiles.sourceFile, imageFile);
|
||||||
|
files.push({src: imageFile});
|
||||||
|
}
|
||||||
|
|
||||||
|
//читаем изображения
|
||||||
|
const limitSize = 2*this.config.maxUploadFileSize;
|
||||||
|
let imagesSize = 0;
|
||||||
|
|
||||||
|
const loadImage = async(image) => {
|
||||||
|
const src = path.parse(image.src);
|
||||||
|
let type = 'unknown';
|
||||||
|
switch (src.ext) {
|
||||||
|
case '.jpg': type = 'image/jpeg'; break;
|
||||||
|
case '.png': type = 'image/png'; break;
|
||||||
|
}
|
||||||
|
if (type != 'unknown') {
|
||||||
|
image.data = (await fs.readFile(image.src)).toString('base64');
|
||||||
|
image.type = type;
|
||||||
|
image.name = src.base;
|
||||||
|
|
||||||
|
imagesSize += image.data.length;
|
||||||
|
if (imagesSize > limitSize) {
|
||||||
|
throw new Error(`Файл для конвертирования слишком большой|FORLOG| imagesSize: ${imagesSize} > ${limitSize}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let images = [];
|
||||||
|
let loading = [];
|
||||||
|
files.forEach(img => {
|
||||||
|
images.push(img);
|
||||||
|
loading.push(loadImage(img));
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(loading);
|
||||||
|
|
||||||
|
//формируем fb2
|
||||||
|
let titleInfo = {};
|
||||||
|
let desc = {_n: 'description', 'title-info': titleInfo};
|
||||||
|
let pars = [];
|
||||||
|
let body = {_n: 'body', section: {_a: [pars]}};
|
||||||
|
let binary = [];
|
||||||
|
let fb2 = [desc, body, binary];
|
||||||
|
|
||||||
|
let title = '';
|
||||||
|
if (uploadFileName)
|
||||||
|
title = uploadFileName;
|
||||||
|
|
||||||
|
titleInfo['book-title'] = title;
|
||||||
|
|
||||||
|
for (const image of images) {
|
||||||
|
if (image.type) {
|
||||||
|
const img = {_n: 'binary', _attrs: {id: image.name, 'content-type': image.type}, _t: image.data};
|
||||||
|
binary.push(img);
|
||||||
|
|
||||||
|
const attrs = {'l:href': `#${image.name}`};
|
||||||
|
if (image.alt) {
|
||||||
|
image.alt = (image.alt.length > 256 ? image.alt.substring(0, 256) : image.alt);
|
||||||
|
attrs.alt = image.alt;
|
||||||
|
}
|
||||||
|
|
||||||
|
pars.push({_n: 'p', _t: ''});
|
||||||
|
pars.push({_n: 'image', _attrs: attrs});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pars.push({_n: 'p', _t: ''});
|
||||||
|
|
||||||
|
return this.formatFb2(fb2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertJpegPng;
|
||||||
@@ -5,7 +5,6 @@ const path = require('path');
|
|||||||
const sax = require('../../sax');
|
const sax = require('../../sax');
|
||||||
const utils = require('../../utils');
|
const utils = require('../../utils');
|
||||||
const ConvertHtml = require('./ConvertHtml');
|
const ConvertHtml = require('./ConvertHtml');
|
||||||
const xmlParser = require('../../xmlParser');
|
|
||||||
|
|
||||||
class ConvertPdf extends ConvertHtml {
|
class ConvertPdf extends ConvertHtml {
|
||||||
check(data, opts) {
|
check(data, opts) {
|
||||||
@@ -16,7 +15,7 @@ class ConvertPdf extends ConvertHtml {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(notUsed, opts) {
|
async run(notUsed, opts) {
|
||||||
if (!this.check(notUsed, opts))
|
if (!opts.pdfAsText || !this.check(notUsed, opts))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
await this.checkExternalConverterPresent();
|
await this.checkExternalConverterPresent();
|
||||||
@@ -26,16 +25,14 @@ class ConvertPdf extends ConvertHtml {
|
|||||||
const inpFile = inputFiles.sourceFile;
|
const inpFile = inputFiles.sourceFile;
|
||||||
const outBasename = `${inputFiles.filesDir}/${utils.randomHexString(10)}`;
|
const outBasename = `${inputFiles.filesDir}/${utils.randomHexString(10)}`;
|
||||||
const outFile = `${outBasename}.xml`;
|
const outFile = `${outBasename}.xml`;
|
||||||
const metaFile = `${outBasename}_metadata.xml`;
|
|
||||||
|
|
||||||
const pdfaltoPath = `${this.config.dataDir}/pdfalto/pdfalto`;
|
const pdftohtmlPath = '/usr/bin/pdftohtml';
|
||||||
|
if (!await fs.pathExists(pdftohtmlPath))
|
||||||
if (!await fs.pathExists(pdfaltoPath))
|
throw new Error('Внешний конвертер pdftohtml не найден');
|
||||||
throw new Error('Внешний конвертер pdfalto не найден');
|
|
||||||
|
|
||||||
//конвертируем в xml
|
//конвертируем в xml
|
||||||
let perc = 0;
|
let perc = 0;
|
||||||
await this.execConverter(pdfaltoPath, [inpFile, outFile], () => {
|
await this.execConverter(pdftohtmlPath, ['-nodrm', '-c', '-s', '-xml', inpFile, outFile], () => {
|
||||||
perc = (perc < 80 ? perc + 10 : 40);
|
perc = (perc < 80 ? perc + 10 : 40);
|
||||||
callback(perc);
|
callback(perc);
|
||||||
}, abort);
|
}, abort);
|
||||||
@@ -57,8 +54,10 @@ class ConvertPdf extends ConvertHtml {
|
|||||||
let images = [];
|
let images = [];
|
||||||
let loading = [];
|
let loading = [];
|
||||||
|
|
||||||
let title = '';
|
let inText = false;
|
||||||
let author = '';
|
let bold = false;
|
||||||
|
let italic = false;
|
||||||
|
|
||||||
let i = -1;
|
let i = -1;
|
||||||
|
|
||||||
const loadImage = async(image) => {
|
const loadImage = async(image) => {
|
||||||
@@ -85,22 +84,30 @@ class ConvertPdf extends ConvertHtml {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isTextBold = (text) => {
|
||||||
|
const m = text.trim().match(/^<b>(.*)<\/b>$/);
|
||||||
|
return m && !m[1].match(/<b>|<\/b>|<i>|<\/i>/g);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isTextEmpty = (text) => {
|
||||||
|
return text.replace(/<b>|<\/b>|<i>|<\/i>/g, '').trim() == '';
|
||||||
|
};
|
||||||
|
|
||||||
const putPageLines = () => {
|
const putPageLines = () => {
|
||||||
pagelines.sort((a, b) => (a.top - b.top)*10000 + (a.left - b.left))
|
pagelines.sort((a, b) => (Math.abs(a.top - b.top) > 3 ? a.top - b.top : 0)*10000 + (a.left - b.left))
|
||||||
|
|
||||||
//объединяем в одну строку равные по высоте
|
//объединяем в одну строку равные по высоте
|
||||||
const pl = [];
|
const pl = [];
|
||||||
let pt = 0;
|
let pt = 0;
|
||||||
let j = -1;
|
let j = -1;
|
||||||
pagelines.forEach(line => {
|
pagelines.forEach(line => {
|
||||||
//добавим закрывающий тег стиля
|
if (isTextEmpty(line.text))
|
||||||
line.text += line.tClose;
|
return;
|
||||||
|
|
||||||
//проверим, возможно это заголовок
|
//проверим, возможно это заголовок
|
||||||
if (line.fonts.length == 1 && line.pageWidth) {
|
if (line.fontId && line.pageWidth) {
|
||||||
const f = (line.fonts.length ? fonts[line.fonts[0]] : null);
|
|
||||||
const centerLeft = (line.pageWidth - line.width)/2;
|
const centerLeft = (line.pageWidth - line.width)/2;
|
||||||
if (f && f.isBold && Math.abs(centerLeft - line.left) < 3) {
|
if (isTextBold(line.text) && Math.abs(centerLeft - line.left) < 10) {
|
||||||
if (!sectionTitleFound) {
|
if (!sectionTitleFound) {
|
||||||
line.isSectionTitle = true;
|
line.isSectionTitle = true;
|
||||||
sectionTitleFound = true;
|
sectionTitleFound = true;
|
||||||
@@ -128,7 +135,7 @@ class ConvertPdf extends ConvertHtml {
|
|||||||
//добавим пустую строку, если надо
|
//добавим пустую строку, если надо
|
||||||
const prevLine = (i > lastIndex ? lines[i] : {fonts: [], top: 0});
|
const prevLine = (i > lastIndex ? lines[i] : {fonts: [], top: 0});
|
||||||
if (prevLine && !prevLine.isImage) {
|
if (prevLine && !prevLine.isImage) {
|
||||||
const f = (prevLine.fonts.length ? fonts[prevLine.fonts[0]] : (line.fonts.length ? fonts[line.fonts[0]] : null));
|
const f = (prevLine.fontId ? fonts[prevLine.fontId] : (line.fontId ? fonts[line.fontId] : null));
|
||||||
if (f && f.fontSize && !line.isImage && line.top - prevLine.top > f.fontSize * 1.8) {
|
if (f && f.fontSize && !line.isImage && line.top - prevLine.top > f.fontSize * 1.8) {
|
||||||
i++;
|
i++;
|
||||||
lines[i] = {text: '<br>'};
|
lines[i] = {text: '<br>'};
|
||||||
@@ -142,29 +149,26 @@ class ConvertPdf extends ConvertHtml {
|
|||||||
putImage(100000);
|
putImage(100000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onTextNode = (text, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (!cutCounter && inText) {
|
||||||
|
let tOpen = (bold ? '<b>' : '');
|
||||||
|
tOpen += (italic ? '<i>' : '');
|
||||||
|
let tClose = (italic ? '</i>' : '');
|
||||||
|
tClose += (bold ? '</b>' : '');
|
||||||
|
|
||||||
|
line.text += ` ${tOpen}${text}${tClose}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const onStartNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
const onStartNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
if (tag == 'textstyle') {
|
if (inText) {
|
||||||
const attrs = sax.getAttrsSync(tail);
|
switch (tag) {
|
||||||
const fontId = (attrs.id && attrs.id.value ? attrs.id.value : '');
|
case 'i':
|
||||||
const fontStyle = (attrs.fontstyle && attrs.fontstyle.value ? attrs.fontstyle.value : '');
|
italic = true;
|
||||||
const fontSize = (attrs.fontsize && attrs.fontsize.value ? attrs.fontsize.value : '');
|
break;
|
||||||
|
case 'b':
|
||||||
if (fontId) {
|
bold = true;
|
||||||
const styleTags = {bold: 'b', italics: 'i', superscript: 'sup', subscript: 'sub'};
|
break;
|
||||||
const f = fonts[fontId] = {tOpen: '', tClose: '', isBold: false, fontSize};
|
|
||||||
|
|
||||||
if (fontStyle) {
|
|
||||||
const styles = fontStyle.split(' ');
|
|
||||||
styles.forEach(style => {
|
|
||||||
const s = styleTags[style];
|
|
||||||
if (s) {
|
|
||||||
f.tOpen += `<${s}>`;
|
|
||||||
f.tClose = `</${s}>${f.tClose}`;
|
|
||||||
if (s == 'b')
|
|
||||||
f.isBold = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,80 +181,78 @@ class ConvertPdf extends ConvertHtml {
|
|||||||
putPageLines();
|
putPageLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'textline') {
|
if (tag == 'fontspec') {
|
||||||
|
const attrs = sax.getAttrsSync(tail);
|
||||||
|
const fontId = (attrs.id && attrs.id.value ? attrs.id.value : '');
|
||||||
|
const fontSize = (attrs.size && attrs.size.value ? attrs.size.value : '');
|
||||||
|
|
||||||
|
if (fontId) {
|
||||||
|
fonts[fontId] = {fontSize};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'text' && !inText) {
|
||||||
const attrs = sax.getAttrsSync(tail);
|
const attrs = sax.getAttrsSync(tail);
|
||||||
line = {
|
line = {
|
||||||
text: '',
|
text: '',
|
||||||
top: parseInt((attrs.vpos && attrs.vpos.value ? attrs.vpos.value : null), 10),
|
top: parseInt((attrs.top && attrs.top.value ? attrs.top.value : null), 10),
|
||||||
left: parseInt((attrs.hpos && attrs.hpos.value ? attrs.hpos.value : null), 10),
|
left: parseInt((attrs.left && attrs.left.value ? attrs.left.value : null), 10),
|
||||||
width: parseInt((attrs.width && attrs.width.value ? attrs.width.value : null), 10),
|
width: parseInt((attrs.width && attrs.width.value ? attrs.width.value : null), 10),
|
||||||
height: parseInt((attrs.height && attrs.height.value ? attrs.height.value : null), 10),
|
height: parseInt((attrs.height && attrs.height.value ? attrs.height.value : null), 10),
|
||||||
tOpen: '',
|
|
||||||
tClose: '',
|
|
||||||
isSectionTitle: false,
|
isSectionTitle: false,
|
||||||
isSubtitle: false,
|
isSubtitle: false,
|
||||||
pageWidth: page.width,
|
pageWidth: page.width,
|
||||||
fonts: [],
|
fontId: (attrs.font && attrs.font.value ? attrs.font.value : ''),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (line.width != 0 || line.height != 0) {
|
if (line.width != 0 || line.height != 0) {
|
||||||
|
inText = true;
|
||||||
pagelines.push(line);
|
pagelines.push(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'string') {
|
if (tag == 'image') {
|
||||||
const attrs = sax.getAttrsSync(tail);
|
const attrs = sax.getAttrsSync(tail);
|
||||||
if (attrs.content && attrs.content.value) {
|
let src = (attrs.src && attrs.src.value ? attrs.src.value : '');
|
||||||
|
|
||||||
let tOpen = '';
|
|
||||||
let tClose = '';
|
|
||||||
const fontId = (attrs.stylerefs && attrs.stylerefs.value ? attrs.stylerefs.value : '');
|
|
||||||
if (fontId && fonts[fontId]) {
|
|
||||||
tOpen = fonts[fontId].tOpen;
|
|
||||||
tClose = fonts[fontId].tClose;
|
|
||||||
if (!line.fonts.length || line.fonts[0] != fontId)
|
|
||||||
line.fonts.push(fontId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.tOpen != tOpen) {
|
|
||||||
line.text += line.tClose + tOpen;
|
|
||||||
line.tOpen = tOpen;
|
|
||||||
line.tClose = tClose;
|
|
||||||
}
|
|
||||||
|
|
||||||
line.text += `${line.text.length ? ' ' : ''}${attrs.content.value}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tag == 'illustration') {
|
|
||||||
const attrs = sax.getAttrsSync(tail);
|
|
||||||
if (attrs.type && attrs.type.value == 'image') {
|
|
||||||
let src = (attrs.fileid && attrs.fileid.value ? attrs.fileid.value : '');
|
|
||||||
if (src) {
|
if (src) {
|
||||||
const image = {
|
const image = {
|
||||||
isImage: true,
|
isImage: true,
|
||||||
src,
|
src,
|
||||||
data: '',
|
data: '',
|
||||||
type: '',
|
type: '',
|
||||||
top: parseInt((attrs.vpos && attrs.vpos.value ? attrs.vpos.value : null), 10) || 0,
|
top: parseInt((attrs.top && attrs.top.value ? attrs.top.value : null), 10) || 0,
|
||||||
left: parseInt((attrs.hpos && attrs.hpos.value ? attrs.hpos.value : null), 10) || 0,
|
left: parseInt((attrs.left && attrs.left.value ? attrs.left.value : null), 10) || 0,
|
||||||
width: parseInt((attrs.width && attrs.width.value ? attrs.width.value : null), 10) || 0,
|
width: parseInt((attrs.width && attrs.width.value ? attrs.width.value : null), 10) || 0,
|
||||||
height: parseInt((attrs.height && attrs.height.value ? attrs.height.value : null), 10) || 0,
|
height: parseInt((attrs.height && attrs.height.value ? attrs.height.value : null), 10) || 0,
|
||||||
};
|
};
|
||||||
const exists = images.filter(img => (img.top == image.top && img.left == image.left && img.width == image.width && img.height == image.height));
|
|
||||||
if (!exists.length) {
|
|
||||||
loading.push(loadImage(image));
|
loading.push(loadImage(image));
|
||||||
images.push(image);
|
images.push(image);
|
||||||
images.sort((a, b) => (a.top - b.top)*10000 + (a.left - b.left));
|
images.sort((a, b) => (a.top - b.top)*10000 + (a.left - b.left));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onEndNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (inText) {
|
||||||
|
switch (tag) {
|
||||||
|
case 'i':
|
||||||
|
italic = false;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
bold = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag == 'text')
|
||||||
|
inText = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
let buf = this.decode(data).toString();
|
let buf = this.decode(data).toString();
|
||||||
sax.parseSync(buf, {
|
sax.parseSync(buf, {
|
||||||
onStartNode
|
onStartNode, onEndNode, onTextNode
|
||||||
});
|
});
|
||||||
|
|
||||||
putPageLines();
|
putPageLines();
|
||||||
@@ -277,16 +279,8 @@ class ConvertPdf extends ConvertHtml {
|
|||||||
}
|
}
|
||||||
indents[0] = 0;
|
indents[0] = 0;
|
||||||
|
|
||||||
//title
|
//author & title
|
||||||
if (fs.pathExists(metaFile)) {
|
let {author, title} = await this.getPdfTitleAndAuthor(inpFile);
|
||||||
const metaXmlString = (await fs.readFile(metaFile)).toString();
|
|
||||||
let metaXmlParsed = xmlParser.parseXml(metaXmlString);
|
|
||||||
metaXmlParsed = xmlParser.simplifyXmlParsed(metaXmlParsed);
|
|
||||||
if (metaXmlParsed.metadata) {
|
|
||||||
title = (metaXmlParsed.metadata.title ? metaXmlParsed.metadata.title._t : '');
|
|
||||||
author = (metaXmlParsed.metadata.author ? metaXmlParsed.metadata.author._t : '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!title && uploadFileName)
|
if (!title && uploadFileName)
|
||||||
title = uploadFileName;
|
title = uploadFileName;
|
||||||
@@ -302,6 +296,7 @@ class ConvertPdf extends ConvertHtml {
|
|||||||
|
|
||||||
let concat = '';
|
let concat = '';
|
||||||
let sp = '';
|
let sp = '';
|
||||||
|
let firstLine = true;
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (text.length > limitSize) {
|
if (text.length > limitSize) {
|
||||||
throw new Error(`Файл для конвертирования слишком большой|FORLOG| text.length: ${text.length} > ${limitSize}`);
|
throw new Error(`Файл для конвертирования слишком большой|FORLOG| text.length: ${text.length} > ${limitSize}`);
|
||||||
@@ -313,10 +308,15 @@ class ConvertPdf extends ConvertHtml {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (line.isSectionTitle) {
|
if (line.isSectionTitle) {
|
||||||
|
if (firstLine)
|
||||||
text += `<fb2-section-title>${line.text.trim()}</fb2-section-title>`;
|
text += `<fb2-section-title>${line.text.trim()}</fb2-section-title>`;
|
||||||
|
else
|
||||||
|
text += `<fb2-subtitle>${line.text.trim()}</fb2-subtitle>`;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
firstLine = false;
|
||||||
|
|
||||||
if (line.isSubtitle) {
|
if (line.isSubtitle) {
|
||||||
text += `<br><fb2-subtitle>${line.text.trim()}</fb2-subtitle>`;
|
text += `<br><fb2-subtitle>${line.text.trim()}</fb2-subtitle>`;
|
||||||
continue;
|
continue;
|
||||||
@@ -341,8 +341,34 @@ class ConvertPdf extends ConvertHtml {
|
|||||||
|
|
||||||
//console.log(text);
|
//console.log(text);
|
||||||
await utils.sleep(100);
|
await utils.sleep(100);
|
||||||
return await super.run(Buffer.from(text), {skipCheck: true, isText: true});
|
return await super.run(Buffer.from(text), {skipHtmlCheck: true, isText: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPdfTitleAndAuthor(pdfFile) {
|
||||||
|
const result = {author: '', title: ''};
|
||||||
|
|
||||||
|
const pdfinfoPath = '/usr/bin/pdfinfo';
|
||||||
|
|
||||||
|
if (!await fs.pathExists(pdfinfoPath))
|
||||||
|
throw new Error('Внешний конвертер pdfinfo не найден');
|
||||||
|
|
||||||
|
const execResult = await this.execConverter(pdfinfoPath, [pdfFile]);
|
||||||
|
|
||||||
|
const titlePrefix = 'Title:';
|
||||||
|
const authorPrefix = 'Author:';
|
||||||
|
|
||||||
|
const stdout = execResult.stdout.split("\n");
|
||||||
|
stdout.forEach(line => {
|
||||||
|
if (line.indexOf(titlePrefix) == 0)
|
||||||
|
result.title = line.substring(titlePrefix.length).trim();
|
||||||
|
|
||||||
|
if (line.indexOf(authorPrefix) == 0)
|
||||||
|
result.author = line.substring(authorPrefix.length).trim();
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = ConvertPdf;
|
module.exports = ConvertPdf;
|
||||||
|
|||||||
115
server/core/Reader/BookConverter/ConvertPdfImages.js
Normal file
115
server/core/Reader/BookConverter/ConvertPdfImages.js
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
const utils = require('../../utils');
|
||||||
|
|
||||||
|
const sax = require('../../sax');
|
||||||
|
|
||||||
|
const ConvertJpegPng = require('./ConvertJpegPng');
|
||||||
|
|
||||||
|
class ConvertPdfImages extends ConvertJpegPng {
|
||||||
|
check(data, opts) {
|
||||||
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
|
return this.config.useExternalBookConverter &&
|
||||||
|
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'pdf';
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
if (!this.check(data, opts))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
let {inputFiles, callback, abort, pdfQuality} = opts;
|
||||||
|
|
||||||
|
pdfQuality = (pdfQuality && pdfQuality <= 100 && pdfQuality >= 10 ? pdfQuality : 20);
|
||||||
|
|
||||||
|
const pdftoppmPath = '/usr/bin/pdftoppm';
|
||||||
|
if (!await fs.pathExists(pdftoppmPath))
|
||||||
|
throw new Error('Внешний конвертер pdftoppm не найден');
|
||||||
|
|
||||||
|
const pdftohtmlPath = '/usr/bin/pdftohtml';
|
||||||
|
if (!await fs.pathExists(pdftohtmlPath))
|
||||||
|
throw new Error('Внешний конвертер pdftohtml не найден');
|
||||||
|
|
||||||
|
const inpFile = inputFiles.sourceFile;
|
||||||
|
const dir = `${inputFiles.filesDir}/`;
|
||||||
|
const outBasename = `${dir}${utils.randomHexString(10)}`;
|
||||||
|
const outFile = `${outBasename}.tmp`;
|
||||||
|
|
||||||
|
//конвертируем в jpeg
|
||||||
|
let perc = 0;
|
||||||
|
await this.execConverter(pdftoppmPath, ['-jpeg', '-jpegopt', `quality=${pdfQuality},progressive=y`, inpFile, outFile], () => {
|
||||||
|
perc = (perc < 100 ? perc + 1 : 40);
|
||||||
|
callback(perc);
|
||||||
|
}, abort);
|
||||||
|
|
||||||
|
const limitSize = 2*this.config.maxUploadFileSize;
|
||||||
|
let jpgFilesSize = 0;
|
||||||
|
|
||||||
|
//ищем изображения
|
||||||
|
let files = [];
|
||||||
|
await utils.findFiles(async(file) => {
|
||||||
|
if (path.extname(file) == '.jpg') {
|
||||||
|
jpgFilesSize += (await fs.stat(file)).size;
|
||||||
|
if (jpgFilesSize > limitSize) {
|
||||||
|
throw new Error(`Файл для конвертирования слишком большой|FORLOG| jpgFilesSize: ${jpgFilesSize} > ${limitSize}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
files.push({name: file, base: path.basename(file)});
|
||||||
|
}
|
||||||
|
}, dir);
|
||||||
|
|
||||||
|
files.sort((a, b) => a.base.localeCompare(b.base));
|
||||||
|
|
||||||
|
//схема документа (outline)
|
||||||
|
const outXml = `${outBasename}.xml`;
|
||||||
|
await this.execConverter(pdftohtmlPath, ['-nodrm', '-i', '-c', '-s', '-xml', inpFile, outXml], null, abort);
|
||||||
|
const outline = [];
|
||||||
|
|
||||||
|
let inOutline = 0;
|
||||||
|
let inItem = false;
|
||||||
|
let pageNum = 0;
|
||||||
|
|
||||||
|
const onTextNode = (text, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (inOutline > 0 && inItem && pageNum) {
|
||||||
|
outline[pageNum] = text;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onStartNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (tag == 'outline')
|
||||||
|
inOutline++;
|
||||||
|
|
||||||
|
if (inOutline > 0 && tag == 'item') {
|
||||||
|
const attrs = sax.getAttrsSync(tail);
|
||||||
|
pageNum = (attrs.page && attrs.page.value ? attrs.page.value : 0);
|
||||||
|
inItem = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onEndNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (tag == 'outline')
|
||||||
|
inOutline--;
|
||||||
|
if (tag == 'item')
|
||||||
|
inItem = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataXml = await fs.readFile(outXml);
|
||||||
|
const buf = this.decode(dataXml).toString();
|
||||||
|
sax.parseSync(buf, {
|
||||||
|
onStartNode, onEndNode, onTextNode
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
await utils.sleep(100);
|
||||||
|
//формируем список файлов
|
||||||
|
let i = 0;
|
||||||
|
const imageFiles = files.map(f => {
|
||||||
|
i++;
|
||||||
|
let alt = (outline[i] ? outline[i] : '');
|
||||||
|
return {src: f.name, alt};
|
||||||
|
});
|
||||||
|
return await super.run(data, Object.assign({}, opts, {imageFiles}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertPdfImages;
|
||||||
@@ -48,7 +48,7 @@ class ConvertSites extends ConvertHtml {
|
|||||||
if (text === false)
|
if (text === false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return await super.run(Buffer.from(text), {skipCheck: true});
|
return await super.run(Buffer.from(text), {skipHtmlCheck: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
getTitle(text) {
|
getTitle(text) {
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ const FileDetector = require('../../FileDetector');
|
|||||||
|
|
||||||
//порядок важен
|
//порядок важен
|
||||||
const convertClassFactory = [
|
const convertClassFactory = [
|
||||||
|
require('./ConvertJpegPng'),
|
||||||
require('./ConvertEpub'),
|
require('./ConvertEpub'),
|
||||||
require('./ConvertDjvu'),
|
require('./ConvertDjvu'),
|
||||||
require('./ConvertPdf'),
|
require('./ConvertPdf'),
|
||||||
|
require('./ConvertPdfImages'),
|
||||||
require('./ConvertRtf'),
|
require('./ConvertRtf'),
|
||||||
require('./ConvertDocX'),
|
require('./ConvertDocX'),
|
||||||
require('./ConvertFb3'),
|
require('./ConvertFb3'),
|
||||||
|
|||||||
Reference in New Issue
Block a user