Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce7ae84e0f | ||
|
|
01eb545f15 | ||
|
|
706738c7f1 | ||
|
|
6afa78cde9 | ||
|
|
71f5710bba | ||
|
|
0d87043f91 | ||
|
|
e25375fb7a | ||
|
|
41822999c8 | ||
|
|
07444bc7c2 | ||
|
|
ec48e5b0b7 | ||
|
|
e8e2e9297f | ||
|
|
4f871dd5ca | ||
|
|
f5f07a591a | ||
|
|
4c11e6918f | ||
|
|
403b9c0508 | ||
|
|
ee8ba75371 | ||
|
|
a2773fb180 | ||
|
|
ca36d588fc |
@@ -593,12 +593,6 @@ class Reader extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
refreshBookSplitToPara() {
|
||||
if (this.mostRecentBook()) {
|
||||
this.loadBook({url: this.mostRecentBook().url, skipCheck: true, isText: true, force: true});
|
||||
}
|
||||
}
|
||||
|
||||
recentBooksClose() {
|
||||
this.recentBooksActive = false;
|
||||
}
|
||||
@@ -688,9 +682,14 @@ class Reader extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
refreshBook() {
|
||||
if (this.mostRecentBook()) {
|
||||
this.loadBook({url: this.mostRecentBook().url, force: true});
|
||||
refreshBook(mode) {
|
||||
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});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -882,6 +881,7 @@ class Reader extends Vue {
|
||||
wasOpened = (wasOpened ? wasOpened : {});
|
||||
const bookPos = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos);
|
||||
const bookPosSeen = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPosSeen);
|
||||
const uploadFileName = (opts.uploadFileName ? opts.uploadFileName : '');
|
||||
|
||||
let book = null;
|
||||
|
||||
@@ -929,7 +929,7 @@ class Reader extends Vue {
|
||||
skipCheck: (opts.skipCheck ? true : false),
|
||||
isText: (opts.isText ? true : false),
|
||||
enableSitesFilter: this.enableSitesFilter,
|
||||
uploadFileName: (opts.uploadFileName ? opts.uploadFileName : ''),
|
||||
uploadFileName
|
||||
},
|
||||
(state) => {
|
||||
progress.setState(state);
|
||||
@@ -945,7 +945,7 @@ class Reader extends Vue {
|
||||
});
|
||||
|
||||
// добавляем в историю
|
||||
await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, addedBook));
|
||||
await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen, uploadFileName}, addedBook));
|
||||
this.mostRecentBook();
|
||||
this.addAction(bookPos);
|
||||
this.updateRoute(true);
|
||||
@@ -982,7 +982,7 @@ class Reader extends Vue {
|
||||
|
||||
progress.hide(); this.progressActive = false;
|
||||
|
||||
await this.loadBook({url, uploadFileName: opts.file.name});
|
||||
await this.loadBook({url, uploadFileName: opts.file.name, force: true});
|
||||
} catch (e) {
|
||||
progress.hide(); this.progressActive = false;
|
||||
this.loaderActive = true;
|
||||
@@ -1054,7 +1054,7 @@ class Reader extends Vue {
|
||||
this.copyTextToggle();
|
||||
break;
|
||||
case 'splitToPara':
|
||||
this.refreshBookSplitToPara();
|
||||
this.refreshBook('split');
|
||||
break;
|
||||
case 'refresh':
|
||||
this.refreshBook();
|
||||
|
||||
@@ -216,8 +216,15 @@ class ServerStorage extends Vue {
|
||||
}
|
||||
|
||||
error(message) {
|
||||
if (this.showServerStorageMessages && !this.offlineModeActive)
|
||||
this.$root.notify.error(message);
|
||||
if (this.showServerStorageMessages && !this.offlineModeActive) {
|
||||
this.errorMessageCounter = (this.errorMessageCounter ? this.errorMessageCounter + 1 : 1);
|
||||
const hint = (this.errorMessageCounter < 2 ? '' :
|
||||
'<div><br>Надоело это сообщение? Добавьте в настройках кнопку "Автономный режим" ' +
|
||||
'<i class="la la-unlink" style="font-size: 20px; color: white"></i> на панель инструментов и активируйте ее.</div>'
|
||||
);
|
||||
|
||||
this.$root.notify.error(message + hint);
|
||||
}
|
||||
}
|
||||
|
||||
async loadSettings(force = false, doNotifySuccess = true) {
|
||||
|
||||
@@ -38,6 +38,8 @@ sudo apt install rar
|
||||
sudo apt install libreoffice
|
||||
sudo apt install poppler-utils
|
||||
sudo apt install djvulibre-bin
|
||||
sudo apt install libtiff-tools
|
||||
sudo apt install graphicsmagick-imagemagick-compat
|
||||
```
|
||||
|
||||
### nginx, server config
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
sudo -H -u www-data bash -c "cd /var/www; /home/liberama/liberama" &
|
||||
sudo -H -u www-data bash -c "cd /var/www; /home/liberama/liberama" & disown
|
||||
sudo service cron start
|
||||
|
||||
@@ -135,7 +135,7 @@ class FileDecompressor {
|
||||
try {
|
||||
return await zip.unpack(filename, outputDir, {
|
||||
limitFileSize: this.limitFileSize,
|
||||
limitFileCount: 1000,
|
||||
limitFileCount: 10000,
|
||||
decodeEntryNameCallback: (nameRaw) => {
|
||||
return utils.bufferRemoveZeroes(nameRaw);
|
||||
}
|
||||
@@ -144,7 +144,7 @@ class FileDecompressor {
|
||||
fs.emptyDir(outputDir);
|
||||
return await zip.unpack(filename, outputDir, {
|
||||
limitFileSize: this.limitFileSize,
|
||||
limitFileCount: 1000,
|
||||
limitFileCount: 10000,
|
||||
decodeEntryNameCallback: (nameRaw) => {
|
||||
nameRaw = utils.bufferRemoveZeroes(nameRaw);
|
||||
const enc = textUtils.getEncodingLite(nameRaw);
|
||||
@@ -171,7 +171,7 @@ class FileDecompressor {
|
||||
|
||||
if (this.limitFileSize) {
|
||||
if ((await fs.stat(filename)).size > this.limitFileSize) {
|
||||
reject('Файл слишком большой');
|
||||
reject(new Error('Файл слишком большой'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class LimitedQueue {
|
||||
get(onPlaceChange) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.destroyed)
|
||||
reject('destroyed');
|
||||
reject(new Error('destroyed'));
|
||||
|
||||
const take = () => {
|
||||
if (this.freed <= 0)
|
||||
@@ -73,7 +73,7 @@ class LimitedQueue {
|
||||
if (onPlaceChange)
|
||||
onPlaceChange(this.listeners.length);
|
||||
} else {
|
||||
reject('Превышен размер очереди ожидания');
|
||||
reject(new Error('Превышен размер очереди ожидания'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -15,7 +15,6 @@ class ConvertBase {
|
||||
this.calibrePath = `${config.dataDir}/calibre/ebook-convert`;
|
||||
this.sofficePath = '/usr/bin/soffice';
|
||||
this.pdfToHtmlPath = '/usr/bin/pdftohtml';
|
||||
this.ddjvuPath = '/usr/bin/ddjvu';
|
||||
}
|
||||
|
||||
async run(data, opts) {// eslint-disable-line no-unused-vars
|
||||
@@ -31,9 +30,6 @@ class ConvertBase {
|
||||
|
||||
if (!await fs.pathExists(this.pdfToHtmlPath))
|
||||
throw new Error('Внешний конвертер pdftohtml не найден');
|
||||
|
||||
if (!await fs.pathExists(this.ddjvuPath))
|
||||
throw new Error('Внешний конвертер ddjvu не найден');
|
||||
}
|
||||
|
||||
async execConverter(path, args, onData, abort) {
|
||||
@@ -46,21 +42,32 @@ class ConvertBase {
|
||||
throw new Error('Слишком большая очередь конвертирования. Пожалуйста, попробуйте позже.');
|
||||
}
|
||||
|
||||
abort = (abort ? abort : () => false);
|
||||
const myAbort = () => {
|
||||
return q.abort() || abort();
|
||||
}
|
||||
|
||||
try {
|
||||
if (myAbort())
|
||||
throw new Error('abort');
|
||||
|
||||
const result = await utils.spawnProcess(path, {
|
||||
killAfter: 3600,//1 час
|
||||
args,
|
||||
onData: (data) => {
|
||||
q.resetTimeout();
|
||||
if (queue.freed > 0)
|
||||
q.resetTimeout();
|
||||
onData(data);
|
||||
},
|
||||
//будем периодически проверять работу конвертера и если очереди нет, то разрешаем работу пинком onData
|
||||
onUsage: (stats) => {
|
||||
if (queue.freed > 1 && stats.cpu >= 10)
|
||||
if (queue.freed > 0 && stats.cpu >= 10) {
|
||||
q.resetTimeout();
|
||||
onData('.');
|
||||
}
|
||||
},
|
||||
onUsageInterval: 10,
|
||||
abort
|
||||
abort: myAbort
|
||||
});
|
||||
if (result.code != 0) {
|
||||
const error = `${result.code}|FORLOG|, exec: ${path}, args: ${args.join(' ')}, stdout: ${result.stdout}, stderr: ${result.stderr}`;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const utils = require('../../utils');
|
||||
|
||||
const ConvertPdf = require('./ConvertPdf');
|
||||
const ConvertHtml = require('./ConvertHtml');
|
||||
|
||||
class ConvertRtf extends ConvertPdf {
|
||||
class ConvertDjvu extends ConvertHtml {
|
||||
check(data, opts) {
|
||||
const {inputFiles} = opts;
|
||||
|
||||
@@ -14,26 +15,88 @@ class ConvertRtf extends ConvertPdf {
|
||||
async run(data, opts) {
|
||||
if (!this.check(data, opts))
|
||||
return false;
|
||||
await this.checkExternalConverterPresent();
|
||||
|
||||
const {inputFiles, callback, abort} = opts;
|
||||
const {inputFiles, callback, abort, uploadFileName} = opts;
|
||||
|
||||
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||
const pdfFile = `${outFile}.pdf`;
|
||||
const ddjvuPath = '/usr/bin/ddjvu';
|
||||
if (!await fs.pathExists(ddjvuPath))
|
||||
throw new Error('Внешний конвертер ddjvu не найден');
|
||||
|
||||
const tiffsplitPath = '/usr/bin/tiffsplit';
|
||||
if (!await fs.pathExists(tiffsplitPath))
|
||||
throw new Error('Внешний конвертер tiffsplitPath не найден');
|
||||
|
||||
const mogrifyPath = '/usr/bin/mogrify';
|
||||
if (!await fs.pathExists(mogrifyPath))
|
||||
throw new Error('Внешний конвертер mogrifyPath не найден');
|
||||
|
||||
const dir = `${inputFiles.filesDir}/`;
|
||||
const inpFile = `${dir}${path.basename(inputFiles.sourceFile)}`;
|
||||
const tifFile = `${inpFile}.tif`;
|
||||
|
||||
//конвертируем в tiff
|
||||
let perc = 0;
|
||||
await this.execConverter(this.ddjvuPath, ['-format=pdf', '-quality=85', '-verbose', inputFiles.sourceFile, pdfFile], () => {
|
||||
await this.execConverter(ddjvuPath, ['-format=tiff', '-quality=50', '-verbose', inputFiles.sourceFile, tifFile], () => {
|
||||
perc = (perc < 100 ? perc + 1 : 40);
|
||||
callback(perc);
|
||||
}, abort);
|
||||
|
||||
const pdfFileSize = (await fs.stat(pdfFile)).size;
|
||||
if (pdfFileSize > 2*this.config.maxUploadFileSize) {
|
||||
throw new Error(`Файл для конвертирования слишком большой|FORLOG| ${pdfFileSize} > ${2*this.config.maxUploadFileSize}`);
|
||||
const tifFileSize = (await fs.stat(tifFile)).size;
|
||||
let limitSize = 3*this.config.maxUploadFileSize;
|
||||
if (tifFileSize > limitSize) {
|
||||
throw new Error(`Файл для конвертирования слишком большой|FORLOG| ${tifFileSize} > ${limitSize}`);
|
||||
}
|
||||
|
||||
return await super.run(null, Object.assign({}, opts, {pdfFile, skipCheck: true}));
|
||||
//разбиваем на файлы
|
||||
await this.execConverter(tiffsplitPath, [tifFile, dir], null, abort);
|
||||
|
||||
await fs.remove(tifFile);
|
||||
|
||||
//конвертируем в jpg
|
||||
await this.execConverter(mogrifyPath, ['-quality', '20', '-scale', '2048', '-verbose', '-format', 'jpg', `${dir}*.tif`], () => {
|
||||
perc = (perc < 100 ? perc + 1 : 40);
|
||||
callback(perc);
|
||||
}, abort);
|
||||
|
||||
//читаем изображения
|
||||
const loadImage = async(image) => {
|
||||
image.data = (await fs.readFile(image.file)).toString('base64');
|
||||
image.name = path.basename(image.file);
|
||||
}
|
||||
|
||||
let files = [];
|
||||
await utils.findFiles(async(file) => {
|
||||
if (path.extname(file) == '.jpg')
|
||||
files.push({name: file, base: path.basename(file)});
|
||||
}, dir);
|
||||
|
||||
files.sort((a, b) => a.base.localeCompare(b.base));
|
||||
|
||||
let images = [];
|
||||
let loading = [];
|
||||
files.forEach(f => {
|
||||
const image = {file: f.name};
|
||||
images.push(image);
|
||||
loading.push(loadImage(image));
|
||||
});
|
||||
|
||||
await Promise.all(loading);
|
||||
|
||||
//формируем текст
|
||||
limitSize = 2*this.config.maxUploadFileSize;
|
||||
let title = '';
|
||||
if (uploadFileName)
|
||||
title = uploadFileName;
|
||||
let text = `<title>${title}</title>`;
|
||||
for (const image of images) {
|
||||
text += `<fb2-image type="image/jpeg" name="${image.name}">${image.data}</fb2-image>`;
|
||||
|
||||
if (text.length > limitSize) {
|
||||
throw new Error(`Файл для конвертирования слишком большой|FORLOG| text.length: ${text.length} > ${limitSize}`);
|
||||
}
|
||||
}
|
||||
return await super.run(Buffer.from(text), {skipCheck: true, isText: true, cutTitle: true});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConvertRtf;
|
||||
module.exports = ConvertDjvu;
|
||||
|
||||
@@ -14,15 +14,14 @@ class ConvertPdf extends ConvertHtml {
|
||||
}
|
||||
|
||||
async run(notUsed, opts) {
|
||||
if (!opts.skipCheck) {
|
||||
if (!this.check(notUsed, opts))
|
||||
return false;
|
||||
}
|
||||
if (!this.check(notUsed, opts))
|
||||
return false;
|
||||
|
||||
await this.checkExternalConverterPresent();
|
||||
|
||||
const {inputFiles, callback, abort, uploadFileName} = opts;
|
||||
|
||||
const inpFile = (opts.pdfFile ? opts.pdfFile : inputFiles.sourceFile);
|
||||
const inpFile = inputFiles.sourceFile;
|
||||
const outFile = `${inputFiles.filesDir}/${utils.randomHexString(10)}.xml`;
|
||||
|
||||
//конвертируем в xml
|
||||
@@ -189,12 +188,17 @@ class ConvertPdf extends ConvertHtml {
|
||||
indents[0] = 0;
|
||||
|
||||
//формируем текст
|
||||
const limitSize = 2*this.config.maxUploadFileSize;
|
||||
if (!title && uploadFileName)
|
||||
title = uploadFileName;
|
||||
let text = `<title>${title}</title>`;
|
||||
let concat = '';
|
||||
let sp = '';
|
||||
for (const line of lines) {
|
||||
if (text.length > limitSize) {
|
||||
throw new Error(`Файл для конвертирования слишком большой|FORLOG| text.length: ${text.length} > ${limitSize}`);
|
||||
}
|
||||
|
||||
if (line.isImage) {
|
||||
text += `<fb2-image type="${line.type}" name="${line.name}">${line.data}</fb2-image>`;
|
||||
continue;
|
||||
|
||||
@@ -12,7 +12,7 @@ const utils = require('../utils');
|
||||
const log = new (require('../AppLogger'))().log;//singleton
|
||||
|
||||
const cleanDirPeriod = 60*60*1000;//1 раз в час
|
||||
const queue = new LimitedQueue(5, 100, 4*60*1000);//4 минуты ожидание подвижек
|
||||
const queue = new LimitedQueue(5, 100, 2*60*1000 + 15000);//2 минуты ожидание подвижек
|
||||
|
||||
let instance = null;
|
||||
|
||||
@@ -130,7 +130,8 @@ class ReaderWorker {
|
||||
convertFilename = `${this.config.tempDownloadDir}/${tempFilename2}`;
|
||||
await this.bookConverter.convertToFb2(decompFiles, convertFilename, opts, progress => {
|
||||
wState.set({progress});
|
||||
q.resetTimeout();
|
||||
if (queue.freed > 0)
|
||||
q.resetTimeout();
|
||||
}, q.abort);
|
||||
|
||||
//сжимаем файл в tmp, если там уже нет с тем же именем-sha256
|
||||
|
||||
@@ -76,13 +76,13 @@ class ZipStreamer {
|
||||
if (limitFileCount || limitFileSize || decodeEntryNameCallback) {
|
||||
const entries = Object.values(unzip.entries());
|
||||
if (limitFileCount && entries.length > limitFileCount) {
|
||||
reject('Слишком много файлов');
|
||||
reject(new Error('Слишком много файлов'));
|
||||
return;
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
if (limitFileSize && !entry.isDirectory && entry.size > limitFileSize) {
|
||||
reject('Файл слишком большой');
|
||||
reject(new Error('Файл слишком большой'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user