mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
utils/Abiword: use jshint
This commit is contained in:
parent
11568b1278
commit
2a05f2d3df
1 changed files with 21 additions and 21 deletions
|
@ -17,7 +17,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
var util = require('util');
|
||||
var spawn = require('child_process').spawn;
|
||||
var async = require("async");
|
||||
|
@ -35,7 +35,7 @@ if(os.type().indexOf("Windows") > -1)
|
|||
{
|
||||
//span an abiword process to perform the conversion
|
||||
var abiword = spawn(settings.abiword, ["--to=" + task.destFile, task.srcFile]);
|
||||
|
||||
|
||||
//delegate the processing of stdout to another function
|
||||
abiword.stdout.on('data', function (data)
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ if(os.type().indexOf("Windows") > -1)
|
|||
});
|
||||
|
||||
//append error messages to the buffer
|
||||
abiword.stderr.on('data', function (data)
|
||||
abiword.stderr.on('data', function (data)
|
||||
{
|
||||
stdoutBuffer += data.toString();
|
||||
});
|
||||
|
@ -52,19 +52,19 @@ if(os.type().indexOf("Windows") > -1)
|
|||
//throw exceptions if abiword is dieing
|
||||
abiword.on('exit', function (code)
|
||||
{
|
||||
if(code != 0) {
|
||||
if(code !== 0) {
|
||||
throw "Abiword died with exit code " + code;
|
||||
}
|
||||
|
||||
if(stdoutBuffer != "")
|
||||
if(stdoutBuffer !== "")
|
||||
{
|
||||
console.log(stdoutBuffer);
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
exports.convertFile = function(srcFile, destFile, type, callback)
|
||||
{
|
||||
doConvertTask({"srcFile": srcFile, "destFile": destFile, "type": type}, callback);
|
||||
|
@ -78,13 +78,13 @@ else
|
|||
var abiword = spawn(settings.abiword, ["--plugin", "AbiCommand"]);
|
||||
|
||||
//append error messages to the buffer
|
||||
abiword.stderr.on('data', function (data)
|
||||
abiword.stderr.on('data', function (data)
|
||||
{
|
||||
stdoutBuffer += data.toString();
|
||||
});
|
||||
|
||||
//throw exceptions if abiword is dieing
|
||||
abiword.on('exit', function (code)
|
||||
abiword.on('exit', function (code)
|
||||
{
|
||||
throw "Abiword died with exit code " + code;
|
||||
});
|
||||
|
@ -96,49 +96,49 @@ else
|
|||
var stdoutBuffer = "";
|
||||
var firstPrompt = true;
|
||||
|
||||
function onAbiwordStdout(data)
|
||||
var onAbiwordStdout = function onAbiwordStdout(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
|
||||
var 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)
|
||||
if(stdoutCallback && !firstPrompt)
|
||||
{
|
||||
stdoutCallback(err);
|
||||
stdoutCallback = null;
|
||||
}
|
||||
|
||||
|
||||
firstPrompt = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
doConvertTask = function(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)
|
||||
{
|
||||
callback();
|
||||
task.callback(err);
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//Queue with the converts we have to do
|
||||
var queue = async.queue(doConvertTask, 1);
|
||||
|
||||
|
||||
exports.convertFile = function(srcFile, destFile, type, callback)
|
||||
{
|
||||
{
|
||||
queue.push({"srcFile": srcFile, "destFile": destFile, "type": type, "callback": callback});
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue