mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-31 19:02:59 +01:00
lint: src/node/utils/Abiword.js
This commit is contained in:
parent
666dd7abd1
commit
7afc809073
1 changed files with 17 additions and 15 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
'use strict';
|
||||||
/**
|
/**
|
||||||
* Controls the communication with the Abiword application
|
* Controls the communication with the Abiword application
|
||||||
*/
|
*/
|
||||||
|
@ -25,11 +26,12 @@ const os = require('os');
|
||||||
|
|
||||||
let doConvertTask;
|
let doConvertTask;
|
||||||
|
|
||||||
// on windows we have to spawn a process for each convertion, cause the plugin abicommand doesn't exist on this platform
|
// on windows we have to spawn a process for each convertion,
|
||||||
|
// cause the plugin abicommand doesn't exist on this platform
|
||||||
if (os.type().indexOf('Windows') > -1) {
|
if (os.type().indexOf('Windows') > -1) {
|
||||||
let stdoutBuffer = '';
|
let stdoutBuffer = '';
|
||||||
|
|
||||||
doConvertTask = function (task, callback) {
|
doConvertTask = (task, callback) => {
|
||||||
// span an abiword process to perform the conversion
|
// 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]);
|
||||||
|
|
||||||
|
@ -46,11 +48,11 @@ if (os.type().indexOf('Windows') > -1) {
|
||||||
|
|
||||||
// throw exceptions if abiword is dieing
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,17 +60,17 @@ if (os.type().indexOf('Windows') > -1) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.convertFile = function (srcFile, destFile, type, callback) {
|
exports.convertFile = (srcFile, destFile, type, callback) => {
|
||||||
doConvertTask({srcFile, destFile, type}, callback);
|
doConvertTask({srcFile, destFile, type}, callback);
|
||||||
};
|
};
|
||||||
}
|
// on unix operating systems, we can start abiword with abicommand and
|
||||||
// on unix operating systems, we can start abiword with abicommand and 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
|
// spawn the abiword process
|
||||||
let abiword;
|
let abiword;
|
||||||
let stdoutCallback = null;
|
let stdoutCallback = null;
|
||||||
var spawnAbiword = function () {
|
const spawnAbiword = () => {
|
||||||
abiword = spawn(settings.abiword, ['--plugin', 'AbiCommand']);
|
abiword = spawn(settings.abiword, ['--plugin', 'AbiCommand']);
|
||||||
let stdoutBuffer = '';
|
let stdoutBuffer = '';
|
||||||
let firstPrompt = true;
|
let firstPrompt = true;
|
||||||
|
@ -90,9 +92,9 @@ else {
|
||||||
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
|
// filter the feedback message
|
||||||
const err = stdoutBuffer.search('OK') != -1 ? null : stdoutBuffer;
|
const err = stdoutBuffer.search('OK') !== -1 ? null : stdoutBuffer;
|
||||||
|
|
||||||
// reset the buffer
|
// reset the buffer
|
||||||
stdoutBuffer = '';
|
stdoutBuffer = '';
|
||||||
|
@ -110,10 +112,10 @@ else {
|
||||||
};
|
};
|
||||||
spawnAbiword();
|
spawnAbiword();
|
||||||
|
|
||||||
doConvertTask = function (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
|
// create a callback that calls the task callback and the caller callback
|
||||||
stdoutCallback = function (err) {
|
stdoutCallback = (err) => {
|
||||||
callback();
|
callback();
|
||||||
console.log('queue continue');
|
console.log('queue continue');
|
||||||
try {
|
try {
|
||||||
|
@ -126,7 +128,7 @@ else {
|
||||||
|
|
||||||
// Queue with the converts we have to do
|
// Queue with the converts we have to do
|
||||||
const queue = async.queue(doConvertTask, 1);
|
const queue = async.queue(doConvertTask, 1);
|
||||||
exports.convertFile = function (srcFile, destFile, type, callback) {
|
exports.convertFile = (srcFile, destFile, type, callback) => {
|
||||||
queue.push({srcFile, destFile, type, callback});
|
queue.push({srcFile, destFile, type, callback});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue