semi working requires browser refresh

This commit is contained in:
John McLear 2014-12-29 20:57:58 +01:00
parent 565097efb4
commit 3773b6346b
7 changed files with 91 additions and 42 deletions

View file

@ -44,6 +44,7 @@
"pad.importExport.import": "Upload any text file or document", "pad.importExport.import": "Upload any text file or document",
"pad.importExport.importSuccessful": "Successful!", "pad.importExport.importSuccessful": "Successful!",
"pad.importExport.export": "Export current pad as:", "pad.importExport.export": "Export current pad as:",
"pad.importExport.exportetherpad": "Etherpad",
"pad.importExport.exporthtml": "HTML", "pad.importExport.exporthtml": "HTML",
"pad.importExport.exportplain": "Plain text", "pad.importExport.exportplain": "Plain text",
"pad.importExport.exportword": "Microsoft Word", "pad.importExport.exportword": "Microsoft Word",

View file

@ -21,6 +21,7 @@
var ERR = require("async-stacktrace"); var ERR = require("async-stacktrace");
var exporthtml = require("../utils/ExportHtml"); var exporthtml = require("../utils/ExportHtml");
var exporttxt = require("../utils/ExportTxt"); var exporttxt = require("../utils/ExportTxt");
var exportEtherpad = require("../utils/ExportEtherpad");
var async = require("async"); var async = require("async");
var fs = require("fs"); var fs = require("fs");
var settings = require('../utils/Settings'); var settings = require('../utils/Settings');
@ -52,14 +53,21 @@ exports.doExport = function(req, res, padId, type)
// if fileName is set then set it to the padId, note that fileName is returned as an array. // if fileName is set then set it to the padId, note that fileName is returned as an array.
if(hookFileName.length) fileName = hookFileName; if(hookFileName.length) fileName = hookFileName;
//tell the browser that this is a downloadable file //tell the browser that this is a downloadable file
res.attachment(fileName + "." + type); res.attachment(fileName + "." + type);
//if this is a plain text export, we can do this directly //if this is a plain text export, we can do this directly
// We have to over engineer this because tabs are stored as attributes and not plain text // We have to over engineer this because tabs are stored as attributes and not plain text
if(type == "etherpad"){
if(type == "txt") console.log("Exporting Etherpad");
exportEtherpad.getPadRaw(padId, function(err, pad){
if(!err){
res.send(pad);
// return;
}
});
}
else if(type == "txt")
{ {
var txt; var txt;
var randNum; var randNum;

View file

@ -29,6 +29,7 @@ var ERR = require("async-stacktrace")
, formidable = require('formidable') , formidable = require('formidable')
, os = require("os") , os = require("os")
, importHtml = require("../utils/ImportHtml") , importHtml = require("../utils/ImportHtml")
, importEtherpad = require("../utils/ImportEtherpad")
, log4js = require("log4js") , log4js = require("log4js")
, hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js"); , hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js");
@ -53,7 +54,8 @@ exports.doImport = function(req, res, padId)
var srcFile, destFile var srcFile, destFile
, pad , pad
, text , text
, importHandledByPlugin; , importHandledByPlugin
, directDatabaseAccess;
var randNum = Math.floor(Math.random()*0xFFFFFFFF); var randNum = Math.floor(Math.random()*0xFFFFFFFF);
@ -83,7 +85,7 @@ exports.doImport = function(req, res, padId)
//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 = path.extname(srcFile).toLowerCase() var fileEnding = path.extname(srcFile).toLowerCase()
, knownFileEndings = [".txt", ".doc", ".docx", ".pdf", ".odt", ".html", ".htm"] , knownFileEndings = [".txt", ".doc", ".docx", ".pdf", ".odt", ".html", ".htm", ".etherpad"]
, fileEndingKnown = (knownFileEndings.indexOf(fileEnding) > -1); , fileEndingKnown = (knownFileEndings.indexOf(fileEnding) > -1);
//if the file ending is known, continue as normal //if the file ending is known, continue as normal
@ -116,9 +118,22 @@ exports.doImport = function(req, res, padId)
} }
}); });
}, },
function(callback) {
var fileEnding = path.extname(srcFile).toLowerCase()
var fileIsEtherpad = (fileEnding === ".etherpad");
if(fileIsEtherpad){
fs.readFile(srcFile, "utf8", function(err, _text){
directDatabaseAccess = true;
importEtherpad.setPadRaw(padId, _text, function(err){
console.log("returning");
return callback(null);
});
});
}
},
//convert file to html //convert file to html
function(callback) { function(callback) {
if(!importHandledByPlugin){ if(!importHandledByPlugin || !directDatabaseAccess){
var fileEnding = path.extname(srcFile).toLowerCase(); var fileEnding = path.extname(srcFile).toLowerCase();
var fileIsHTML = (fileEnding === ".html" || fileEnding === ".htm"); var fileIsHTML = (fileEnding === ".html" || fileEnding === ".htm");
if (abiword && !fileIsHTML) { if (abiword && !fileIsHTML) {
@ -141,7 +156,7 @@ exports.doImport = function(req, res, padId)
}, },
function(callback) { function(callback) {
if (!abiword) { if (!abiword || !directDatabaseAccess) {
// Read the file with no encoding for raw buffer access. // Read the file with no encoding for raw buffer access.
fs.readFile(destFile, function(err, buf) { fs.readFile(destFile, function(err, buf) {
if (err) throw err; if (err) throw err;
@ -175,6 +190,7 @@ exports.doImport = function(req, res, padId)
//read the text //read the text
function(callback) { function(callback) {
if(!directDatabaseAccess){
fs.readFile(destFile, "utf8", function(err, _text){ fs.readFile(destFile, "utf8", function(err, _text){
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
text = _text; text = _text;
@ -190,10 +206,14 @@ exports.doImport = function(req, res, padId)
callback(); callback();
} }
}); });
}else{
callback();
}
}, },
//change text of the pad and broadcast the changeset //change text of the pad and broadcast the changeset
function(callback) { function(callback) {
if(!directDatabaseAccess){
var fileEnding = path.extname(srcFile).toLowerCase(); var fileEnding = path.extname(srcFile).toLowerCase();
if (abiword || fileEnding == ".htm" || fileEnding == ".html") { if (abiword || fileEnding == ".htm" || fileEnding == ".html") {
try{ try{
@ -204,11 +224,23 @@ exports.doImport = function(req, res, padId)
} else { } else {
pad.setText(text); pad.setText(text);
} }
padMessageHandler.updatePadClients(pad, callback); }
// Load the Pad into memory then brodcast updates to all clients
padManager.unloadPad(padId);
padManager.getPad(padId, function(err, _pad){
var pad = _pad;
padManager.unloadPad(padId);
padMessageHandler.updatePadClients(pad, function(){
callback();
});
});
}, },
//clean up temporary files //clean up temporary files
function(callback) { function(callback) {
if(!directDatabaseAccess){
//for node < 0.7 compatible //for node < 0.7 compatible
var fileExists = fs.exists || path.exists; var fileExists = fs.exists || path.exists;
async.parallel([ async.parallel([
@ -219,6 +251,9 @@ exports.doImport = function(req, res, padId)
fileExists (destFile, function(exist) { (exist)? fs.unlink(destFile, callback): callback(); }); fileExists (destFile, function(exist) { (exist)? fs.unlink(destFile, callback): callback(); });
} }
], callback); ], callback);
}else{
callback();
}
} }
], function(err) { ], function(err) {

View file

@ -5,7 +5,7 @@ var importHandler = require('../../handler/ImportHandler');
exports.expressCreateServer = function (hook_name, args, cb) { exports.expressCreateServer = function (hook_name, args, cb) {
args.app.get('/p/:pad/:rev?/export/:type', function(req, res, next) { args.app.get('/p/:pad/:rev?/export/:type', function(req, res, next) {
var types = ["pdf", "doc", "txt", "html", "odt"]; var types = ["pdf", "doc", "txt", "html", "odt", "etherpad"];
//send a 404 if we don't support this filetype //send a 404 if we don't support this filetype
if (types.indexOf(req.params.type) == -1) { if (types.indexOf(req.params.type) == -1) {
next(); next();

View file

@ -689,6 +689,9 @@ table#otheruserstable {
#exportpdfa:before { #exportpdfa:before {
content: "\e803"; content: "\e803";
} }
#exportetherpada:before {
content: "\e806";
}
#exportopena:before { #exportopena:before {
content: "\e805"; content: "\e805";
} }

View file

@ -198,6 +198,7 @@ var padimpexp = (function()
// build the export links // build the export links
$("#exporthtmla").attr("href", pad_root_path + "/export/html"); $("#exporthtmla").attr("href", pad_root_path + "/export/html");
$("#exportetherpada").attr("href", pad_root_path + "/export/etherpad");
$("#exportplaina").attr("href", pad_root_path + "/export/txt"); $("#exportplaina").attr("href", pad_root_path + "/export/txt");
// activate action to import in the form // activate action to import in the form

View file

@ -203,6 +203,7 @@
<div class="column" id="exportColumn"> <div class="column" id="exportColumn">
<h2 data-l10n-id="pad.importExport.export"></h2> <h2 data-l10n-id="pad.importExport.export"></h2>
<% e.begin_block("exportColumn"); %> <% e.begin_block("exportColumn"); %>
<a id="exportetherpada" target="_blank" class="exportlink"><div class="exporttype" id="exportetherpad" data-l10n-id="pad.importExport.exportetherpad"></div></a>
<a id="exporthtmla" target="_blank" class="exportlink"><div class="exporttype" id="exporthtml" data-l10n-id="pad.importExport.exporthtml"></div></a> <a id="exporthtmla" target="_blank" class="exportlink"><div class="exporttype" id="exporthtml" data-l10n-id="pad.importExport.exporthtml"></div></a>
<a id="exportplaina" target="_blank" class="exportlink"><div class="exporttype" id="exportplain" data-l10n-id="pad.importExport.exportplain"></div></a> <a id="exportplaina" target="_blank" class="exportlink"><div class="exporttype" id="exportplain" data-l10n-id="pad.importExport.exportplain"></div></a>
<a id="exportworda" target="_blank" class="exportlink"><div class="exporttype" id="exportword" data-l10n-id="pad.importExport.exportword"></div></a> <a id="exportworda" target="_blank" class="exportlink"><div class="exporttype" id="exportword" data-l10n-id="pad.importExport.exportword"></div></a>