Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0341cc1630 | ||
|
|
d307d233f0 | ||
|
|
5931b9625b | ||
|
|
fb837f5b97 | ||
|
|
8cfe95b3cf | ||
|
|
5fd73ac1e1 | ||
|
|
b51a574038 | ||
|
|
51b39f0775 | ||
|
|
17c4f96c94 | ||
|
|
89bf907613 | ||
|
|
641d0e45fd | ||
|
|
b3e579d8b7 | ||
|
|
fcb61c89d5 | ||
|
|
3483d78c2c | ||
|
|
36b14d0b3a | ||
|
|
2f8b68ec62 | ||
|
|
cb65cac333 | ||
|
|
d12ffc3d0d | ||
|
|
921744167e | ||
|
|
ebd96c4759 | ||
|
|
dd9876fc43 | ||
|
|
e0de614f30 | ||
|
|
30260883fb | ||
|
|
91c331e5f3 | ||
|
|
db803bcd23 | ||
|
|
cd482ea890 | ||
|
|
a2497c939a | ||
|
|
2e5249d30b | ||
|
|
b1d60c19d5 | ||
|
|
d28a82b33a | ||
|
|
787821f64b | ||
|
|
612b15fecc | ||
|
|
d88d5a1352 | ||
|
|
8584ddd00e | ||
|
|
4f572b5a10 | ||
|
|
90a0882c59 | ||
|
|
759344bb34 | ||
|
|
c9b65a3c43 | ||
|
|
b06e600946 | ||
|
|
2777751e54 | ||
|
|
b4493b2e8d | ||
|
|
55d5f6524d | ||
|
|
c7d376adf2 | ||
|
|
56bf69a770 | ||
|
|
22f9287d8b | ||
|
|
ca47d9272c | ||
|
|
0d61f5523a | ||
|
|
863ea9089a | ||
|
|
ad2af95ebd | ||
|
|
d65092c203 |
@@ -5,8 +5,7 @@ const stream = require('stream');
|
|||||||
const pipeline = util.promisify(stream.pipeline);
|
const pipeline = util.promisify(stream.pipeline);
|
||||||
|
|
||||||
const got = require('got');
|
const got = require('got');
|
||||||
const decompress = require('decompress');
|
const FileDecompressor = require('../server/core/FileDecompressor');
|
||||||
const decompressTargz = require('decompress-targz');
|
|
||||||
|
|
||||||
const distDir = path.resolve(__dirname, '../dist');
|
const distDir = path.resolve(__dirname, '../dist');
|
||||||
const publicDir = `${distDir}/tmp/public`;
|
const publicDir = `${distDir}/tmp/public`;
|
||||||
@@ -15,6 +14,8 @@ const outDir = `${distDir}/linux`;
|
|||||||
const tempDownloadDir = `${distDir}/tmp/download`;
|
const tempDownloadDir = `${distDir}/tmp/download`;
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
const decomp = new FileDecompressor();
|
||||||
|
|
||||||
await fs.emptyDir(outDir);
|
await fs.emptyDir(outDir);
|
||||||
// перемещаем public на место
|
// перемещаем public на место
|
||||||
if (await fs.pathExists(publicDir))
|
if (await fs.pathExists(publicDir))
|
||||||
@@ -32,11 +33,7 @@ async function main() {
|
|||||||
console.log(`done downloading ${sqliteRemoteUrl}`);
|
console.log(`done downloading ${sqliteRemoteUrl}`);
|
||||||
|
|
||||||
//распаковываем
|
//распаковываем
|
||||||
await decompress(`${tempDownloadDir}/sqlite.tar.gz`, `${tempDownloadDir}`, {
|
console.log(await decomp.unpackTarZZ(`${tempDownloadDir}/sqlite.tar.gz`, tempDownloadDir));
|
||||||
plugins: [
|
|
||||||
decompressTargz()
|
|
||||||
]
|
|
||||||
});
|
|
||||||
console.log('files decompressed');
|
console.log('files decompressed');
|
||||||
}
|
}
|
||||||
// копируем в дистрибутив
|
// копируем в дистрибутив
|
||||||
@@ -53,11 +50,7 @@ async function main() {
|
|||||||
console.log(`done downloading ${ipfsRemoteUrl}`);
|
console.log(`done downloading ${ipfsRemoteUrl}`);
|
||||||
|
|
||||||
//распаковываем
|
//распаковываем
|
||||||
await decompress(`${tempDownloadDir}/ipfs.tar.gz`, `${tempDownloadDir}`, {
|
console.log(await decomp.unpackTarZZ(`${tempDownloadDir}/ipfs.tar.gz`, tempDownloadDir));
|
||||||
plugins: [
|
|
||||||
decompressTargz()
|
|
||||||
]
|
|
||||||
});
|
|
||||||
console.log('files decompressed');
|
console.log('files decompressed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
build/win.js
13
build/win.js
@@ -5,8 +5,7 @@ const stream = require('stream');
|
|||||||
const pipeline = util.promisify(stream.pipeline);
|
const pipeline = util.promisify(stream.pipeline);
|
||||||
|
|
||||||
const got = require('got');
|
const got = require('got');
|
||||||
const decompress = require('decompress');
|
const FileDecompressor = require('../server/core/FileDecompressor');
|
||||||
const decompressTargz = require('decompress-targz');
|
|
||||||
|
|
||||||
const distDir = path.resolve(__dirname, '../dist');
|
const distDir = path.resolve(__dirname, '../dist');
|
||||||
const publicDir = `${distDir}/tmp/public`;
|
const publicDir = `${distDir}/tmp/public`;
|
||||||
@@ -15,6 +14,8 @@ const outDir = `${distDir}/win`;
|
|||||||
const tempDownloadDir = `${distDir}/tmp/download`;
|
const tempDownloadDir = `${distDir}/tmp/download`;
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
const decomp = new FileDecompressor();
|
||||||
|
|
||||||
await fs.emptyDir(outDir);
|
await fs.emptyDir(outDir);
|
||||||
// перемещаем public на место
|
// перемещаем public на место
|
||||||
if (await fs.pathExists(publicDir))
|
if (await fs.pathExists(publicDir))
|
||||||
@@ -32,11 +33,7 @@ async function main() {
|
|||||||
console.log(`done downloading ${sqliteRemoteUrl}`);
|
console.log(`done downloading ${sqliteRemoteUrl}`);
|
||||||
|
|
||||||
//распаковываем
|
//распаковываем
|
||||||
await decompress(`${tempDownloadDir}/sqlite.tar.gz`, `${tempDownloadDir}`, {
|
console.log(await decomp.unpackTarZZ(`${tempDownloadDir}/sqlite.tar.gz`, tempDownloadDir));
|
||||||
plugins: [
|
|
||||||
decompressTargz()
|
|
||||||
]
|
|
||||||
});
|
|
||||||
console.log('files decompressed');
|
console.log('files decompressed');
|
||||||
}
|
}
|
||||||
// копируем в дистрибутив
|
// копируем в дистрибутив
|
||||||
@@ -53,7 +50,7 @@ async function main() {
|
|||||||
console.log(`done downloading ${ipfsRemoteUrl}`);
|
console.log(`done downloading ${ipfsRemoteUrl}`);
|
||||||
|
|
||||||
//распаковываем
|
//распаковываем
|
||||||
await decompress(`${tempDownloadDir}/ipfs.zip`, `${tempDownloadDir}`);
|
console.log(await decomp.unpack(`${tempDownloadDir}/ipfs.zip`, tempDownloadDir));
|
||||||
console.log('files decompressed');
|
console.log('files decompressed');
|
||||||
}
|
}
|
||||||
// копируем в дистрибутив
|
// копируем в дистрибутив
|
||||||
|
|||||||
@@ -49,8 +49,9 @@ class Reader {
|
|||||||
}
|
}
|
||||||
//проверка воркера
|
//проверка воркера
|
||||||
const prevProgress = response.data.progress;
|
const prevProgress = response.data.progress;
|
||||||
|
const prevState = response.data.state;
|
||||||
response = await workerApi.post('/get-state', {workerId});
|
response = await workerApi.post('/get-state', {workerId});
|
||||||
i = (prevProgress != response.data.progress ? 1 : i);
|
i = (prevProgress != response.data.progress || prevState != response.data.state ? 1 : i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<p>В качестве URL можно задавать html-страничку с книгой, либо прямую ссылку
|
<p>В качестве URL можно задавать html-страничку с книгой, либо прямую ссылку
|
||||||
на файл из онлайн-библиотеки (например, скопировав адрес ссылки или кнопки "скачать fb2").</p>
|
на файл из онлайн-библиотеки (например, скопировав адрес ссылки или кнопки "скачать fb2").</p>
|
||||||
<p>Поддерживаемые форматы: <strong>html, txt, fb2, fb2.zip</strong></p>
|
<p>Поддерживаемые форматы: <b>fb2, fb2.zip, html, txt</b> и другие</p>
|
||||||
|
|
||||||
<div v-html="automationHtml"></div>
|
<div v-html="automationHtml"></div>
|
||||||
<p>Связаться с разработчиком: <a href="mailto:bookpauk@gmail.com">bookpauk@gmail.com</a></p>
|
<p>Связаться с разработчиком: <a href="mailto:bookpauk@gmail.com">bookpauk@gmail.com</a></p>
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
<div ref="main" class="main">
|
<div ref="main" class="main">
|
||||||
<div class="part">
|
<div class="part">
|
||||||
<span class="greeting bold-font">{{ title }}</span>
|
<span class="greeting bold-font">{{ title }}</span>
|
||||||
|
<div class="space"></div>
|
||||||
<span class="greeting">Добро пожаловать!</span>
|
<span class="greeting">Добро пожаловать!</span>
|
||||||
<span class="greeting">Поддерживаются форматы: <b>fb2, html, txt</b></span>
|
<span class="greeting">Поддерживаются форматы: <b>fb2, html, txt</b> и сжатие: <b>zip, bz2, gz</b></span>
|
||||||
<span v-if="isExternalConverter" class="greeting">...а также: <b>rtf, doc, docx</b>, и вскоре: pdf, epub, mobi</span>
|
<span v-if="isExternalConverter" class="greeting">...а также форматы: <b>rtf, doc, docx, pdf, epub, mobi</b></span>
|
||||||
<span class="greeting">...и распознается сжатие: <b>zip, bz2, gz</b></span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="part center">
|
<div class="part center">
|
||||||
@@ -130,6 +130,7 @@ class LoaderPage extends Vue {
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
min-height: 340px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.part {
|
.part {
|
||||||
@@ -141,8 +142,8 @@ class LoaderPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.greeting {
|
.greeting {
|
||||||
font-size: 130%;
|
font-size: 120%;
|
||||||
line-height: 170%;
|
line-height: 160%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bold-font {
|
.bold-font {
|
||||||
|
|||||||
@@ -340,8 +340,8 @@ class Reader extends Vue {
|
|||||||
this.setPositionActive = true;
|
this.setPositionActive = true;
|
||||||
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$refs.setPositionPage.sliderMax = this.mostRecentBook().textLength - 1;
|
const recent = this.mostRecentBook();
|
||||||
this.$refs.setPositionPage.sliderValue = this.mostRecentBook().bookPos;
|
this.$refs.setPositionPage.init(recent.bookPos, recent.textLength - 1);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setPositionActive = false;
|
this.setPositionActive = false;
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import Component from 'vue-class-component';
|
import Component from 'vue-class-component';
|
||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
import Window from '../../share/Window.vue';
|
import Window from '../../share/Window.vue';
|
||||||
|
|
||||||
@@ -28,7 +27,8 @@ export default @Component({
|
|||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
sliderValue: function(newValue) {
|
sliderValue: function(newValue) {
|
||||||
this.$emit('book-pos-changed', {bookPos: newValue});
|
if (this.initialized)
|
||||||
|
this.$emit('book-pos-changed', {bookPos: newValue});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -39,6 +39,13 @@ class SetPositionPage extends Vue {
|
|||||||
created() {
|
created() {
|
||||||
this.commit = this.$store.commit;
|
this.commit = this.$store.commit;
|
||||||
this.reader = this.$store.state.reader;
|
this.reader = this.$store.state.reader;
|
||||||
|
this.initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
init(sliderValue, sliderMax) {
|
||||||
|
this.sliderMax = sliderMax;
|
||||||
|
this.sliderValue = sliderValue;
|
||||||
|
this.initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
formatTooltip(val) {
|
formatTooltip(val) {
|
||||||
|
|||||||
@@ -251,7 +251,7 @@
|
|||||||
<el-form :model="form" size="mini" label-width="120px" @submit.native.prevent>
|
<el-form :model="form" size="mini" label-width="120px" @submit.native.prevent>
|
||||||
<div class="partHeader">Анимация</div>
|
<div class="partHeader">Анимация</div>
|
||||||
|
|
||||||
<el-form-item label="Вид">
|
<el-form-item label="Тип">
|
||||||
<el-col :span="11">
|
<el-col :span="11">
|
||||||
<el-select v-model="pageChangeAnimation">
|
<el-select v-model="pageChangeAnimation">
|
||||||
<el-option label="Нет" value=""></el-option>
|
<el-option label="Нет" value=""></el-option>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export default class DrawHelper {
|
|||||||
|
|
||||||
let out = `<div style="width: ${this.w}px; height: ${this.h + (isScrolling ? this.lineHeight : 0)}px;` +
|
let out = `<div style="width: ${this.w}px; height: ${this.h + (isScrolling ? this.lineHeight : 0)}px;` +
|
||||||
` position: absolute; top: ${this.fontSize*this.textShift}px; color: ${this.textColor}; font: ${font}; ${justify}` +
|
` position: absolute; top: ${this.fontSize*this.textShift}px; color: ${this.textColor}; font: ${font}; ${justify}` +
|
||||||
` line-height: ${this.lineHeight}px; white-space: nowrap; overflow: hidden;">`;
|
` line-height: ${this.lineHeight}px; white-space: nowrap;">`;
|
||||||
|
|
||||||
let imageDrawn = new Set();
|
let imageDrawn = new Set();
|
||||||
let len = lines.length;
|
let len = lines.length;
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
<div v-html="background"></div>
|
<div v-html="background"></div>
|
||||||
<!-- img -->
|
<!-- img -->
|
||||||
</div>
|
</div>
|
||||||
<div ref="scrollBox1" class="layout" style="overflow: hidden" @wheel.prevent.stop="onMouseWheel">
|
<div ref="scrollBox1" class="layout over-hidden" @wheel.prevent.stop="onMouseWheel">
|
||||||
<div ref="scrollingPage1" class="layout" @transitionend="onPage1TransitionEnd" @animationend="onPage1AnimationEnd">
|
<div ref="scrollingPage1" class="layout over-hidden" @transitionend="onPage1TransitionEnd" @animationend="onPage1AnimationEnd">
|
||||||
<div v-html="page1"></div>
|
<div v-html="page1"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div ref="scrollBox2" class="layout" style="overflow: hidden" @wheel.prevent.stop="onMouseWheel">
|
<div ref="scrollBox2" class="layout over-hidden" @wheel.prevent.stop="onMouseWheel">
|
||||||
<div ref="scrollingPage2" class="layout" @transitionend="onPage2TransitionEnd" @animationend="onPage2AnimationEnd">
|
<div ref="scrollingPage2" class="layout over-hidden" @transitionend="onPage2TransitionEnd" @animationend="onPage2AnimationEnd">
|
||||||
<div v-html="page2"></div>
|
<div v-html="page2"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -157,9 +157,11 @@ class TextPage extends Vue {
|
|||||||
this.$refs.layoutEvents.style.height = this.realHeight + 'px';
|
this.$refs.layoutEvents.style.height = this.realHeight + 'px';
|
||||||
|
|
||||||
this.w = this.realWidth - 2*this.indentLR;
|
this.w = this.realWidth - 2*this.indentLR;
|
||||||
this.h = this.realHeight - (this.showStatusBar ? this.statusBarHeight : 0) - 2*this.indentTB;
|
this.scrollHeight = this.realHeight - (this.showStatusBar ? this.statusBarHeight : 0);
|
||||||
|
this.h = this.scrollHeight - 2*this.indentTB;
|
||||||
this.lineHeight = this.fontSize + this.lineInterval;
|
this.lineHeight = this.fontSize + this.lineInterval;
|
||||||
this.pageLineCount = 1 + Math.floor((this.h - this.fontSize)/this.lineHeight);
|
this.pageLineCount = 1 + Math.floor((this.h - this.lineHeight + this.lineInterval/2)/this.lineHeight);
|
||||||
|
this.pageSpace = this.scrollHeight - this.pageLineCount*this.lineHeight;
|
||||||
|
|
||||||
this.$refs.scrollingPage1.style.width = this.w + 'px';
|
this.$refs.scrollingPage1.style.width = this.w + 'px';
|
||||||
this.$refs.scrollingPage2.style.width = this.w + 'px';
|
this.$refs.scrollingPage2.style.width = this.w + 'px';
|
||||||
@@ -193,6 +195,7 @@ class TextPage extends Vue {
|
|||||||
this.drawHelper.indentLR = this.indentLR;
|
this.drawHelper.indentLR = this.indentLR;
|
||||||
this.drawHelper.textAlignJustify = this.textAlignJustify;
|
this.drawHelper.textAlignJustify = this.textAlignJustify;
|
||||||
this.drawHelper.lineHeight = this.lineHeight;
|
this.drawHelper.lineHeight = this.lineHeight;
|
||||||
|
this.drawHelper.pageSpace = this.pageSpace;
|
||||||
this.drawHelper.context = this.context;
|
this.drawHelper.context = this.context;
|
||||||
|
|
||||||
//сообщение "Загрузка шрифтов..."
|
//сообщение "Загрузка шрифтов..."
|
||||||
@@ -232,20 +235,26 @@ class TextPage extends Vue {
|
|||||||
this.statusBarClickable = this.drawHelper.statusBarClickable(this.statusBarTop, this.statusBarHeight);
|
this.statusBarClickable = this.drawHelper.statusBarClickable(this.statusBarTop, this.statusBarHeight);
|
||||||
|
|
||||||
//scrolling page
|
//scrolling page
|
||||||
const pageDelta = this.h - (this.pageLineCount*this.lineHeight - this.lineInterval);
|
let y = this.pageSpace/2;
|
||||||
let y = this.indentTB + pageDelta/2;
|
|
||||||
if (this.showStatusBar)
|
if (this.showStatusBar)
|
||||||
y += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
|
y += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
|
||||||
const page1 = this.$refs.scrollBox1;
|
let page1 = this.$refs.scrollBox1;
|
||||||
const page2 = this.$refs.scrollBox2;
|
let page2 = this.$refs.scrollBox2;
|
||||||
page1.style.width = this.w + 'px';
|
page1.style.width = this.w + this.indentLR + 'px';
|
||||||
page2.style.width = this.w + 'px';
|
page2.style.width = this.w + this.indentLR + 'px';
|
||||||
page1.style.height = (this.h - pageDelta) + 'px';
|
page1.style.height = this.scrollHeight - (this.pageSpace > 0 ? this.pageSpace : 0) + 'px';
|
||||||
page2.style.height = (this.h - pageDelta) + 'px';
|
page2.style.height = this.scrollHeight - (this.pageSpace > 0 ? this.pageSpace : 0) + 'px';
|
||||||
page1.style.top = y + 'px';
|
page1.style.top = y + 'px';
|
||||||
page2.style.top = y + 'px';
|
page2.style.top = y + 'px';
|
||||||
page1.style.left = this.indentLR + 'px';
|
page1.style.left = this.indentLR + 'px';
|
||||||
page2.style.left = this.indentLR + 'px';
|
page2.style.left = this.indentLR + 'px';
|
||||||
|
|
||||||
|
page1 = this.$refs.scrollingPage1;
|
||||||
|
page2 = this.$refs.scrollingPage2;
|
||||||
|
page1.style.width = this.w + this.indentLR + 'px';
|
||||||
|
page2.style.width = this.w + this.indentLR + 'px';
|
||||||
|
page1.style.height = this.scrollHeight + this.lineHeight + 'px';
|
||||||
|
page2.style.height = this.scrollHeight + this.lineHeight + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkLoadedFonts() {
|
async checkLoadedFonts() {
|
||||||
@@ -633,8 +642,14 @@ class TextPage extends Vue {
|
|||||||
duration, this.pageChangeDirectionDown, transition1Finish);
|
duration, this.pageChangeDirectionDown, transition1Finish);
|
||||||
break;
|
break;
|
||||||
case 'downShift':
|
case 'downShift':
|
||||||
|
page1.style.height = this.scrollHeight + 'px';
|
||||||
|
page2.style.height = this.scrollHeight + 'px';
|
||||||
|
|
||||||
await this.drawHelper.doPageAnimationDownShift(page1, page2,
|
await this.drawHelper.doPageAnimationDownShift(page1, page2,
|
||||||
duration, this.pageChangeDirectionDown, transition1Finish);
|
duration, this.pageChangeDirectionDown, transition1Finish);
|
||||||
|
|
||||||
|
page1.style.height = this.scrollHeight + this.lineHeight + 'px';
|
||||||
|
page2.style.height = this.scrollHeight + this.lineHeight + 'px';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1098,6 +1113,10 @@ class TextPage extends Vue {
|
|||||||
z-index: 10;
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.over-hidden {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.back {
|
.back {
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,6 @@ import BookParser from './BookParser';
|
|||||||
|
|
||||||
const maxDataSize = 500*1024*1024;//chars, not bytes
|
const maxDataSize = 500*1024*1024;//chars, not bytes
|
||||||
|
|
||||||
const bmCacheStore = localForage.createInstance({
|
|
||||||
name: 'bmCacheStore'
|
|
||||||
});
|
|
||||||
|
|
||||||
const bmMetaStore = localForage.createInstance({
|
const bmMetaStore = localForage.createInstance({
|
||||||
name: 'bmMetaStore'
|
name: 'bmMetaStore'
|
||||||
});
|
});
|
||||||
@@ -21,15 +17,23 @@ const bmRecentStore = localForage.createInstance({
|
|||||||
name: 'bmRecentStore'
|
name: 'bmRecentStore'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const bmCacheStore = localForage.createInstance({
|
||||||
|
name: 'bmCacheStore'
|
||||||
|
});
|
||||||
|
|
||||||
class BookManager {
|
class BookManager {
|
||||||
async init(settings) {
|
async init(settings) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
|
|
||||||
//this.booksCached нужен только для ускорения загрузки читалки
|
//bmCacheStore нужен только для ускорения загрузки читалки
|
||||||
this.booksCached = await bmCacheStore.getItem('books');
|
this.booksCached = await bmCacheStore.getItem('books');
|
||||||
if (!this.booksCached)
|
if (!this.booksCached)
|
||||||
this.booksCached = {};
|
this.booksCached = {};
|
||||||
this.recent = await bmCacheStore.getItem('recent');
|
this.recent = await bmCacheStore.getItem('recent');
|
||||||
|
this.recentLast = await bmCacheStore.getItem('recent-last');
|
||||||
|
if (this.recentLast)
|
||||||
|
this.recent[this.recentLast.key] = this.recentLast;
|
||||||
|
|
||||||
this.books = Object.assign({}, this.booksCached);
|
this.books = Object.assign({}, this.booksCached);
|
||||||
|
|
||||||
this.recentChanged1 = true;
|
this.recentChanged1 = true;
|
||||||
@@ -44,7 +48,9 @@ class BookManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//долгая загрузка из хранилища,
|
||||||
|
//хранение в отдельных записях дает относительно
|
||||||
|
//нормальное поведение при нескольких вкладках с читалкой в браузере
|
||||||
async loadMeta(immediate) {
|
async loadMeta(immediate) {
|
||||||
if (!immediate)
|
if (!immediate)
|
||||||
await utils.sleep(2000);
|
await utils.sleep(2000);
|
||||||
@@ -57,7 +63,13 @@ class BookManager {
|
|||||||
if (keySplit.length == 2 && keySplit[0] == 'bmMeta') {
|
if (keySplit.length == 2 && keySplit[0] == 'bmMeta') {
|
||||||
let meta = await bmMetaStore.getItem(key);
|
let meta = await bmMetaStore.getItem(key);
|
||||||
|
|
||||||
|
const oldBook = this.books[meta.key];
|
||||||
this.books[meta.key] = meta;
|
this.books[meta.key] = meta;
|
||||||
|
|
||||||
|
if (oldBook && oldBook.data && oldBook.parsed) {
|
||||||
|
this.books[meta.key].data = oldBook.data;
|
||||||
|
this.books[meta.key].parsed = oldBook.parsed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,12 +81,14 @@ class BookManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.cleanBooks();
|
await this.cleanBooks();
|
||||||
|
await this.cleanRecentBooks();
|
||||||
|
|
||||||
this.booksCached = {};
|
this.booksCached = {};
|
||||||
for (const key in this.books) {
|
for (const key in this.books) {
|
||||||
this.booksCached[key] = this.metaOnly(this.books[key]);
|
this.booksCached[key] = this.metaOnly(this.books[key]);
|
||||||
}
|
}
|
||||||
await bmCacheStore.setItem('books', this.booksCached);
|
await bmCacheStore.setItem('books', this.booksCached);
|
||||||
|
await bmCacheStore.setItem('recent', this.recent);
|
||||||
}
|
}
|
||||||
|
|
||||||
async cleanBooks() {
|
async cleanBooks() {
|
||||||
@@ -205,8 +219,13 @@ class BookManager {
|
|||||||
this.recent[result.key] = result;
|
this.recent[result.key] = result;
|
||||||
|
|
||||||
await bmRecentStore.setItem(result.key, result);
|
await bmRecentStore.setItem(result.key, result);
|
||||||
await this.cleanRecentBooks();
|
|
||||||
await bmCacheStore.setItem('recent', this.recent);
|
//кэшируем, аккуратно
|
||||||
|
if (!(this.recentLast && this.recentLast.key == result.key)) {
|
||||||
|
await bmCacheStore.setItem('recent', this.recent);
|
||||||
|
}
|
||||||
|
this.recentLast = result;
|
||||||
|
await bmCacheStore.setItem('recent-last', this.recentLast);
|
||||||
|
|
||||||
this.recentChanged1 = true;
|
this.recentChanged1 = true;
|
||||||
this.recentChanged2 = true;
|
this.recentChanged2 = true;
|
||||||
|
|||||||
345
package-lock.json
generated
345
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.4.7",
|
"version": "0.5.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1597,9 +1597,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"base64-js": {
|
"base64-js": {
|
||||||
"version": "0.0.8",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-0.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz",
|
||||||
"integrity": "sha1-EQHpVE9KdrG8OybUUsqW16NeeXg="
|
"integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw=="
|
||||||
},
|
},
|
||||||
"bcrypt-pbkdf": {
|
"bcrypt-pbkdf": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@@ -1622,12 +1622,23 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"bl": {
|
"bl": {
|
||||||
"version": "1.2.2",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/bl/-/bl-3.0.0.tgz",
|
||||||
"integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==",
|
"integrity": "sha512-EUAyP5UHU5hxF8BPT0LKW8gjYLhq1DQIcneOX/pL/m2Alo+OYDQAJlHq+yseMP50Os2nHXOSic6Ss3vSQeyf4A==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"readable-stream": "^2.3.5",
|
"readable-stream": "^3.0.1"
|
||||||
"safe-buffer": "^5.1.1"
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"readable-stream": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.2.0.tgz",
|
||||||
|
"integrity": "sha512-RV20kLjdmpZuTF1INEb9IA3L68Nmi+Ri7ppZqo78wj//Pn62fCoJyV9zalccNzDD/OuJpMG4f+pfMl8+L6QdGw==",
|
||||||
|
"requires": {
|
||||||
|
"inherits": "^2.0.3",
|
||||||
|
"string_decoder": "^1.1.1",
|
||||||
|
"util-deprecate": "^1.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bluebird": {
|
"bluebird": {
|
||||||
@@ -1809,39 +1820,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"buffer": {
|
"buffer": {
|
||||||
"version": "3.6.0",
|
"version": "5.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-3.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.1.tgz",
|
||||||
"integrity": "sha1-pyyTb3e5a/UvX357RnGAYoVR3vs=",
|
"integrity": "sha512-c+Ko0loDaFfuPWiL02ls9Xd3GO3cPVmUobQ6t3rXNUk304u6hGq+8N/kFi+QEIKhzK3uwolVhLzszmfLmMLnqg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"base64-js": "0.0.8",
|
"base64-js": "^1.0.2",
|
||||||
"ieee754": "^1.1.4",
|
"ieee754": "^1.1.4"
|
||||||
"isarray": "^1.0.0"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"buffer-alloc": {
|
|
||||||
"version": "1.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz",
|
|
||||||
"integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==",
|
|
||||||
"requires": {
|
|
||||||
"buffer-alloc-unsafe": "^1.1.0",
|
|
||||||
"buffer-fill": "^1.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"buffer-alloc-unsafe": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg=="
|
|
||||||
},
|
|
||||||
"buffer-crc32": {
|
|
||||||
"version": "0.2.13",
|
|
||||||
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
|
|
||||||
"integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI="
|
|
||||||
},
|
|
||||||
"buffer-fill": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw="
|
|
||||||
},
|
|
||||||
"buffer-from": {
|
"buffer-from": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||||
@@ -2354,14 +2340,6 @@
|
|||||||
"delayed-stream": "~1.0.0"
|
"delayed-stream": "~1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"commander": {
|
|
||||||
"version": "2.8.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz",
|
|
||||||
"integrity": "sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=",
|
|
||||||
"requires": {
|
|
||||||
"graceful-readlink": ">= 1.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"commondir": {
|
"commondir": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
|
||||||
@@ -3080,45 +3058,6 @@
|
|||||||
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
|
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"decompress": {
|
|
||||||
"version": "4.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress/-/decompress-4.2.0.tgz",
|
|
||||||
"integrity": "sha1-eu3YVCflqS2s/lVnSnxQXpbQH50=",
|
|
||||||
"requires": {
|
|
||||||
"decompress-tar": "^4.0.0",
|
|
||||||
"decompress-tarbz2": "^4.0.0",
|
|
||||||
"decompress-targz": "^4.0.0",
|
|
||||||
"decompress-unzip": "^4.0.1",
|
|
||||||
"graceful-fs": "^4.1.10",
|
|
||||||
"make-dir": "^1.0.0",
|
|
||||||
"pify": "^2.3.0",
|
|
||||||
"strip-dirs": "^2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"decompress-bzip2": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress-bzip2/-/decompress-bzip2-4.0.0.tgz",
|
|
||||||
"integrity": "sha1-0SVMlJ4F6vYol1QoawY/3Hz/AT8=",
|
|
||||||
"requires": {
|
|
||||||
"file-type": "^4.3.0",
|
|
||||||
"seek-bzip": "^1.0.5"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"file-type": {
|
|
||||||
"version": "4.4.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/file-type/-/file-type-4.4.0.tgz",
|
|
||||||
"integrity": "sha1-G2AOX8ofvcboDApwxxyNul95BsU="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"decompress-gz": {
|
|
||||||
"version": "0.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress-gz/-/decompress-gz-0.0.1.tgz",
|
|
||||||
"integrity": "sha512-YMdCWdxHvPplsTbV1tvr2oFJOtAFNxqVMFnKWEmePBXl+LKG5z5bFrowzc12Jzd7O29nnzI/D1M95Asx0Qa1fg==",
|
|
||||||
"requires": {
|
|
||||||
"file-type": "^5.2.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"decompress-response": {
|
"decompress-response": {
|
||||||
"version": "3.3.0",
|
"version": "3.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz",
|
||||||
@@ -3127,63 +3066,6 @@
|
|||||||
"mimic-response": "^1.0.0"
|
"mimic-response": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"decompress-tar": {
|
|
||||||
"version": "4.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress-tar/-/decompress-tar-4.1.1.tgz",
|
|
||||||
"integrity": "sha512-JdJMaCrGpB5fESVyxwpCx4Jdj2AagLmv3y58Qy4GE6HMVjWz1FeVQk1Ct4Kye7PftcdOo/7U7UKzYBJgqnGeUQ==",
|
|
||||||
"requires": {
|
|
||||||
"file-type": "^5.2.0",
|
|
||||||
"is-stream": "^1.1.0",
|
|
||||||
"tar-stream": "^1.5.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"decompress-tarbz2": {
|
|
||||||
"version": "4.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress-tarbz2/-/decompress-tarbz2-4.1.1.tgz",
|
|
||||||
"integrity": "sha512-s88xLzf1r81ICXLAVQVzaN6ZmX4A6U4z2nMbOwobxkLoIIfjVMBg7TeguTUXkKeXni795B6y5rnvDw7rxhAq9A==",
|
|
||||||
"requires": {
|
|
||||||
"decompress-tar": "^4.1.0",
|
|
||||||
"file-type": "^6.1.0",
|
|
||||||
"is-stream": "^1.1.0",
|
|
||||||
"seek-bzip": "^1.0.5",
|
|
||||||
"unbzip2-stream": "^1.0.9"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"file-type": {
|
|
||||||
"version": "6.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/file-type/-/file-type-6.2.0.tgz",
|
|
||||||
"integrity": "sha512-YPcTBDV+2Tm0VqjybVd32MHdlEGAtuxS3VAYsumFokDSMG+ROT5wawGlnHDoz7bfMcMDt9hxuXvXwoKUx2fkOg=="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"decompress-targz": {
|
|
||||||
"version": "4.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress-targz/-/decompress-targz-4.1.1.tgz",
|
|
||||||
"integrity": "sha512-4z81Znfr6chWnRDNfFNqLwPvm4db3WuZkqV+UgXQzSngG3CEKdBkw5jrv3axjjL96glyiiKjsxJG3X6WBZwX3w==",
|
|
||||||
"requires": {
|
|
||||||
"decompress-tar": "^4.1.1",
|
|
||||||
"file-type": "^5.2.0",
|
|
||||||
"is-stream": "^1.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"decompress-unzip": {
|
|
||||||
"version": "4.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress-unzip/-/decompress-unzip-4.0.1.tgz",
|
|
||||||
"integrity": "sha1-3qrM39FK6vhVePczroIQ+bSEj2k=",
|
|
||||||
"requires": {
|
|
||||||
"file-type": "^3.8.0",
|
|
||||||
"get-stream": "^2.2.0",
|
|
||||||
"pify": "^2.3.0",
|
|
||||||
"yauzl": "^2.4.2"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"file-type": {
|
|
||||||
"version": "3.9.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz",
|
|
||||||
"integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"deep-extend": {
|
"deep-extend": {
|
||||||
"version": "0.6.0",
|
"version": "0.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
|
||||||
@@ -4172,6 +4054,43 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"extract-zip": {
|
||||||
|
"version": "1.6.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.6.7.tgz",
|
||||||
|
"integrity": "sha1-qEC0uK9kAyZMjbV/Txp0Mz74H+k=",
|
||||||
|
"requires": {
|
||||||
|
"concat-stream": "1.6.2",
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"mkdirp": "0.5.1",
|
||||||
|
"yauzl": "2.4.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fd-slicer": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=",
|
||||||
|
"requires": {
|
||||||
|
"pend": "~1.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"yauzl": {
|
||||||
|
"version": "2.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.4.1.tgz",
|
||||||
|
"integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=",
|
||||||
|
"requires": {
|
||||||
|
"fd-slicer": "~1.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"extsprintf": {
|
"extsprintf": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
|
||||||
@@ -4213,14 +4132,6 @@
|
|||||||
"integrity": "sha512-483XLLxTVIwWK3QTrMGRqUfUpoOs/0hbQrl2oz4J0pAcm3A3bu84wxTFqGqkJzewCLdME38xJLJAxBABfQT8sQ==",
|
"integrity": "sha512-483XLLxTVIwWK3QTrMGRqUfUpoOs/0hbQrl2oz4J0pAcm3A3bu84wxTFqGqkJzewCLdME38xJLJAxBABfQT8sQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"fd-slicer": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
|
|
||||||
"integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=",
|
|
||||||
"requires": {
|
|
||||||
"pend": "~1.2.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"fg-loadcss": {
|
"fg-loadcss": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/fg-loadcss/-/fg-loadcss-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/fg-loadcss/-/fg-loadcss-2.1.0.tgz",
|
||||||
@@ -4261,11 +4172,6 @@
|
|||||||
"schema-utils": "^1.0.0"
|
"schema-utils": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"file-type": {
|
|
||||||
"version": "5.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/file-type/-/file-type-5.2.0.tgz",
|
|
||||||
"integrity": "sha1-LdvqfHP/42No365J3DOMBYwritY="
|
|
||||||
},
|
|
||||||
"fill-range": {
|
"fill-range": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz",
|
||||||
@@ -5057,15 +4963,6 @@
|
|||||||
"integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==",
|
"integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"get-stream": {
|
|
||||||
"version": "2.3.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-2.3.1.tgz",
|
|
||||||
"integrity": "sha1-Xzj5PzRgCWZu4BUKBUFn+Rvdld4=",
|
|
||||||
"requires": {
|
|
||||||
"object-assign": "^4.0.1",
|
|
||||||
"pinkie-promise": "^2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"get-value": {
|
"get-value": {
|
||||||
"version": "2.0.6",
|
"version": "2.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz",
|
||||||
@@ -5220,11 +5117,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz",
|
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz",
|
||||||
"integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA=="
|
"integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA=="
|
||||||
},
|
},
|
||||||
"graceful-readlink": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz",
|
|
||||||
"integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU="
|
|
||||||
},
|
|
||||||
"har-schema": {
|
"har-schema": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
|
||||||
@@ -5967,11 +5859,6 @@
|
|||||||
"is-extglob": "^2.1.1"
|
"is-extglob": "^2.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"is-natural-number": {
|
|
||||||
"version": "4.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/is-natural-number/-/is-natural-number-4.0.1.tgz",
|
|
||||||
"integrity": "sha1-q5124dtM7VHjXeDHLr7PCfc0zeg="
|
|
||||||
},
|
|
||||||
"is-number": {
|
"is-number": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz",
|
||||||
@@ -6031,7 +5918,8 @@
|
|||||||
"is-stream": {
|
"is-stream": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
|
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"is-svg": {
|
"is-svg": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
@@ -6336,6 +6224,7 @@
|
|||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",
|
||||||
"integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==",
|
"integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==",
|
||||||
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"pify": "^3.0.0"
|
"pify": "^3.0.0"
|
||||||
},
|
},
|
||||||
@@ -6343,7 +6232,8 @@
|
|||||||
"pify": {
|
"pify": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
|
||||||
"integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY="
|
"integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=",
|
||||||
|
"dev": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -7413,20 +7303,17 @@
|
|||||||
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
||||||
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
|
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
|
||||||
},
|
},
|
||||||
"pify": {
|
|
||||||
"version": "2.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
|
||||||
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw="
|
|
||||||
},
|
|
||||||
"pinkie": {
|
"pinkie": {
|
||||||
"version": "2.0.4",
|
"version": "2.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz",
|
||||||
"integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA="
|
"integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"pinkie-promise": {
|
"pinkie-promise": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz",
|
||||||
"integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=",
|
"integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=",
|
||||||
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"pinkie": "^2.0.0"
|
"pinkie": "^2.0.0"
|
||||||
}
|
}
|
||||||
@@ -10047,14 +9934,6 @@
|
|||||||
"ajv-keywords": "^3.1.0"
|
"ajv-keywords": "^3.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"seek-bzip": {
|
|
||||||
"version": "1.0.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/seek-bzip/-/seek-bzip-1.0.5.tgz",
|
|
||||||
"integrity": "sha1-z+kXyz0nS8/6x5J1ivUxc+sfq9w=",
|
|
||||||
"requires": {
|
|
||||||
"commander": "~2.8.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"semver": {
|
"semver": {
|
||||||
"version": "5.6.0",
|
"version": "5.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
|
||||||
@@ -10563,14 +10442,6 @@
|
|||||||
"ansi-regex": "^2.0.0"
|
"ansi-regex": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"strip-dirs": {
|
|
||||||
"version": "2.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/strip-dirs/-/strip-dirs-2.1.0.tgz",
|
|
||||||
"integrity": "sha512-JOCxOeKLm2CAS73y/U4ZeZPTkE+gNVCzKt7Eox84Iej1LT/2pTWYpZKJuxwQpvX1LiZb1xokNR7RLfuBAa7T3g==",
|
|
||||||
"requires": {
|
|
||||||
"is-natural-number": "^4.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"strip-eof": {
|
"strip-eof": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
|
||||||
@@ -10770,18 +10641,50 @@
|
|||||||
"yallist": "^3.0.2"
|
"yallist": "^3.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tar-stream": {
|
"tar-fs": {
|
||||||
"version": "1.6.2",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.6.2.tgz",
|
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.0.0.tgz",
|
||||||
"integrity": "sha512-rzS0heiNf8Xn7/mpdSVVSMAWAoy9bfb1WOTYC78Z0UQKeKa/CWS8FOq0lKGNa8DWKAn9gxjCvMLYc5PGXYlK2A==",
|
"integrity": "sha512-vaY0obB6Om/fso8a8vakQBzwholQ7v5+uy+tF3Ozvxv1KNezmVQAiWtcNmMHFSFPqL3dJA8ha6gdtFbfX9mcxA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"bl": "^1.0.0",
|
"chownr": "^1.1.1",
|
||||||
"buffer-alloc": "^1.2.0",
|
"mkdirp": "^0.5.1",
|
||||||
"end-of-stream": "^1.0.0",
|
"pump": "^3.0.0",
|
||||||
|
"tar-stream": "^2.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"pump": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
|
||||||
|
"requires": {
|
||||||
|
"end-of-stream": "^1.1.0",
|
||||||
|
"once": "^1.3.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tar-stream": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-I6OJF7wE62BC6zNPdHDtseK0D0187PBjbKSLYY4ffvVkBM6tyBn2O9plDvVM2229/mozfEL/X3++qSvYYQE2xw==",
|
||||||
|
"requires": {
|
||||||
|
"bl": "^3.0.0",
|
||||||
|
"end-of-stream": "^1.4.1",
|
||||||
"fs-constants": "^1.0.0",
|
"fs-constants": "^1.0.0",
|
||||||
"readable-stream": "^2.3.0",
|
"inherits": "^2.0.3",
|
||||||
"to-buffer": "^1.1.1",
|
"readable-stream": "^3.1.1"
|
||||||
"xtend": "^4.0.0"
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"readable-stream": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.2.0.tgz",
|
||||||
|
"integrity": "sha512-RV20kLjdmpZuTF1INEb9IA3L68Nmi+Ri7ppZqo78wj//Pn62fCoJyV9zalccNzDD/OuJpMG4f+pfMl8+L6QdGw==",
|
||||||
|
"requires": {
|
||||||
|
"inherits": "^2.0.3",
|
||||||
|
"string_decoder": "^1.1.1",
|
||||||
|
"util-deprecate": "^1.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"terser": {
|
"terser": {
|
||||||
@@ -11036,11 +10939,6 @@
|
|||||||
"integrity": "sha1-fSKbH8xjfkZsoIEYCDanqr/4P0M=",
|
"integrity": "sha1-fSKbH8xjfkZsoIEYCDanqr/4P0M=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"to-buffer": {
|
|
||||||
"version": "1.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz",
|
|
||||||
"integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg=="
|
|
||||||
},
|
|
||||||
"to-fast-properties": {
|
"to-fast-properties": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz",
|
||||||
@@ -11201,12 +11099,12 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"unbzip2-stream": {
|
"unbzip2-stream": {
|
||||||
"version": "1.3.1",
|
"version": "1.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/unbzip2-stream/-/unbzip2-stream-1.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/unbzip2-stream/-/unbzip2-stream-1.3.3.tgz",
|
||||||
"integrity": "sha512-fIZnvdjblYs7Cru/xC6tCPVhz7JkYcVQQkePwMLyQELzYTds2Xn8QefPVnvdVhhZqubxNA1cASXEH5wcK0Bucw==",
|
"integrity": "sha512-fUlAF7U9Ah1Q6EieQ4x4zLNejrRvDWUYmxXUpN3uziFYCHapjWFaCAnreY9bGgxzaMCFAPPpYNng57CypwJVhg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"buffer": "^3.0.1",
|
"buffer": "^5.2.1",
|
||||||
"through": "^2.3.6"
|
"through": "^2.3.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"union-value": {
|
"union-value": {
|
||||||
@@ -12003,15 +11901,6 @@
|
|||||||
"camelcase": "^5.0.0",
|
"camelcase": "^5.0.0",
|
||||||
"decamelize": "^1.2.0"
|
"decamelize": "^1.2.0"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"yauzl": {
|
|
||||||
"version": "2.10.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz",
|
|
||||||
"integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=",
|
|
||||||
"requires": {
|
|
||||||
"buffer-crc32": "~0.2.3",
|
|
||||||
"fd-slicer": "~1.1.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.5.2",
|
"version": "0.5.6",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
},
|
},
|
||||||
@@ -29,7 +29,6 @@
|
|||||||
"clean-webpack-plugin": "^1.0.0",
|
"clean-webpack-plugin": "^1.0.0",
|
||||||
"copy-webpack-plugin": "^4.6.0",
|
"copy-webpack-plugin": "^4.6.0",
|
||||||
"css-loader": "^1.0.0",
|
"css-loader": "^1.0.0",
|
||||||
"decompress-targz": "^4.1.1",
|
|
||||||
"disable-output-webpack-plugin": "^1.0.1",
|
"disable-output-webpack-plugin": "^1.0.1",
|
||||||
"element-theme-chalk": "^2.4.11",
|
"element-theme-chalk": "^2.4.11",
|
||||||
"eslint": "^5.11.1",
|
"eslint": "^5.11.1",
|
||||||
@@ -59,11 +58,9 @@
|
|||||||
"axios": "^0.18.0",
|
"axios": "^0.18.0",
|
||||||
"chardet": "^0.7.0",
|
"chardet": "^0.7.0",
|
||||||
"compression": "^1.7.3",
|
"compression": "^1.7.3",
|
||||||
"decompress": "^4.2.0",
|
|
||||||
"decompress-bzip2": "^4.0.0",
|
|
||||||
"decompress-gz": "0.0.1",
|
|
||||||
"element-ui": "^2.4.11",
|
"element-ui": "^2.4.11",
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
|
"extract-zip": "^1.6.7",
|
||||||
"fg-loadcss": "^2.1.0",
|
"fg-loadcss": "^2.1.0",
|
||||||
"fs-extra": "^7.0.1",
|
"fs-extra": "^7.0.1",
|
||||||
"got": "^9.5.1",
|
"got": "^9.5.1",
|
||||||
@@ -76,6 +73,8 @@
|
|||||||
"path-browserify": "^1.0.0",
|
"path-browserify": "^1.0.0",
|
||||||
"sql-template-strings": "^2.2.2",
|
"sql-template-strings": "^2.2.2",
|
||||||
"sqlite": "^3.0.0",
|
"sqlite": "^3.0.0",
|
||||||
|
"tar-fs": "^2.0.0",
|
||||||
|
"unbzip2-stream": "^1.3.3",
|
||||||
"vue": "^2.5.21",
|
"vue": "^2.5.21",
|
||||||
"vue-router": "^3.0.2",
|
"vue-router": "^3.0.2",
|
||||||
"vuex": "^3.0.1",
|
"vuex": "^3.0.1",
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ const chardet = require('chardet');
|
|||||||
const textUtils = require('./textUtils');
|
const textUtils = require('./textUtils');
|
||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
|
|
||||||
|
let execConverterCounter = 0;
|
||||||
|
|
||||||
class ConvertBase {
|
class ConvertBase {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@@ -30,7 +32,11 @@ class ConvertBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async execConverter(path, args, onData) {
|
async execConverter(path, args, onData) {
|
||||||
|
execConverterCounter++;
|
||||||
try {
|
try {
|
||||||
|
if (execConverterCounter > 10)
|
||||||
|
throw new Error('Слишком большая очередь конвертирования. Пожалуйста, попробуйте позже.');
|
||||||
|
|
||||||
const result = await utils.spawnProcess(path, {args, onData});
|
const result = await utils.spawnProcess(path, {args, onData});
|
||||||
if (result.code != 0) {
|
if (result.code != 0) {
|
||||||
let error = result.code;
|
let error = result.code;
|
||||||
@@ -46,6 +52,8 @@ class ConvertBase {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error(e);
|
throw new Error(e);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
execConverterCounter--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ class ConvertDoc extends ConvertDocX {
|
|||||||
|
|
||||||
const {inputFiles, callback} = opts;
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
const outFile = `${inputFiles.fileListDir}/${path.basename(inputFiles.sourceFile)}`;
|
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||||
const docFile = `${outFile}.doc`;
|
const docFile = `${outFile}.doc`;
|
||||||
const docxFile = `${outFile}.docx`;
|
const docxFile = `${outFile}.docx`;
|
||||||
const fb2File = `${outFile}.fb2`;
|
const fb2File = `${outFile}.fb2`;
|
||||||
|
|
||||||
await fs.copy(inputFiles.sourceFile, docFile);
|
await fs.copy(inputFiles.sourceFile, docFile);
|
||||||
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.fileListDir, docFile]);
|
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.filesDir, docFile]);
|
||||||
|
|
||||||
return await super.convert(docxFile, fb2File, callback);
|
return await super.convert(docxFile, fb2File, callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ const ConvertBase = require('./ConvertBase');
|
|||||||
class ConvertDocX extends ConvertBase {
|
class ConvertDocX extends ConvertBase {
|
||||||
check(data, opts) {
|
check(data, opts) {
|
||||||
const {inputFiles} = opts;
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
if (this.config.useExternalBookConverter &&
|
if (this.config.useExternalBookConverter &&
|
||||||
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'zip') {
|
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'zip') {
|
||||||
//ищем файл '[Content_Types].xml'
|
//ищем файл '[Content_Types].xml'
|
||||||
for (const file of inputFiles.fileList) {
|
for (const file of inputFiles.files) {
|
||||||
if (file == '[Content_Types].xml') {
|
if (file.path == '[Content_Types].xml') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,7 +36,7 @@ class ConvertDocX extends ConvertBase {
|
|||||||
|
|
||||||
const {inputFiles, callback} = opts;
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
const outFile = `${inputFiles.fileListDir}/${path.basename(inputFiles.sourceFile)}`;
|
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||||
const docxFile = `${outFile}.docx`;
|
const docxFile = `${outFile}.docx`;
|
||||||
const fb2File = `${outFile}.fb2`;
|
const fb2File = `${outFile}.fb2`;
|
||||||
|
|
||||||
|
|||||||
49
server/core/BookConverter/ConvertEpub.js
Normal file
49
server/core/BookConverter/ConvertEpub.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const ConvertBase = require('./ConvertBase');
|
||||||
|
|
||||||
|
class ConvertEpub extends ConvertBase {
|
||||||
|
async check(data, opts) {
|
||||||
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
|
if (this.config.useExternalBookConverter &&
|
||||||
|
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'zip') {
|
||||||
|
//ищем файл 'mimetype'
|
||||||
|
for (const file of inputFiles.files) {
|
||||||
|
if (file.path == 'mimetype') {
|
||||||
|
const mt = await fs.readFile(`${inputFiles.filesDir}/${file.path}`);
|
||||||
|
if (mt.toString().trim() == 'application/epub+zip')
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
if (!await this.check(data, opts))
|
||||||
|
return false;
|
||||||
|
await this.checkExternalConverterPresent();
|
||||||
|
|
||||||
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
|
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||||
|
const epubFile = `${outFile}.epub`;
|
||||||
|
const fb2File = `${outFile}.fb2`;
|
||||||
|
|
||||||
|
await fs.copy(inputFiles.sourceFile, epubFile);
|
||||||
|
|
||||||
|
let perc = 0;
|
||||||
|
await this.execConverter(this.calibrePath, [epubFile, fb2File], () => {
|
||||||
|
perc = (perc < 100 ? perc + 5 : 50);
|
||||||
|
callback(perc);
|
||||||
|
});
|
||||||
|
|
||||||
|
return await fs.readFile(fb2File);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertEpub;
|
||||||
@@ -18,19 +18,31 @@ class ConvertHtml extends ConvertBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(data, opts) {
|
async run(data, opts) {
|
||||||
const checkResult = this.check(data, opts);
|
let isText = false;
|
||||||
if (!checkResult)
|
if (!opts.skipCheck) {
|
||||||
return false;
|
const checkResult = this.check(data, opts);
|
||||||
|
if (!checkResult)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
isText = checkResult.isText;
|
||||||
|
} else {
|
||||||
|
isText = opts.isText;
|
||||||
|
}
|
||||||
|
const {cutTitle} = opts;
|
||||||
|
|
||||||
let {isText} = checkResult;
|
|
||||||
let titleInfo = {};
|
let titleInfo = {};
|
||||||
let desc = {_n: 'description', 'title-info': titleInfo};
|
let desc = {_n: 'description', 'title-info': titleInfo};
|
||||||
let pars = [];
|
let pars = [];
|
||||||
let body = {_n: 'body', section: {_a: []}};
|
let body = {_n: 'body', section: {_a: []}};
|
||||||
let fb2 = [desc, body];
|
let binary = [];
|
||||||
|
let fb2 = [desc, body, binary];
|
||||||
|
|
||||||
let title = '';
|
let title = '';
|
||||||
let inTitle = false;
|
let inTitle = false;
|
||||||
|
let inImage = false;
|
||||||
|
let image = {};
|
||||||
|
let bold = false;
|
||||||
|
let italic = false;
|
||||||
|
|
||||||
let spaceCounter = [];
|
let spaceCounter = [];
|
||||||
|
|
||||||
@@ -45,14 +57,14 @@ class ConvertHtml extends ConvertBase {
|
|||||||
newParagraph();
|
newParagraph();
|
||||||
|
|
||||||
const l = pars.length;
|
const l = pars.length;
|
||||||
if (pars[l - 1]._t == '')
|
|
||||||
text = text.trimLeft();
|
|
||||||
pars[l - 1]._t += text;
|
pars[l - 1]._t += text;
|
||||||
|
|
||||||
//посчитаем отступы у текста, чтобы выделить потом параграфы
|
//посчитаем отступы у текста, чтобы выделить потом параграфы
|
||||||
const lines = text.split('\n');
|
const lines = text.split('\n');
|
||||||
for (let line of lines) {
|
for (let line of lines) {
|
||||||
line = repCrLfTab(line)
|
if (line.trim() == '')
|
||||||
|
continue;
|
||||||
|
line = repCrLfTab(line);
|
||||||
|
|
||||||
let l = 0;
|
let l = 0;
|
||||||
while (l < line.length && line[l] == ' ') {
|
while (l < line.length && line[l] == ' ') {
|
||||||
@@ -64,37 +76,93 @@ class ConvertHtml extends ConvertBase {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const newPara = new Set(['tr', 'br', 'br/', 'dd', 'p', 'title', '/title', 'h1', 'h2', 'h3', '/h1', '/h2', '/h3']);
|
const newPara = new Set(['tr', '/table', 'hr', 'br', 'br/', 'li', 'dt', 'dd', 'p', 'title', '/title', 'h1', 'h2', 'h3', '/h1', '/h2', '/h3']);
|
||||||
|
|
||||||
const onTextNode = (text, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
const onTextNode = (text, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
if (!cutCounter) {
|
if (!cutCounter && !(cutTitle && inTitle)) {
|
||||||
growParagraph(text);
|
let tOpen = (bold ? '<strong>' : '');
|
||||||
|
tOpen += (italic ? '<emphasis>' : '');
|
||||||
|
let tClose = (italic ? '</emphasis>' : '');
|
||||||
|
tClose += (bold ? '</strong>' : '');
|
||||||
|
|
||||||
|
growParagraph(`${tOpen}${text}${tClose}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inTitle && !title)
|
if (inTitle && !title)
|
||||||
title = text;
|
title = text;
|
||||||
|
|
||||||
|
if (inImage) {
|
||||||
|
image._t = text;
|
||||||
|
binary.push(image);
|
||||||
|
|
||||||
|
pars.push({_n: 'image', _attrs: {'l:href': '#' + image._attrs.id}, _t: ''});
|
||||||
|
newParagraph();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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 (!cutCounter) {
|
if (!cutCounter) {
|
||||||
if (newPara.has(tag))
|
if (newPara.has(tag))
|
||||||
newParagraph();
|
newParagraph();
|
||||||
|
|
||||||
|
switch (tag) {
|
||||||
|
case 'i':
|
||||||
|
case 'em':
|
||||||
|
italic = true;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
case 'strong':
|
||||||
|
case 'h1':
|
||||||
|
case 'h2':
|
||||||
|
case 'h3':
|
||||||
|
bold = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'title')
|
if (tag == 'title')
|
||||||
inTitle = true;
|
inTitle = true;
|
||||||
|
|
||||||
|
if (tag == 'fb2-image') {
|
||||||
|
inImage = true;
|
||||||
|
const attrs = sax.getAttrsSync(tail);
|
||||||
|
image = {_n: 'binary', _attrs: {id: attrs.name.value, 'content-type': attrs.type.value}, _t: ''};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onEndNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
const onEndNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (!cutCounter) {
|
||||||
|
if (newPara.has('/' + tag))
|
||||||
|
newParagraph();
|
||||||
|
|
||||||
|
switch (tag) {
|
||||||
|
case 'i':
|
||||||
|
case 'em':
|
||||||
|
italic = false;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
case 'strong':
|
||||||
|
case 'h1':
|
||||||
|
case 'h2':
|
||||||
|
case 'h3':
|
||||||
|
bold = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (tag == 'title')
|
if (tag == 'title')
|
||||||
inTitle = false;
|
inTitle = false;
|
||||||
|
|
||||||
|
if (tag == 'fb2-image')
|
||||||
|
inImage = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
let buf = this.decode(data).toString();
|
let buf = this.decode(data).toString();
|
||||||
|
|
||||||
sax.parseSync(buf, {
|
sax.parseSync(buf, {
|
||||||
onStartNode, onEndNode, onTextNode,
|
onStartNode, onEndNode, onTextNode,
|
||||||
innerCut: new Set(['head', 'script', 'style', 'binary'])
|
innerCut: new Set(['head', 'script', 'style', 'binary', 'fb2-image'])
|
||||||
});
|
});
|
||||||
|
|
||||||
titleInfo['book-title'] = title;
|
titleInfo['book-title'] = title;
|
||||||
@@ -102,12 +170,27 @@ class ConvertHtml extends ConvertBase {
|
|||||||
//подозрение на чистый текст, надо разбить на параграфы
|
//подозрение на чистый текст, надо разбить на параграфы
|
||||||
if (isText || pars.length < buf.length/2000) {
|
if (isText || pars.length < buf.length/2000) {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
let count = 1;
|
||||||
for (let i = 0; i < spaceCounter.length; i++) {
|
for (let i = 0; i < spaceCounter.length; i++) {
|
||||||
total += (spaceCounter[i] ? spaceCounter[i] : 0);
|
const sc = (spaceCounter[i] ? spaceCounter[i] : 0);
|
||||||
|
if (sc) count++;
|
||||||
|
total += sc;
|
||||||
|
}
|
||||||
|
|
||||||
|
let d = 0;
|
||||||
|
const mid = total/count;
|
||||||
|
for (let i = 0; i < spaceCounter.length; i++) {
|
||||||
|
const sc = (spaceCounter[i] ? spaceCounter[i] : 0);
|
||||||
|
if (sc > mid) d++;
|
||||||
|
}
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
//если разброс не слишком большой, выделяем параграфы
|
||||||
|
if (d < 10 && spaceCounter.length) {
|
||||||
|
total /= 20;
|
||||||
|
i = spaceCounter.length - 1;
|
||||||
|
while (i > 0 && (!spaceCounter[i] || spaceCounter[i] < total)) i--;
|
||||||
}
|
}
|
||||||
total /= 10;
|
|
||||||
let i = spaceCounter.length - 1;
|
|
||||||
while (i > 0 && (!spaceCounter[i] || spaceCounter[i] < total)) i--;
|
|
||||||
|
|
||||||
const parIndent = (i > 0 ? i : 0);
|
const parIndent = (i > 0 ? i : 0);
|
||||||
|
|
||||||
@@ -126,10 +209,16 @@ class ConvertHtml extends ConvertBase {
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (const par of pars) {
|
for (const par of pars) {
|
||||||
|
if (par._n != 'p') {
|
||||||
|
newPars.push(par);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
newPar();
|
newPar();
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
let j = 0;
|
||||||
const lines = par._t.split('\n');
|
const lines = par._t.split('\n');
|
||||||
for (let line of lines) {
|
for (let line of lines) {
|
||||||
line = repCrLfTab(line);
|
line = repCrLfTab(line);
|
||||||
@@ -139,8 +228,11 @@ class ConvertHtml extends ConvertBase {
|
|||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l >= parIndent)
|
if (l >= parIndent) {
|
||||||
newPar();
|
if (j > 0)
|
||||||
|
newPar();
|
||||||
|
j++;
|
||||||
|
}
|
||||||
growPar(line.trim() + ' ');
|
growPar(line.trim() + ' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,6 +243,7 @@ class ConvertHtml extends ConvertBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//убираем лишнее
|
//убираем лишнее
|
||||||
|
pars = body.section._a[0];
|
||||||
for (let i = 0; i < pars.length; i++)
|
for (let i = 0; i < pars.length; i++)
|
||||||
pars[i]._t = this.repSpaces(pars[i]._t).trim();
|
pars[i]._t = this.repSpaces(pars[i]._t).trim();
|
||||||
|
|
||||||
|
|||||||
37
server/core/BookConverter/ConvertMobi.js
Normal file
37
server/core/BookConverter/ConvertMobi.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const ConvertBase = require('./ConvertBase');
|
||||||
|
|
||||||
|
class ConvertMobi extends ConvertBase {
|
||||||
|
async check(data, opts) {
|
||||||
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
|
return (this.config.useExternalBookConverter &&
|
||||||
|
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'mobi');
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
if (!await this.check(data, opts))
|
||||||
|
return false;
|
||||||
|
await this.checkExternalConverterPresent();
|
||||||
|
|
||||||
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
|
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||||
|
const mobiFile = `${outFile}.mobi`;
|
||||||
|
const fb2File = `${outFile}.fb2`;
|
||||||
|
|
||||||
|
await fs.copy(inputFiles.sourceFile, mobiFile);
|
||||||
|
|
||||||
|
let perc = 0;
|
||||||
|
await this.execConverter(this.calibrePath, [mobiFile, fb2File], () => {
|
||||||
|
perc = (perc < 100 ? perc + 5 : 50);
|
||||||
|
callback(perc);
|
||||||
|
});
|
||||||
|
|
||||||
|
return await fs.readFile(fb2File);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertMobi;
|
||||||
219
server/core/BookConverter/ConvertPdf.js
Normal file
219
server/core/BookConverter/ConvertPdf.js
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const sax = require('./sax');
|
||||||
|
const utils = require('../utils');
|
||||||
|
const ConvertHtml = require('./ConvertHtml');
|
||||||
|
|
||||||
|
class ConvertPdf extends ConvertHtml {
|
||||||
|
check(data, opts) {
|
||||||
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
|
return this.config.useExternalBookConverter &&
|
||||||
|
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'pdf';
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(notUsed, opts) {
|
||||||
|
if (!this.check(notUsed, opts))
|
||||||
|
return false;
|
||||||
|
await this.checkExternalConverterPresent();
|
||||||
|
|
||||||
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
|
const outFile = `${inputFiles.filesDir}/${utils.randomHexString(10)}.xml`;
|
||||||
|
|
||||||
|
//конвертируем в xml
|
||||||
|
let perc = 0;
|
||||||
|
await this.execConverter(this.pdfToHtmlPath, ['-c', '-s', '-xml', inputFiles.sourceFile, outFile], () => {
|
||||||
|
perc = (perc < 80 ? perc + 10 : 40);
|
||||||
|
callback(perc);
|
||||||
|
});
|
||||||
|
callback(80);
|
||||||
|
|
||||||
|
const data = await fs.readFile(outFile);
|
||||||
|
callback(90);
|
||||||
|
|
||||||
|
//парсим xml
|
||||||
|
let lines = [];
|
||||||
|
let images = [];
|
||||||
|
let loading = [];
|
||||||
|
let inText = false;
|
||||||
|
let bold = false;
|
||||||
|
let italic = false;
|
||||||
|
let title = '';
|
||||||
|
let prevTop = 0;
|
||||||
|
let i = -1;
|
||||||
|
let titleCount = 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const putImage = (curTop) => {
|
||||||
|
if (!isNaN(curTop) && images.length) {
|
||||||
|
while (images.length && images[0].top < curTop) {
|
||||||
|
i++;
|
||||||
|
lines[i] = images[0];
|
||||||
|
images.shift();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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>' : '');
|
||||||
|
|
||||||
|
lines[i].text += `${tOpen}${text}${tClose} `;
|
||||||
|
if (titleCount < 2 && text.trim() != '') {
|
||||||
|
title += text + (titleCount ? '' : ' - ');
|
||||||
|
titleCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onStartNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (!cutCounter) {
|
||||||
|
if (inText) {
|
||||||
|
switch (tag) {
|
||||||
|
case 'i':
|
||||||
|
italic = true;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
bold = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'text' && !inText) {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
const line = {
|
||||||
|
text: '',
|
||||||
|
top: parseInt((attrs.top && attrs.top.value ? attrs.top.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),
|
||||||
|
height: parseInt((attrs.height && attrs.height.value ? attrs.height.value : null), 10),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (line.width != 0 || line.height != 0) {
|
||||||
|
inText = true;
|
||||||
|
if (isNaN(line.top) || isNaN(prevTop) || (Math.abs(prevTop - line.top) > 3)) {
|
||||||
|
putImage(line.top);
|
||||||
|
i++;
|
||||||
|
lines[i] = line;
|
||||||
|
}
|
||||||
|
prevTop = line.top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'image') {
|
||||||
|
const attrs = sax.getAttrsSync(tail);
|
||||||
|
const src = (attrs.src && attrs.src.value ? attrs.src.value : '');
|
||||||
|
if (src) {
|
||||||
|
const image = {
|
||||||
|
isImage: true,
|
||||||
|
src,
|
||||||
|
data: '',
|
||||||
|
type: '',
|
||||||
|
top: parseInt((attrs.top && attrs.top.value ? attrs.top.value : null), 10) || 0,
|
||||||
|
};
|
||||||
|
loading.push(loadImage(image));
|
||||||
|
images.push(image);
|
||||||
|
images.sort((a, b) => a.top - b.top)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'page') {
|
||||||
|
putImage(100000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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();
|
||||||
|
sax.parseSync(buf, {
|
||||||
|
onStartNode, onEndNode, onTextNode
|
||||||
|
});
|
||||||
|
|
||||||
|
putImage(100000);
|
||||||
|
|
||||||
|
await Promise.all(loading);
|
||||||
|
|
||||||
|
//найдем параграфы и отступы
|
||||||
|
const indents = [];
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.isImage)
|
||||||
|
continue;
|
||||||
|
if (!isNaN(line.left)) {
|
||||||
|
indents[line.left] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let j = 0;
|
||||||
|
for (let i = 0; i < indents.length; i++) {
|
||||||
|
if (indents[i]) {
|
||||||
|
j++;
|
||||||
|
indents[i] = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
indents[0] = 0;
|
||||||
|
|
||||||
|
//формируем текст
|
||||||
|
let text = `<title>${title}</title>`;
|
||||||
|
let concat = '';
|
||||||
|
let sp = '';
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.isImage) {
|
||||||
|
text += `<fb2-image type="${line.type}" name="${line.name}">${line.data}</fb2-image>`;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (concat == '') {
|
||||||
|
const left = line.left || 0;
|
||||||
|
sp = ' '.repeat(indents[left]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let t = line.text.trim();
|
||||||
|
if (t.substr(-1) == '-') {
|
||||||
|
t = t.substr(0, t.length - 1);
|
||||||
|
concat += t;
|
||||||
|
} else {
|
||||||
|
text += sp + concat + t + "\n";
|
||||||
|
concat = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (concat)
|
||||||
|
text += sp + concat + "\n";
|
||||||
|
|
||||||
|
return await super.run(Buffer.from(text), {skipCheck: true, isText: true, cutTitle: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertPdf;
|
||||||
@@ -18,13 +18,13 @@ class ConvertRtf extends ConvertDocX {
|
|||||||
|
|
||||||
const {inputFiles, callback} = opts;
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
const outFile = `${inputFiles.fileListDir}/${path.basename(inputFiles.sourceFile)}`;
|
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||||
const rtfFile = `${outFile}.rtf`;
|
const rtfFile = `${outFile}.rtf`;
|
||||||
const docxFile = `${outFile}.docx`;
|
const docxFile = `${outFile}.docx`;
|
||||||
const fb2File = `${outFile}.fb2`;
|
const fb2File = `${outFile}.fb2`;
|
||||||
|
|
||||||
await fs.copy(inputFiles.sourceFile, rtfFile);
|
await fs.copy(inputFiles.sourceFile, rtfFile);
|
||||||
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.fileListDir, rtfFile]);
|
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.filesDir, rtfFile]);
|
||||||
|
|
||||||
return await super.convert(docxFile, fb2File, callback);
|
return await super.convert(docxFile, fb2File, callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ class ConvertSamlib extends ConvertBase {
|
|||||||
let href = attrs.src.value;
|
let href = attrs.src.value;
|
||||||
if (href[0] == '/')
|
if (href[0] == '/')
|
||||||
href = `http://${hostname}${href}`;
|
href = `http://${hostname}${href}`;
|
||||||
openTag('image', {href});
|
openTag('image', {'l:href': href});
|
||||||
inImage = true;
|
inImage = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -3,9 +3,12 @@ const FileDetector = require('../FileDetector');
|
|||||||
|
|
||||||
//порядок важен
|
//порядок важен
|
||||||
const convertClassFactory = [
|
const convertClassFactory = [
|
||||||
|
require('./ConvertEpub'),
|
||||||
|
require('./ConvertPdf'),
|
||||||
require('./ConvertRtf'),
|
require('./ConvertRtf'),
|
||||||
require('./ConvertDocX'),
|
require('./ConvertDocX'),
|
||||||
require('./ConvertDoc'),
|
require('./ConvertDoc'),
|
||||||
|
require('./ConvertMobi'),
|
||||||
require('./ConvertFb2'),
|
require('./ConvertFb2'),
|
||||||
require('./ConvertSamlib'),
|
require('./ConvertSamlib'),
|
||||||
require('./ConvertHtml'),
|
require('./ConvertHtml'),
|
||||||
@@ -25,13 +28,6 @@ class BookConverter {
|
|||||||
const selectedFileType = await this.detector.detectFile(inputFiles.selectedFile);
|
const selectedFileType = await this.detector.detectFile(inputFiles.selectedFile);
|
||||||
const data = await fs.readFile(inputFiles.selectedFile);
|
const data = await fs.readFile(inputFiles.selectedFile);
|
||||||
|
|
||||||
let selectedFileType2 = null;
|
|
||||||
let data2 = null;
|
|
||||||
if (inputFiles.nesting) {
|
|
||||||
selectedFileType2 = await this.detector.detectFile(inputFiles.nesting.selectedFile);
|
|
||||||
data2 = await fs.readFile(inputFiles.nesting.selectedFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = false;
|
let result = false;
|
||||||
for (const convert of this.convertFactory) {
|
for (const convert of this.convertFactory) {
|
||||||
result = await convert.run(data, {inputFiles, url, callback, dataType: selectedFileType});
|
result = await convert.run(data, {inputFiles, url, callback, dataType: selectedFileType});
|
||||||
@@ -39,14 +35,10 @@ class BookConverter {
|
|||||||
await fs.writeFile(outputFile, result);
|
await fs.writeFile(outputFile, result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (inputFiles.nesting) {
|
if (!result && inputFiles.nesting) {
|
||||||
result = await convert.run(data2, {inputFiles: inputFiles.nesting, url, callback, dataType: selectedFileType2});
|
result = await this.convertToFb2(inputFiles.nesting, outputFile, url, callback);
|
||||||
if (result) {
|
|
||||||
await fs.writeFile(outputFile, result);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
@@ -58,6 +50,7 @@ class BookConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
callback(100);
|
callback(100);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ const fs = require('fs-extra');
|
|||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const utils = require('./utils');
|
const extractZip = require('extract-zip');
|
||||||
const decompress = require('decompress');
|
const unbzip2Stream = require('unbzip2-stream');
|
||||||
const decompressGz = require('decompress-gz');
|
const tar = require('tar-fs')
|
||||||
const decompressBzip2 = require('decompress-bzip2');
|
|
||||||
|
|
||||||
|
const utils = require('./utils');
|
||||||
const FileDetector = require('./FileDetector');
|
const FileDetector = require('./FileDetector');
|
||||||
|
|
||||||
class FileDecompressor {
|
class FileDecompressor {
|
||||||
@@ -14,72 +14,188 @@ class FileDecompressor {
|
|||||||
this.detector = new FileDetector();
|
this.detector = new FileDetector();
|
||||||
}
|
}
|
||||||
|
|
||||||
async decompressFile(filename, outputDir) {
|
async decompressNested(filename, outputDir) {
|
||||||
|
await fs.ensureDir(outputDir);
|
||||||
|
|
||||||
const fileType = await this.detector.detectFile(filename);
|
const fileType = await this.detector.detectFile(filename);
|
||||||
|
|
||||||
let result = {
|
let result = {
|
||||||
sourceFile: filename,
|
sourceFile: filename,
|
||||||
sourceFileType: fileType,
|
sourceFileType: fileType,
|
||||||
selectedFile: filename,
|
selectedFile: filename,
|
||||||
fileListDir: outputDir,
|
filesDir: outputDir,
|
||||||
fileList: []
|
files: []
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!fileType || !(fileType.ext == 'zip' || fileType.ext == 'bz2' || fileType.ext == 'gz')) {
|
if (!fileType || !(fileType.ext == 'zip' || fileType.ext == 'bz2' || fileType.ext == 'gz' || fileType.ext == 'tar')) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//дурной decompress, поэтому в 2 этапа
|
result.files = await this.decompressTarZZ(fileType.ext, filename, outputDir);
|
||||||
//этап 1
|
|
||||||
let files = [];
|
|
||||||
try {
|
|
||||||
files = await decompress(filename, outputDir);
|
|
||||||
} catch (e) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
//этап 2
|
|
||||||
if (files.length == 0) {
|
|
||||||
try {
|
|
||||||
files = await decompress(filename, outputDir, {
|
|
||||||
inputFile: filename,
|
|
||||||
plugins: [
|
|
||||||
decompressGz(),
|
|
||||||
decompressBzip2({path: path.basename(filename)}),
|
|
||||||
]
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sel = filename;
|
let sel = filename;
|
||||||
let fileList = [];
|
|
||||||
let max = 0;
|
let max = 0;
|
||||||
if (files.length) {
|
if (result.files.length) {
|
||||||
//ищем файл с максимальным размером
|
//ищем файл с максимальным размером
|
||||||
for (let file of files) {
|
for (let file of result.files) {
|
||||||
fileList.push(file.path);
|
if (file.size > max) {
|
||||||
if (file.data.length > max) {
|
|
||||||
sel = `${outputDir}/${file.path}`;
|
sel = `${outputDir}/${file.path}`;
|
||||||
max = file.data.length;
|
max = file.size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//дурной decompress
|
|
||||||
if (sel != filename)
|
|
||||||
await fs.chmod(sel, 0o664);
|
|
||||||
|
|
||||||
result.selectedFile = sel;
|
result.selectedFile = sel;
|
||||||
result.fileList = fileList;
|
|
||||||
|
|
||||||
if (sel != filename) {
|
if (sel != filename) {
|
||||||
result.nesting = await this.decompressFile(sel, `${outputDir}/${utils.randomHexString(10)}`);
|
result.nesting = await this.decompressNested(sel, `${outputDir}/${utils.randomHexString(10)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async unpack(filename, outputDir) {
|
||||||
|
const fileType = await this.detector.detectFile(filename);
|
||||||
|
if (!fileType)
|
||||||
|
throw new Error('Не удалось определить формат файла');
|
||||||
|
|
||||||
|
return await this.decompress(fileType.ext, filename, outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
async unpackTarZZ(filename, outputDir) {
|
||||||
|
const fileType = await this.detector.detectFile(filename);
|
||||||
|
if (!fileType)
|
||||||
|
throw new Error('Не удалось определить формат файла');
|
||||||
|
|
||||||
|
return await this.decompressTarZZ(fileType.ext, filename, outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
async decompressTarZZ(fileExt, filename, outputDir) {
|
||||||
|
const files = await this.decompress(fileExt, filename, outputDir);
|
||||||
|
if (fileExt == 'tar' || files.length != 1)
|
||||||
|
return files;
|
||||||
|
|
||||||
|
const tarFilename = `${outputDir}/${files[0].path}`;
|
||||||
|
const fileType = await this.detector.detectFile(tarFilename);
|
||||||
|
if (!fileType || fileType.ext != 'tar')
|
||||||
|
return files;
|
||||||
|
|
||||||
|
const newTarFilename = `${outputDir}/${utils.randomHexString(30)}`;
|
||||||
|
await fs.rename(tarFilename, newTarFilename);
|
||||||
|
|
||||||
|
const tarFiles = await this.decompress('tar', newTarFilename, outputDir);
|
||||||
|
await fs.remove(newTarFilename);
|
||||||
|
|
||||||
|
return tarFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
async decompress(fileExt, filename, outputDir) {
|
||||||
|
let files = [];
|
||||||
|
|
||||||
|
switch (fileExt) {
|
||||||
|
case 'zip':
|
||||||
|
files = await this.unZip(filename, outputDir);
|
||||||
|
break;
|
||||||
|
case 'bz2':
|
||||||
|
files = await this.unBz2(filename, outputDir);
|
||||||
|
break;
|
||||||
|
case 'gz':
|
||||||
|
files = await this.unGz(filename, outputDir);
|
||||||
|
break;
|
||||||
|
case 'tar':
|
||||||
|
files = await this.unTar(filename, outputDir);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`FileDecompressor: неизвестный формат файла '${fileExt}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
async unZip(filename, outputDir) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const files = [];
|
||||||
|
extractZip(filename, {
|
||||||
|
dir: outputDir,
|
||||||
|
onEntry: (entry) => {
|
||||||
|
files.push({path: entry.fileName, size: entry.uncompressedSize});
|
||||||
|
}
|
||||||
|
}, (err) => {
|
||||||
|
if (err)
|
||||||
|
reject(err);
|
||||||
|
resolve(files);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
unBz2(filename, outputDir) {
|
||||||
|
return this.decompressByStream(unbzip2Stream(), filename, outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
unGz(filename, outputDir) {
|
||||||
|
return this.decompressByStream(zlib.createGunzip(), filename, outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
unTar(filename, outputDir) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const files = [];
|
||||||
|
|
||||||
|
const tarExtract = tar.extract(outputDir, {
|
||||||
|
map: (header) => {
|
||||||
|
files.push({path: header.name, size: header.size});
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tarExtract.on('finish', () => {
|
||||||
|
resolve(files);
|
||||||
|
});
|
||||||
|
|
||||||
|
tarExtract.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
const inputStream = fs.createReadStream(filename);
|
||||||
|
inputStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
inputStream.pipe(tarExtract);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
decompressByStream(stream, filename, outputDir) {
|
||||||
|
return new Promise(async(resolve, reject) => {
|
||||||
|
const file = {path: path.parse(filename).name};
|
||||||
|
let outFilename = `${outputDir}/${file.path}`;
|
||||||
|
if (await fs.pathExists(outFilename)) {
|
||||||
|
file.path = `${utils.randomHexString(10)}-${file.path}`;
|
||||||
|
outFilename = `${outputDir}/${file.path}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputStream = fs.createReadStream(filename);
|
||||||
|
const outputStream = fs.createWriteStream(outFilename);
|
||||||
|
|
||||||
|
outputStream.on('finish', async() => {
|
||||||
|
try {
|
||||||
|
file.size = (await fs.stat(outFilename)).size;
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
resolve([file]);
|
||||||
|
});
|
||||||
|
|
||||||
|
inputStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
outputStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
inputStream.pipe(stream).pipe(outputStream);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async gzipBuffer(buf) {
|
async gzipBuffer(buf) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
zlib.gzip(buf, {level: 1}, (err, result) => {
|
zlib.gzip(buf, {level: 1}, (err, result) => {
|
||||||
|
|||||||
@@ -128,21 +128,10 @@
|
|||||||
{ "type": "equal", "start": 3, "end": 4, "bytes": "08" }
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "08" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{ "type": "notEqual", "start": 36, "end": 58, "bytes": "70656170706c69636174696f6e2f657075622b7a6970" },
|
|
||||||
{ "type": "notEqual", "start": 30, "end": 50, "bytes": "4d4554412d494e462f6d6f7a696c6c612e727361" }
|
{ "type": "notEqual", "start": 30, "end": 50, "bytes": "4d4554412d494e462f6d6f7a696c6c612e727361" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
"type": "epub",
|
|
||||||
"ext": "epub",
|
|
||||||
"mime": "application/epub+zip",
|
|
||||||
"rules": [
|
|
||||||
{ "type": "equal", "start": 0, "end": 4, "bytes": "504b0304" },
|
|
||||||
{ "type": "equal", "start": 36, "end": 58, "bytes": "70656170706c69636174696f6e2f657075622b7a6970" }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"type": "xpi",
|
"type": "xpi",
|
||||||
"ext": "xpi",
|
"ext": "xpi",
|
||||||
@@ -722,6 +711,15 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "mobi",
|
||||||
|
"ext": "mobi",
|
||||||
|
"mime": "application/x-mobipocket-ebook",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 64, "end": 68, "bytes": "4d4f4249" }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -63,7 +63,14 @@ class ReaderWorker {
|
|||||||
//decompress
|
//decompress
|
||||||
wState.set({state: 'decompress', step: 2, progress: 0});
|
wState.set({state: 'decompress', step: 2, progress: 0});
|
||||||
decompDir = `${this.config.tempDownloadDir}/${decompDirname}`;
|
decompDir = `${this.config.tempDownloadDir}/${decompDirname}`;
|
||||||
const decompFiles = await this.decomp.decompressFile(downloadedFilename, decompDir);
|
let decompFiles = {};
|
||||||
|
try {
|
||||||
|
decompFiles = await this.decomp.decompressNested(downloadedFilename, decompDir);
|
||||||
|
} catch (e) {
|
||||||
|
if (this.config.branch == 'development')
|
||||||
|
console.error(e);
|
||||||
|
throw new Error('Ошибка распаковки');
|
||||||
|
}
|
||||||
wState.set({progress: 100});
|
wState.set({progress: 100});
|
||||||
|
|
||||||
//конвертирование в fb2
|
//конвертирование в fb2
|
||||||
|
|||||||
Reference in New Issue
Block a user