mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +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
|
||||
*/
|
||||
|
@ -25,11 +26,12 @@ const os = require('os');
|
|||
|
||||
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) {
|
||||
let stdoutBuffer = '';
|
||||
|
||||
doConvertTask = function (task, callback) {
|
||||
doConvertTask = (task, callback) => {
|
||||
// span an abiword process to perform the conversion
|
||||
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
|
||||
abiword.on('exit', (code) => {
|
||||
if (code != 0) {
|
||||
if (code !== 0) {
|
||||
return callback(`Abiword died with exit code ${code}`);
|
||||
}
|
||||
|
||||
if (stdoutBuffer != '') {
|
||||
if (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);
|
||||
};
|
||||
}
|
||||
// on unix operating systems, we can start abiword with abicommand and communicate with it via stdin/stdout
|
||||
// thats much faster, about factor 10
|
||||
else {
|
||||
// on unix operating systems, we can start abiword with abicommand and
|
||||
// communicate with it via stdin/stdout
|
||||
// thats much faster, about factor 10
|
||||
} else {
|
||||
// spawn the abiword process
|
||||
let abiword;
|
||||
let stdoutCallback = null;
|
||||
var spawnAbiword = function () {
|
||||
const spawnAbiword = () => {
|
||||
abiword = spawn(settings.abiword, ['--plugin', 'AbiCommand']);
|
||||
let stdoutBuffer = '';
|
||||
let firstPrompt = true;
|
||||
|
@ -90,9 +92,9 @@ else {
|
|||
stdoutBuffer += data.toString();
|
||||
|
||||
// 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 = '';
|
||||
|
@ -110,10 +112,10 @@ else {
|
|||
};
|
||||
spawnAbiword();
|
||||
|
||||
doConvertTask = function (task, callback) {
|
||||
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 = function (err) {
|
||||
stdoutCallback = (err) => {
|
||||
callback();
|
||||
console.log('queue continue');
|
||||
try {
|
||||
|
@ -126,7 +128,7 @@ else {
|
|||
|
||||
// Queue with the converts we have to do
|
||||
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});
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue