Добавил конвертер файлов rtf
This commit is contained in:
@@ -24,9 +24,7 @@ class ConvertDoc extends ConvertDocX {
|
||||
const fb2File = `${outFile}.fb2`;
|
||||
|
||||
await fs.copy(inputFiles.sourceFile, docFile);
|
||||
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.fileListDir, docFile], (data) => {
|
||||
console.log(data.toString());
|
||||
});
|
||||
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.fileListDir, docFile]);
|
||||
|
||||
return await super.convert(docxFile, fb2File, callback);
|
||||
}
|
||||
|
||||
33
server/core/BookConverter/ConvertRtf.js
Normal file
33
server/core/BookConverter/ConvertRtf.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
|
||||
const ConvertDocX = require('./ConvertDocX');
|
||||
|
||||
class ConvertRtf extends ConvertDocX {
|
||||
check(data, opts) {
|
||||
const {inputFiles} = opts;
|
||||
|
||||
return this.config.useExternalBookConverter &&
|
||||
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'rtf';
|
||||
}
|
||||
|
||||
async run(data, opts) {
|
||||
if (!this.check(data, opts))
|
||||
return false;
|
||||
await this.checkExternalConverterPresent();
|
||||
|
||||
const {inputFiles, callback} = opts;
|
||||
|
||||
const outFile = `${inputFiles.fileListDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||
const rtfFile = `${outFile}.rtf`;
|
||||
const docxFile = `${outFile}.docx`;
|
||||
const fb2File = `${outFile}.fb2`;
|
||||
|
||||
await fs.copy(inputFiles.sourceFile, rtfFile);
|
||||
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.fileListDir, rtfFile]);
|
||||
|
||||
return await super.convert(docxFile, fb2File, callback);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConvertRtf;
|
||||
@@ -3,6 +3,7 @@ const FileDetector = require('../FileDetector');
|
||||
|
||||
//порядок важен
|
||||
const convertClassFactory = [
|
||||
require('./ConvertRtf'),
|
||||
require('./ConvertDocX'),
|
||||
require('./ConvertDoc'),
|
||||
require('./ConvertFb2'),
|
||||
|
||||
Reference in New Issue
Block a user