Use abiword --to parameter instead of abicommand for document conversions.

This commit is contained in:
Randy 2011-08-03 15:57:11 -07:00
parent 5b5230b28c
commit e8d84b6058
3 changed files with 63 additions and 62 deletions

View file

@ -23,11 +23,20 @@ var padManager = require("../db/PadManager");
var async = require("async");
var fs = require("fs");
var settings = require('../utils/Settings');
var os = require('os');
//load abiword only if its enabled
if(settings.abiword != null)
var abiword = require("../utils/Abiword");
var tempDirectory = "/tmp";
//tempDirectory changes if the operating system is windows
if(os.type().indexOf("Windows") > -1)
{
tempDirectory = "c:\\Temp";
}
/**
* do a requested export
*/
@ -52,7 +61,7 @@ exports.doExport = function(req, res, padId, type)
var html;
var randNum;
var srcFile, destFile;
async.series([
//render the html document
function(callback)
@ -76,7 +85,7 @@ exports.doExport = function(req, res, padId, type)
else
{
randNum = Math.floor(Math.random()*new Date().getTime());
srcFile = "/tmp/eplite_export_" + randNum + ".html";
srcFile = tempDirectory + "/eplite_export_" + randNum + ".html";
fs.writeFile(srcFile, html, callback);
}
},
@ -86,7 +95,7 @@ exports.doExport = function(req, res, padId, type)
//ensure html can be collected by the garbage collector
html = null;
destFile = "/tmp/eplite_export_" + randNum + "." + type;
destFile = tempDirectory + "/eplite_export_" + randNum + "." + type;
abiword.convertFile(srcFile, destFile, type, callback);
},
//send the file
@ -104,7 +113,11 @@ exports.doExport = function(req, res, padId, type)
},
function(callback)
{
fs.unlink(destFile, callback);
//100ms delay to accomidate for slow windows fs
setTimeout(function()
{
fs.unlink(destFile, callback);
}, 100);
}
], callback);
}

View file

@ -24,10 +24,19 @@ var async = require("async");
var fs = require("fs");
var settings = require('../utils/Settings');
var formidable = require('formidable');
var os = require("os");
//load abiword only if its enabled
if(settings.abiword != null)
var abiword = require("../utils/Abiword");
var tempDirectory = "/tmp/";
//tempDirectory changes if the operating system is windows
if(os.type().indexOf("Windows") > -1)
{
tempDirectory = "c:\\Temp\\";
}
/**
* do a requested import
@ -48,6 +57,7 @@ exports.doImport = function(req, res, padId)
{
var form = new formidable.IncomingForm();
form.keepExtensions = true;
form.uploadDir = tempDirectory;
form.parse(req, function(err, fields, files)
{
@ -94,7 +104,7 @@ exports.doImport = function(req, res, padId)
function(callback)
{
var randNum = Math.floor(Math.random()*new Date().getTime());
destFile = "/tmp/eplite_import_" + randNum + ".txt";
destFile = tempDirectory + "eplite_import_" + randNum + ".txt";
abiword.convertFile(srcFile, destFile, "txt", callback);
},
@ -114,7 +124,13 @@ exports.doImport = function(req, res, padId)
fs.readFile(destFile, "utf8", function(err, _text)
{
text = _text;
callback(err);
//node on windows has a delay on releasing of the file lock.
//We add a 100ms delay to work around this
setTimeout(function()
{
callback(err);
}, 100);
});
},