import/export: Delete unnecessary comments
This commit is contained in:
parent
fe1eceb6b5
commit
b6c2586920
3 changed files with 9 additions and 71 deletions
|
@ -33,17 +33,10 @@ const util = require('util');
|
|||
const fsp_writeFile = util.promisify(fs.writeFile);
|
||||
const fsp_unlink = util.promisify(fs.unlink);
|
||||
|
||||
let convertor = null;
|
||||
|
||||
// load abiword only if it is enabled
|
||||
if (settings.abiword != null) {
|
||||
convertor = require('../utils/Abiword');
|
||||
}
|
||||
|
||||
// Use LibreOffice if an executable has been defined in the settings
|
||||
if (settings.soffice != null) {
|
||||
convertor = require('../utils/LibreOffice');
|
||||
}
|
||||
const convertor =
|
||||
settings.soffice != null ? require('../utils/LibreOffice')
|
||||
: settings.abiword != null ? require('../utils/Abiword')
|
||||
: null;
|
||||
|
||||
const tempDirectory = os.tmpdir();
|
||||
|
||||
|
|
|
@ -32,30 +32,16 @@ if (os.type().indexOf('Windows') > -1) {
|
|||
let stdoutBuffer = '';
|
||||
|
||||
doConvertTask = (task, callback) => {
|
||||
// span an abiword process to perform the conversion
|
||||
const abiword = spawn(settings.abiword, [`--to=${task.destFile}`, task.srcFile]);
|
||||
|
||||
// delegate the processing of stdout to another function
|
||||
abiword.stdout.on('data', (data) => {
|
||||
// add data to buffer
|
||||
stdoutBuffer += data.toString();
|
||||
});
|
||||
|
||||
// append error messages to the buffer
|
||||
abiword.stderr.on('data', (data) => {
|
||||
stdoutBuffer += data.toString();
|
||||
});
|
||||
|
||||
// throw exceptions if abiword is dieing
|
||||
abiword.stdout.on('data', (data) => { stdoutBuffer += data.toString(); });
|
||||
abiword.stderr.on('data', (data) => { stdoutBuffer += data.toString(); });
|
||||
abiword.on('exit', (code) => {
|
||||
if (code !== 0) {
|
||||
return callback(`Abiword died with exit code ${code}`);
|
||||
}
|
||||
|
||||
if (stdoutBuffer !== '') {
|
||||
console.log(stdoutBuffer);
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
@ -67,45 +53,27 @@ if (os.type().indexOf('Windows') > -1) {
|
|||
// communicate with it via stdin/stdout
|
||||
// thats much faster, about factor 10
|
||||
} else {
|
||||
// spawn the abiword process
|
||||
let abiword;
|
||||
let stdoutCallback = null;
|
||||
const spawnAbiword = () => {
|
||||
abiword = spawn(settings.abiword, ['--plugin', 'AbiCommand']);
|
||||
let stdoutBuffer = '';
|
||||
let firstPrompt = true;
|
||||
|
||||
// append error messages to the buffer
|
||||
abiword.stderr.on('data', (data) => {
|
||||
stdoutBuffer += data.toString();
|
||||
});
|
||||
|
||||
// abiword died, let's restart abiword and return an error with the callback
|
||||
abiword.stderr.on('data', (data) => { stdoutBuffer += data.toString(); });
|
||||
abiword.on('exit', (code) => {
|
||||
spawnAbiword();
|
||||
stdoutCallback(`Abiword died with exit code ${code}`);
|
||||
});
|
||||
|
||||
// delegate the processing of stdout to a other function
|
||||
abiword.stdout.on('data', (data) => {
|
||||
// add data to buffer
|
||||
stdoutBuffer += data.toString();
|
||||
|
||||
// we're searching for the prompt, cause this means everything we need is in the buffer
|
||||
if (stdoutBuffer.search('AbiWord:>') !== -1) {
|
||||
// filter the feedback message
|
||||
const err = stdoutBuffer.search('OK') !== -1 ? null : stdoutBuffer;
|
||||
|
||||
// reset the buffer
|
||||
stdoutBuffer = '';
|
||||
|
||||
// call the callback with the error message
|
||||
// skip the first prompt
|
||||
if (stdoutCallback != null && !firstPrompt) {
|
||||
stdoutCallback(err);
|
||||
stdoutCallback = null;
|
||||
}
|
||||
|
||||
firstPrompt = false;
|
||||
}
|
||||
});
|
||||
|
@ -114,7 +82,6 @@ if (os.type().indexOf('Windows') > -1) {
|
|||
|
||||
doConvertTask = (task, callback) => {
|
||||
abiword.stdin.write(`convert ${task.srcFile} ${task.destFile} ${task.type}\n`);
|
||||
// create a callback that calls the task callback and the caller callback
|
||||
stdoutCallback = (err) => {
|
||||
callback();
|
||||
console.log('queue continue');
|
||||
|
@ -126,7 +93,6 @@ if (os.type().indexOf('Windows') > -1) {
|
|||
};
|
||||
};
|
||||
|
||||
// Queue with the converts we have to do
|
||||
const queue = async.queue(doConvertTask, 1);
|
||||
exports.convertFile = (srcFile, destFile, type, callback) => {
|
||||
queue.push({srcFile, destFile, type, callback});
|
||||
|
|
|
@ -31,10 +31,6 @@ const doConvertTask = (task, callback) => {
|
|||
const tmpDir = os.tmpdir();
|
||||
|
||||
async.series([
|
||||
/*
|
||||
* use LibreOffice to convert task.srcFile to another format, given in
|
||||
* task.type
|
||||
*/
|
||||
(callback) => {
|
||||
libreOfficeLogger.debug(
|
||||
`Converting ${task.srcFile} to format ${task.type}. The result will be put in ${tmpDir}`
|
||||
|
@ -57,32 +53,18 @@ const doConvertTask = (task, callback) => {
|
|||
soffice.stdin.pause(); // required to kill hanging threads
|
||||
soffice.kill();
|
||||
}, 120000);
|
||||
|
||||
let stdoutBuffer = '';
|
||||
|
||||
// Delegate the processing of stdout to another function
|
||||
soffice.stdout.on('data', (data) => {
|
||||
stdoutBuffer += data.toString();
|
||||
});
|
||||
|
||||
// Append error messages to the buffer
|
||||
soffice.stderr.on('data', (data) => {
|
||||
stdoutBuffer += data.toString();
|
||||
});
|
||||
|
||||
soffice.stdout.on('data', (data) => { stdoutBuffer += data.toString(); });
|
||||
soffice.stderr.on('data', (data) => { stdoutBuffer += data.toString(); });
|
||||
soffice.on('exit', (code) => {
|
||||
clearTimeout(hangTimeout);
|
||||
if (code !== 0) {
|
||||
// Throw an exception if libreoffice failed
|
||||
return callback(`LibreOffice died with exit code ${code} and message: ${stdoutBuffer}`);
|
||||
}
|
||||
|
||||
// if LibreOffice exited succesfully, go on with processing
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
// Move the converted file to the correct place
|
||||
(callback) => {
|
||||
const filename = path.basename(task.srcFile);
|
||||
const sourceFile = `${filename.substr(0, filename.lastIndexOf('.'))}.${task.fileExtension}`;
|
||||
|
@ -91,10 +73,7 @@ const doConvertTask = (task, callback) => {
|
|||
fs.rename(sourcePath, task.destFile, callback);
|
||||
},
|
||||
], (err) => {
|
||||
// Invoke the callback for the local queue
|
||||
callback();
|
||||
|
||||
// Invoke the callback for the task
|
||||
task.callback(err);
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue