handler/ImportHandler: use jshint

This commit is contained in:
booo 2011-12-22 12:28:25 +01:00
parent da7098168e
commit 8e42192f2f

View file

@ -28,8 +28,10 @@ var formidable = require('formidable');
var os = require("os"); var os = require("os");
//load abiword only if its enabled //load abiword only if its enabled
if(settings.abiword != null) if(settings.abiword)
{
var abiword = require("../utils/Abiword"); var abiword = require("../utils/Abiword");
}
var tempDirectory = "/tmp/"; var tempDirectory = "/tmp/";
@ -38,20 +40,20 @@ if(os.type().indexOf("Windows") > -1)
{ {
tempDirectory = process.env.TEMP; tempDirectory = process.env.TEMP;
} }
/** /**
* do a requested import * do a requested import
*/ */
exports.doImport = function(req, res, padId) exports.doImport = function(req, res, padId)
{ {
//pipe to a file //pipe to a file
//convert file to text via abiword //convert file to text via abiword
//set text in the pad //set text in the pad
var srcFile, destFile; var srcFile, destFile;
var pad; var pad;
var text; var text;
async.series([ async.series([
//save the uploaded file to /tmp //save the uploaded file to /tmp
function(callback) function(callback)
@ -59,9 +61,9 @@ exports.doImport = function(req, res, padId)
var form = new formidable.IncomingForm(); var form = new formidable.IncomingForm();
form.keepExtensions = true; form.keepExtensions = true;
form.uploadDir = tempDirectory; form.uploadDir = tempDirectory;
form.parse(req, function(err, fields, files) form.parse(req, function(err, fields, files)
{ {
//the upload failed, stop at this point //the upload failed, stop at this point
if(err || files.file === undefined) if(err || files.file === undefined)
{ {
@ -69,7 +71,7 @@ exports.doImport = function(req, res, padId)
callback("uploadFailed"); callback("uploadFailed");
} }
//everything ok, continue //everything ok, continue
else else
{ {
//save the path of the uploaded file //save the path of the uploaded file
srcFile = files.file.path; srcFile = files.file.path;
@ -77,14 +79,14 @@ exports.doImport = function(req, res, padId)
} }
}); });
}, },
//ensure this is a file ending we know, else we change the file ending to .txt //ensure this is a file ending we know, else we change the file ending to .txt
//this allows us to accept source code files like .c or .java //this allows us to accept source code files like .c or .java
function(callback) function(callback)
{ {
var fileEnding = srcFile.split(".")[1].toLowerCase(); var fileEnding = srcFile.split(".")[1].toLowerCase();
var knownFileEndings = ["txt", "doc", "docx", "pdf", "odt", "html", "htm"]; var knownFileEndings = ["txt", "doc", "docx", "pdf", "odt", "html", "htm"];
//find out if this is a known file ending //find out if this is a known file ending
var fileEndingKnown = false; var fileEndingKnown = false;
for(var i in knownFileEndings) for(var i in knownFileEndings)
@ -94,7 +96,7 @@ exports.doImport = function(req, res, padId)
fileEndingKnown = true; fileEndingKnown = true;
} }
} }
//if the file ending is known, continue as normal //if the file ending is known, continue as normal
if(fileEndingKnown) if(fileEndingKnown)
{ {
@ -105,11 +107,11 @@ exports.doImport = function(req, res, padId)
{ {
var oldSrcFile = srcFile; var oldSrcFile = srcFile;
srcFile = srcFile.split(".")[0] + ".txt"; srcFile = srcFile.split(".")[0] + ".txt";
fs.rename(oldSrcFile, srcFile, callback); fs.rename(oldSrcFile, srcFile, callback);
} }
}, },
//convert file to text //convert file to text
function(callback) function(callback)
{ {
@ -117,7 +119,7 @@ exports.doImport = function(req, res, padId)
destFile = tempDirectory + "eplite_import_" + randNum + ".txt"; destFile = tempDirectory + "eplite_import_" + randNum + ".txt";
abiword.convertFile(srcFile, destFile, "txt", callback); abiword.convertFile(srcFile, destFile, "txt", callback);
}, },
//get the pad object //get the pad object
function(callback) function(callback)
{ {
@ -128,7 +130,7 @@ exports.doImport = function(req, res, padId)
callback(); callback();
}); });
}, },
//read the text //read the text
function(callback) function(callback)
{ {
@ -136,30 +138,30 @@ exports.doImport = function(req, res, padId)
{ {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
text = _text; text = _text;
//node on windows has a delay on releasing of the file lock. //node on windows has a delay on releasing of the file lock.
//We add a 100ms delay to work around this //We add a 100ms delay to work around this
if(os.type().indexOf("Windows") > -1) if(os.type().indexOf("Windows") > -1)
{ {
setTimeout(function() setTimeout(function()
{ {
callback(); callback();
}, 100); }, 100);
} }
else else
{ {
callback(); callback();
} }
}); });
}, },
//change text of the pad and broadcast the changeset //change text of the pad and broadcast the changeset
function(callback) function(callback)
{ {
pad.setText(text); pad.setText(text);
padMessageHandler.updatePadClients(pad, callback); padMessageHandler.updatePadClients(pad, callback);
}, },
//clean up temporary files //clean up temporary files
function(callback) function(callback)
{ {
@ -184,8 +186,8 @@ exports.doImport = function(req, res, padId)
} }
ERR(err); ERR(err);
//close the connection //close the connection
res.send("ok"); res.send("ok");
}); });
} };