mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
Use abiword --to parameter instead of abicommand for document conversions.
This commit is contained in:
parent
5b5230b28c
commit
e8d84b6058
3 changed files with 63 additions and 62 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue