mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
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_writeFile = util.promisify(fs.writeFile);
|
||||||
const fsp_unlink = util.promisify(fs.unlink);
|
const fsp_unlink = util.promisify(fs.unlink);
|
||||||
|
|
||||||
let convertor = null;
|
const convertor =
|
||||||
|
settings.soffice != null ? require('../utils/LibreOffice')
|
||||||
// load abiword only if it is enabled
|
: settings.abiword != null ? require('../utils/Abiword')
|
||||||
if (settings.abiword != null) {
|
: 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 tempDirectory = os.tmpdir();
|
const tempDirectory = os.tmpdir();
|
||||||
|
|
||||||
|
|
|
@ -32,30 +32,16 @@ if (os.type().indexOf('Windows') > -1) {
|
||||||
let stdoutBuffer = '';
|
let stdoutBuffer = '';
|
||||||
|
|
||||||
doConvertTask = (task, callback) => {
|
doConvertTask = (task, callback) => {
|
||||||
// span an abiword process to perform the conversion
|
|
||||||
const abiword = spawn(settings.abiword, [`--to=${task.destFile}`, task.srcFile]);
|
const abiword = spawn(settings.abiword, [`--to=${task.destFile}`, task.srcFile]);
|
||||||
|
abiword.stdout.on('data', (data) => { stdoutBuffer += data.toString(); });
|
||||||
// delegate the processing of stdout to another function
|
abiword.stderr.on('data', (data) => { stdoutBuffer += data.toString(); });
|
||||||
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.on('exit', (code) => {
|
abiword.on('exit', (code) => {
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
return callback(`Abiword died with exit code ${code}`);
|
return callback(`Abiword died with exit code ${code}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stdoutBuffer !== '') {
|
if (stdoutBuffer !== '') {
|
||||||
console.log(stdoutBuffer);
|
console.log(stdoutBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -67,45 +53,27 @@ if (os.type().indexOf('Windows') > -1) {
|
||||||
// communicate with it via stdin/stdout
|
// communicate with it via stdin/stdout
|
||||||
// thats much faster, about factor 10
|
// thats much faster, about factor 10
|
||||||
} else {
|
} else {
|
||||||
// spawn the abiword process
|
|
||||||
let abiword;
|
let abiword;
|
||||||
let stdoutCallback = null;
|
let stdoutCallback = null;
|
||||||
const spawnAbiword = () => {
|
const spawnAbiword = () => {
|
||||||
abiword = spawn(settings.abiword, ['--plugin', 'AbiCommand']);
|
abiword = spawn(settings.abiword, ['--plugin', 'AbiCommand']);
|
||||||
let stdoutBuffer = '';
|
let stdoutBuffer = '';
|
||||||
let firstPrompt = true;
|
let firstPrompt = true;
|
||||||
|
abiword.stderr.on('data', (data) => { stdoutBuffer += data.toString(); });
|
||||||
// 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.on('exit', (code) => {
|
abiword.on('exit', (code) => {
|
||||||
spawnAbiword();
|
spawnAbiword();
|
||||||
stdoutCallback(`Abiword died with exit code ${code}`);
|
stdoutCallback(`Abiword died with exit code ${code}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// delegate the processing of stdout to a other function
|
|
||||||
abiword.stdout.on('data', (data) => {
|
abiword.stdout.on('data', (data) => {
|
||||||
// add data to buffer
|
|
||||||
stdoutBuffer += data.toString();
|
stdoutBuffer += data.toString();
|
||||||
|
|
||||||
// we're searching for the prompt, cause this means everything we need is in the buffer
|
// we're searching for the prompt, cause this means everything we need is in the buffer
|
||||||
if (stdoutBuffer.search('AbiWord:>') !== -1) {
|
if (stdoutBuffer.search('AbiWord:>') !== -1) {
|
||||||
// filter the feedback message
|
|
||||||
const err = stdoutBuffer.search('OK') !== -1 ? null : stdoutBuffer;
|
const err = stdoutBuffer.search('OK') !== -1 ? null : stdoutBuffer;
|
||||||
|
|
||||||
// reset the buffer
|
|
||||||
stdoutBuffer = '';
|
stdoutBuffer = '';
|
||||||
|
|
||||||
// call the callback with the error message
|
|
||||||
// skip the first prompt
|
|
||||||
if (stdoutCallback != null && !firstPrompt) {
|
if (stdoutCallback != null && !firstPrompt) {
|
||||||
stdoutCallback(err);
|
stdoutCallback(err);
|
||||||
stdoutCallback = null;
|
stdoutCallback = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
firstPrompt = false;
|
firstPrompt = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -114,7 +82,6 @@ if (os.type().indexOf('Windows') > -1) {
|
||||||
|
|
||||||
doConvertTask = (task, callback) => {
|
doConvertTask = (task, callback) => {
|
||||||
abiword.stdin.write(`convert ${task.srcFile} ${task.destFile} ${task.type}\n`);
|
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) => {
|
stdoutCallback = (err) => {
|
||||||
callback();
|
callback();
|
||||||
console.log('queue continue');
|
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);
|
const queue = async.queue(doConvertTask, 1);
|
||||||
exports.convertFile = (srcFile, destFile, type, callback) => {
|
exports.convertFile = (srcFile, destFile, type, callback) => {
|
||||||
queue.push({srcFile, destFile, type, callback});
|
queue.push({srcFile, destFile, type, callback});
|
||||||
|
|
|
@ -31,10 +31,6 @@ const doConvertTask = (task, callback) => {
|
||||||
const tmpDir = os.tmpdir();
|
const tmpDir = os.tmpdir();
|
||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
/*
|
|
||||||
* use LibreOffice to convert task.srcFile to another format, given in
|
|
||||||
* task.type
|
|
||||||
*/
|
|
||||||
(callback) => {
|
(callback) => {
|
||||||
libreOfficeLogger.debug(
|
libreOfficeLogger.debug(
|
||||||
`Converting ${task.srcFile} to format ${task.type}. The result will be put in ${tmpDir}`
|
`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.stdin.pause(); // required to kill hanging threads
|
||||||
soffice.kill();
|
soffice.kill();
|
||||||
}, 120000);
|
}, 120000);
|
||||||
|
|
||||||
let stdoutBuffer = '';
|
let stdoutBuffer = '';
|
||||||
|
soffice.stdout.on('data', (data) => { stdoutBuffer += data.toString(); });
|
||||||
// Delegate the processing of stdout to another function
|
soffice.stderr.on('data', (data) => { stdoutBuffer += data.toString(); });
|
||||||
soffice.stdout.on('data', (data) => {
|
|
||||||
stdoutBuffer += data.toString();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Append error messages to the buffer
|
|
||||||
soffice.stderr.on('data', (data) => {
|
|
||||||
stdoutBuffer += data.toString();
|
|
||||||
});
|
|
||||||
|
|
||||||
soffice.on('exit', (code) => {
|
soffice.on('exit', (code) => {
|
||||||
clearTimeout(hangTimeout);
|
clearTimeout(hangTimeout);
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
// Throw an exception if libreoffice failed
|
|
||||||
return callback(`LibreOffice died with exit code ${code} and message: ${stdoutBuffer}`);
|
return callback(`LibreOffice died with exit code ${code} and message: ${stdoutBuffer}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if LibreOffice exited succesfully, go on with processing
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Move the converted file to the correct place
|
|
||||||
(callback) => {
|
(callback) => {
|
||||||
const filename = path.basename(task.srcFile);
|
const filename = path.basename(task.srcFile);
|
||||||
const sourceFile = `${filename.substr(0, filename.lastIndexOf('.'))}.${task.fileExtension}`;
|
const sourceFile = `${filename.substr(0, filename.lastIndexOf('.'))}.${task.fileExtension}`;
|
||||||
|
@ -91,10 +73,7 @@ const doConvertTask = (task, callback) => {
|
||||||
fs.rename(sourcePath, task.destFile, callback);
|
fs.rename(sourcePath, task.destFile, callback);
|
||||||
},
|
},
|
||||||
], (err) => {
|
], (err) => {
|
||||||
// Invoke the callback for the local queue
|
|
||||||
callback();
|
callback();
|
||||||
|
|
||||||
// Invoke the callback for the task
|
|
||||||
task.callback(err);
|
task.callback(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue