Добавлена частичная поддержка формата Djvu
This commit is contained in:
@@ -22,6 +22,7 @@ class ReaderController extends BaseController {
|
||||
enableSitesFilter: (request.hasOwnProperty('enableSitesFilter') ? request.enableSitesFilter : true),
|
||||
skipCheck: (request.hasOwnProperty('skipCheck') ? request.skipCheck : false),
|
||||
isText: (request.hasOwnProperty('isText') ? request.isText : false),
|
||||
uploadFileName: (request.hasOwnProperty('uploadFileName') ? request.uploadFileName : false),
|
||||
});
|
||||
const state = this.workerState.getState(workerId);
|
||||
return (state ? state : {});
|
||||
|
||||
@@ -15,6 +15,7 @@ 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
|
||||
@@ -30,6 +31,9 @@ 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) {
|
||||
|
||||
39
server/core/Reader/BookConverter/ConvertDjvu.js
Normal file
39
server/core/Reader/BookConverter/ConvertDjvu.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
|
||||
const ConvertPdf = require('./ConvertPdf');
|
||||
|
||||
class ConvertRtf extends ConvertPdf {
|
||||
check(data, opts) {
|
||||
const {inputFiles} = opts;
|
||||
|
||||
return this.config.useExternalBookConverter &&
|
||||
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'djvu';
|
||||
}
|
||||
|
||||
async run(data, opts) {
|
||||
if (!this.check(data, opts))
|
||||
return false;
|
||||
await this.checkExternalConverterPresent();
|
||||
|
||||
const {inputFiles, callback, abort} = opts;
|
||||
|
||||
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||
const pdfFile = `${outFile}.pdf`;
|
||||
|
||||
let perc = 0;
|
||||
await this.execConverter(this.ddjvuPath, ['-format=pdf', '-quality=85', '-verbose', inputFiles.sourceFile, pdfFile], () => {
|
||||
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}`);
|
||||
}
|
||||
|
||||
return await super.run(null, Object.assign({}, opts, {pdfFile, skipCheck: true}));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConvertRtf;
|
||||
@@ -14,17 +14,20 @@ class ConvertPdf extends ConvertHtml {
|
||||
}
|
||||
|
||||
async run(notUsed, opts) {
|
||||
if (!this.check(notUsed, opts))
|
||||
return false;
|
||||
if (!opts.skipCheck) {
|
||||
if (!this.check(notUsed, opts))
|
||||
return false;
|
||||
}
|
||||
await this.checkExternalConverterPresent();
|
||||
|
||||
const {inputFiles, callback, abort} = opts;
|
||||
const {inputFiles, callback, abort, uploadFileName} = opts;
|
||||
|
||||
const inpFile = (opts.pdfFile ? opts.pdfFile : inputFiles.sourceFile);
|
||||
const outFile = `${inputFiles.filesDir}/${utils.randomHexString(10)}.xml`;
|
||||
|
||||
//конвертируем в xml
|
||||
let perc = 0;
|
||||
await this.execConverter(this.pdfToHtmlPath, ['-nodrm', '-c', '-s', '-xml', inputFiles.sourceFile, outFile], () => {
|
||||
await this.execConverter(this.pdfToHtmlPath, ['-nodrm', '-c', '-s', '-xml', inpFile, outFile], () => {
|
||||
perc = (perc < 80 ? perc + 10 : 40);
|
||||
callback(perc);
|
||||
}, abort);
|
||||
@@ -186,6 +189,8 @@ class ConvertPdf extends ConvertHtml {
|
||||
indents[0] = 0;
|
||||
|
||||
//формируем текст
|
||||
if (!title && uploadFileName)
|
||||
title = uploadFileName;
|
||||
let text = `<title>${title}</title>`;
|
||||
let concat = '';
|
||||
let sp = '';
|
||||
|
||||
@@ -4,6 +4,7 @@ const FileDetector = require('../../FileDetector');
|
||||
//порядок важен
|
||||
const convertClassFactory = [
|
||||
require('./ConvertEpub'),
|
||||
require('./ConvertDjvu'),
|
||||
require('./ConvertPdf'),
|
||||
require('./ConvertRtf'),
|
||||
require('./ConvertDocX'),
|
||||
|
||||
Reference in New Issue
Block a user