From 3773b6346b919995c311356b7cd582517b6f09ef Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 29 Dec 2014 20:57:58 +0100 Subject: [PATCH 01/13] semi working requires browser refresh --- src/locales/en.json | 1 + src/node/handler/ExportHandler.js | 14 +++- src/node/handler/ImportHandler.js | 111 ++++++++++++++++--------- src/node/hooks/express/importexport.js | 2 +- src/static/css/pad.css | 3 + src/static/js/pad_impexp.js | 1 + src/templates/pad.html | 1 + 7 files changed, 91 insertions(+), 42 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index 9a5fe45f1..5e074e387 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -44,6 +44,7 @@ "pad.importExport.import": "Upload any text file or document", "pad.importExport.importSuccessful": "Successful!", "pad.importExport.export": "Export current pad as:", + "pad.importExport.exportetherpad": "Etherpad", "pad.importExport.exporthtml": "HTML", "pad.importExport.exportplain": "Plain text", "pad.importExport.exportword": "Microsoft Word", diff --git a/src/node/handler/ExportHandler.js b/src/node/handler/ExportHandler.js index f12d66c24..23d1cb10c 100644 --- a/src/node/handler/ExportHandler.js +++ b/src/node/handler/ExportHandler.js @@ -21,6 +21,7 @@ var ERR = require("async-stacktrace"); var exporthtml = require("../utils/ExportHtml"); var exporttxt = require("../utils/ExportTxt"); +var exportEtherpad = require("../utils/ExportEtherpad"); var async = require("async"); var fs = require("fs"); 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(hookFileName.length) fileName = hookFileName; - //tell the browser that this is a downloadable file res.attachment(fileName + "." + type); //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 - - if(type == "txt") + if(type == "etherpad"){ + console.log("Exporting Etherpad"); + exportEtherpad.getPadRaw(padId, function(err, pad){ + if(!err){ + res.send(pad); + // return; + } + }); + } + else if(type == "txt") { var txt; var randNum; diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index 55915d760..7ea10988c 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -29,6 +29,7 @@ var ERR = require("async-stacktrace") , formidable = require('formidable') , os = require("os") , importHtml = require("../utils/ImportHtml") + , importEtherpad = require("../utils/ImportEtherpad") , log4js = require("log4js") , hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js"); @@ -53,7 +54,8 @@ exports.doImport = function(req, res, padId) var srcFile, destFile , pad , text - , importHandledByPlugin; + , importHandledByPlugin + , directDatabaseAccess; 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 function(callback) { 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); //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 function(callback) { - if(!importHandledByPlugin){ + if(!importHandledByPlugin || !directDatabaseAccess){ var fileEnding = path.extname(srcFile).toLowerCase(); var fileIsHTML = (fileEnding === ".html" || fileEnding === ".htm"); if (abiword && !fileIsHTML) { @@ -141,7 +156,7 @@ exports.doImport = function(req, res, padId) }, function(callback) { - if (!abiword) { + if (!abiword || !directDatabaseAccess) { // Read the file with no encoding for raw buffer access. fs.readFile(destFile, function(err, buf) { if (err) throw err; @@ -175,50 +190,70 @@ exports.doImport = function(req, res, padId) //read the text function(callback) { - fs.readFile(destFile, "utf8", function(err, _text){ - if(ERR(err, callback)) return; - text = _text; - // Title needs to be stripped out else it appends it to the pad.. - text = text.replace("", "<!-- <title>"); - text = text.replace("","-->"); - - //node on windows has a delay on releasing of the file lock. - //We add a 100ms delay to work around this - if(os.type().indexOf("Windows") > -1){ - setTimeout(function() {callback();}, 100); - } else { - callback(); - } - }); + if(!directDatabaseAccess){ + fs.readFile(destFile, "utf8", function(err, _text){ + if(ERR(err, callback)) return; + text = _text; + // Title needs to be stripped out else it appends it to the pad.. + text = text.replace("", "<!-- <title>"); + text = text.replace("","-->"); + + //node on windows has a delay on releasing of the file lock. + //We add a 100ms delay to work around this + if(os.type().indexOf("Windows") > -1){ + setTimeout(function() {callback();}, 100); + } else { + callback(); + } + }); + }else{ + callback(); + } }, //change text of the pad and broadcast the changeset function(callback) { - var fileEnding = path.extname(srcFile).toLowerCase(); - if (abiword || fileEnding == ".htm" || fileEnding == ".html") { - try{ - importHtml.setPadHTML(pad, text); - }catch(e){ - apiLogger.warn("Error importing, possibly caused by malformed HTML"); + if(!directDatabaseAccess){ + var fileEnding = path.extname(srcFile).toLowerCase(); + if (abiword || fileEnding == ".htm" || fileEnding == ".html") { + try{ + importHtml.setPadHTML(pad, text); + }catch(e){ + apiLogger.warn("Error importing, possibly caused by malformed HTML"); + } + } else { + pad.setText(text); } - } else { - 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 function(callback) { - //for node < 0.7 compatible - var fileExists = fs.exists || path.exists; - async.parallel([ - function(callback){ - fileExists (srcFile, function(exist) { (exist)? fs.unlink(srcFile, callback): callback(); }); - }, - function(callback){ - fileExists (destFile, function(exist) { (exist)? fs.unlink(destFile, callback): callback(); }); - } - ], callback); + if(!directDatabaseAccess){ + //for node < 0.7 compatible + var fileExists = fs.exists || path.exists; + async.parallel([ + function(callback){ + fileExists (srcFile, function(exist) { (exist)? fs.unlink(srcFile, callback): callback(); }); + }, + function(callback){ + fileExists (destFile, function(exist) { (exist)? fs.unlink(destFile, callback): callback(); }); + } + ], callback); + }else{ + callback(); + } } ], function(err) { diff --git a/src/node/hooks/express/importexport.js b/src/node/hooks/express/importexport.js index 378e88656..f3f051636 100644 --- a/src/node/hooks/express/importexport.js +++ b/src/node/hooks/express/importexport.js @@ -5,7 +5,7 @@ var importHandler = require('../../handler/ImportHandler'); exports.expressCreateServer = function (hook_name, args, cb) { 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 if (types.indexOf(req.params.type) == -1) { next(); diff --git a/src/static/css/pad.css b/src/static/css/pad.css index c1035e8d5..0ff613fc7 100644 --- a/src/static/css/pad.css +++ b/src/static/css/pad.css @@ -689,6 +689,9 @@ table#otheruserstable { #exportpdfa:before { content: "\e803"; } +#exportetherpada:before { + content: "\e806"; +} #exportopena:before { content: "\e805"; } diff --git a/src/static/js/pad_impexp.js b/src/static/js/pad_impexp.js index 20cae2a09..2548b8bb8 100644 --- a/src/static/js/pad_impexp.js +++ b/src/static/js/pad_impexp.js @@ -198,6 +198,7 @@ var padimpexp = (function() // build the export links $("#exporthtmla").attr("href", pad_root_path + "/export/html"); + $("#exportetherpada").attr("href", pad_root_path + "/export/etherpad"); $("#exportplaina").attr("href", pad_root_path + "/export/txt"); // activate action to import in the form diff --git a/src/templates/pad.html b/src/templates/pad.html index 2dd66aa90..fa28b5425 100644 --- a/src/templates/pad.html +++ b/src/templates/pad.html @@ -203,6 +203,7 @@

<% e.begin_block("exportColumn"); %> +
From 1081156f134a5c71bc38ab4a3687a900cb35ba14 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 29 Dec 2014 21:13:49 +0100 Subject: [PATCH 02/13] whoopsi, required files --- src/node/utils/ExportEtherpad.js | 44 ++++++++++++++++++++++++++++++++ src/node/utils/ImportEtherpad.js | 39 ++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/node/utils/ExportEtherpad.js create mode 100644 src/node/utils/ImportEtherpad.js diff --git a/src/node/utils/ExportEtherpad.js b/src/node/utils/ExportEtherpad.js new file mode 100644 index 000000000..99d86140f --- /dev/null +++ b/src/node/utils/ExportEtherpad.js @@ -0,0 +1,44 @@ +/** + * Copyright 2014 John McLear. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +var async = require("async"); +var db = require("../db/DB").db; +var ERR = require("async-stacktrace"); + +exports.getPadRaw = function(padId, callback){ + async.waterfall([ + function(cb){ + db.findKeys("pad:"+padId+"*", null, function(err,records){ + if(!err){ + cb(err, records); + } + }) + }, + function(records, cb){ + var data = {}; + async.forEachSeries(Object.keys(records), function(key, r){ + db.get(records[key], function(err, entry){ + data[records[key]] = entry; + r(null); // callback; + }); + }, function(err){ + cb(err, data); + }) + }], function(err, data){ + callback(null, data); + }); +} diff --git a/src/node/utils/ImportEtherpad.js b/src/node/utils/ImportEtherpad.js new file mode 100644 index 000000000..b18708ffa --- /dev/null +++ b/src/node/utils/ImportEtherpad.js @@ -0,0 +1,39 @@ +/** + * Copyright Yaco Sistemas S.L. 2011. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var log4js = require('log4js'); +var async = require("async"); +var db = require("../db/DB").db; + +exports.setPadRaw = function(padId, records, callback){ + records = JSON.parse(records); + + async.eachSeries(Object.keys(records), function(key, cb){ + var value = records[key] + + // rewrite padId + var oldPadId = key.split(":"); + oldPadId[1] = padId; + var newKey = oldPadId.join(":"); // create the new key + + // Write the value to the server + db.set(newKey, value); + + cb(); + }, function(){ + callback(null, true); + }); +} From ab5e7381a29ae442ede7dde760f7d69a9228fe80 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 29 Dec 2014 21:35:10 +0100 Subject: [PATCH 03/13] working for all files --- src/node/handler/ImportHandler.js | 44 +++++++++++++++++-------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index 7ea10988c..813a8d194 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -125,10 +125,11 @@ exports.doImport = function(req, res, padId) fs.readFile(srcFile, "utf8", function(err, _text){ directDatabaseAccess = true; importEtherpad.setPadRaw(padId, _text, function(err){ - console.log("returning"); - return callback(null); + callback(); }); }); + }else{ + callback(); } }, //convert file to html @@ -156,24 +157,28 @@ exports.doImport = function(req, res, padId) }, function(callback) { - if (!abiword || !directDatabaseAccess) { - // Read the file with no encoding for raw buffer access. - fs.readFile(destFile, function(err, buf) { - if (err) throw err; - var isAscii = true; - // Check if there are only ascii chars in the uploaded file - for (var i=0, len=buf.length; i 240) { - isAscii=false; - break; + if (!abiword){ + if(!directDatabaseAccess) { + // Read the file with no encoding for raw buffer access. + fs.readFile(destFile, function(err, buf) { + if (err) throw err; + var isAscii = true; + // Check if there are only ascii chars in the uploaded file + for (var i=0, len=buf.length; i 240) { + isAscii=false; + break; + } } - } - if (isAscii) { - callback(); - } else { - callback("uploadFailed"); - } - }); + if (isAscii) { + callback(); + } else { + callback("uploadFailed"); + } + }); + }else{ + callback(); + } } else { callback(); } @@ -256,7 +261,6 @@ exports.doImport = function(req, res, padId) } } ], function(err) { - var status = "ok"; //check for known errors and replace the status From a6400b3f619cc62602afa8fc9c6ff1686c8aa089 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 29 Dec 2014 22:02:24 +0100 Subject: [PATCH 04/13] allow only for pads less than 10 to be overwritten --- src/node/handler/ImportHandler.js | 24 ++++++++++++++++++------ src/node/utils/ImportEtherpad.js | 1 - 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index 813a8d194..af4c01f1d 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -121,12 +121,24 @@ 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){ - callback(); - }); + // we do this here so we can see if the pad has quit ea few edits + padManager.getPad(padId, function(err, _pad){ + console.error(_pad); + var headCount = _pad.head; + console.error(headCount); + if(headCount >= 10){ + apiLogger.warn("Direct database Import attempt of a pad that already has content, we wont be doing this") + return callback("padHasData"); + }else{ + fs.readFile(srcFile, "utf8", function(err, _text){ + directDatabaseAccess = true; + importEtherpad.setPadRaw(padId, _text, function(err){ + callback(); + }); + }); + } }); }else{ callback(); @@ -264,7 +276,7 @@ exports.doImport = function(req, res, padId) var status = "ok"; //check for known errors and replace the status - if(err == "uploadFailed" || err == "convertFailed") + if(err == "uploadFailed" || err == "convertFailed" || err == "padHasData") { status = err; err = null; diff --git a/src/node/utils/ImportEtherpad.js b/src/node/utils/ImportEtherpad.js index b18708ffa..be6a8929d 100644 --- a/src/node/utils/ImportEtherpad.js +++ b/src/node/utils/ImportEtherpad.js @@ -23,7 +23,6 @@ exports.setPadRaw = function(padId, records, callback){ async.eachSeries(Object.keys(records), function(key, cb){ var value = records[key] - // rewrite padId var oldPadId = key.split(":"); oldPadId[1] = padId; From a2262c56b987b0ec587f0790fc74e6590bccce71 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 29 Dec 2014 22:05:14 +0100 Subject: [PATCH 05/13] msg for user --- src/locales/en.json | 1 + src/static/js/pad_impexp.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/locales/en.json b/src/locales/en.json index 5e074e387..17a83b466 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -130,6 +130,7 @@ "pad.impexp.importing": "Importing...", "pad.impexp.confirmimport": "Importing a file will overwrite the current text of the pad. Are you sure you want to proceed?", "pad.impexp.convertFailed": "We were not able to import this file. Please use a different document format or copy paste manually", + "pad.impexp.padHasData": "We were not able to import this file because this Pad has already had changes, please import to a new pad", "pad.impexp.uploadFailed": "The upload failed, please try again", "pad.impexp.importfailed": "Import failed", "pad.impexp.copypaste": "Please copy paste", diff --git a/src/static/js/pad_impexp.js b/src/static/js/pad_impexp.js index 2548b8bb8..d9a8953d2 100644 --- a/src/static/js/pad_impexp.js +++ b/src/static/js/pad_impexp.js @@ -109,6 +109,8 @@ var padimpexp = (function() msg = html10n.get("pad.impexp.convertFailed"); } else if(status === "uploadFailed"){ msg = html10n.get("pad.impexp.uploadFailed"); + } else if(status === "padHasData"){ + msg = html10n.get("pad.impexp.padHasData"); } function showError(fade) From ec2b844f9433b61c570fd0624644f19de43e4208 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 29 Dec 2014 22:51:31 +0100 Subject: [PATCH 06/13] authors --- src/node/utils/ExportEtherpad.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/node/utils/ExportEtherpad.js b/src/node/utils/ExportEtherpad.js index 99d86140f..0bc2bf04a 100644 --- a/src/node/utils/ExportEtherpad.js +++ b/src/node/utils/ExportEtherpad.js @@ -22,6 +22,8 @@ var ERR = require("async-stacktrace"); exports.getPadRaw = function(padId, callback){ async.waterfall([ function(cb){ + + // Get the Pad available content keys db.findKeys("pad:"+padId+"*", null, function(err,records){ if(!err){ cb(err, records); @@ -30,15 +32,37 @@ exports.getPadRaw = function(padId, callback){ }, function(records, cb){ var data = {}; + async.forEachSeries(Object.keys(records), function(key, r){ + + // For each piece of info about a pad. db.get(records[key], function(err, entry){ data[records[key]] = entry; + + // Get the Pad Authors + if(entry.pool && entry.pool.numToAttrib){ + var authors = entry.pool.numToAttrib; + async.forEachSeries(Object.keys(authors), function(k, c){ + if(authors[k][0] === "author"){ + var authorId = authors[k][1]; + + // Get the author info + db.get("globalAuthor:"+authorId, function(e, authorEntry){ + if(!e) data["globalAuthor:"+authorId] = authorEntry; + }); + + } + // console.log("authorsK", authors[k]); + c(null); + }); + } r(null); // callback; }); }, function(err){ cb(err, data); }) - }], function(err, data){ + } + ], function(err, data){ callback(null, data); }); } From 1e0de620be85b7b4d8af1472a52a851933a921d0 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 29 Dec 2014 23:08:17 +0100 Subject: [PATCH 07/13] more author logic --- src/node/utils/ImportEtherpad.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/node/utils/ImportEtherpad.js b/src/node/utils/ImportEtherpad.js index be6a8929d..f3d3c4b0d 100644 --- a/src/node/utils/ImportEtherpad.js +++ b/src/node/utils/ImportEtherpad.js @@ -23,10 +23,19 @@ exports.setPadRaw = function(padId, records, callback){ async.eachSeries(Object.keys(records), function(key, cb){ var value = records[key] + // rewrite padId var oldPadId = key.split(":"); oldPadId[1] = padId; - var newKey = oldPadId.join(":"); // create the new key + if(oldPadId[0] === "pad"){ + var newKey = oldPadId.join(":"); // create the new key + } + + // Add the author to this new pad + if(oldPadId[0] === "globalAuthor"){ + value.padIDs[padId] = 1 ; + var newKey = value; + } // Write the value to the server db.set(newKey, value); From b8648b4a49a5e3d050a3a414963c0877f49781c8 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 29 Dec 2014 23:08:42 +0100 Subject: [PATCH 08/13] remove error logging --- src/node/handler/ImportHandler.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index af4c01f1d..65006fa72 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -125,9 +125,7 @@ exports.doImport = function(req, res, padId) if(fileIsEtherpad){ // we do this here so we can see if the pad has quit ea few edits padManager.getPad(padId, function(err, _pad){ - console.error(_pad); var headCount = _pad.head; - console.error(headCount); if(headCount >= 10){ apiLogger.warn("Direct database Import attempt of a pad that already has content, we wont be doing this") return callback("padHasData"); From 0676d2fe24b5fe4bd1b84ffad4c23e2fd4029d75 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 30 Dec 2014 00:01:15 +0100 Subject: [PATCH 09/13] working author import --- src/node/utils/ImportEtherpad.js | 34 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/node/utils/ImportEtherpad.js b/src/node/utils/ImportEtherpad.js index f3d3c4b0d..942f4f182 100644 --- a/src/node/utils/ImportEtherpad.js +++ b/src/node/utils/ImportEtherpad.js @@ -20,26 +20,34 @@ var db = require("../db/DB").db; exports.setPadRaw = function(padId, records, callback){ records = JSON.parse(records); - + async.eachSeries(Object.keys(records), function(key, cb){ var value = records[key] - // rewrite padId - var oldPadId = key.split(":"); - oldPadId[1] = padId; - if(oldPadId[0] === "pad"){ - var newKey = oldPadId.join(":"); // create the new key - } + // we know its an author + if(value.padIDs){ + // rewrite author pad ids + value.padIDs[padId] = 1; + var newKey = key; - // Add the author to this new pad - if(oldPadId[0] === "globalAuthor"){ - value.padIDs[padId] = 1 ; - var newKey = value; - } + }else{ + // we can split it to look to see if its pad data + var oldPadId = key.split(":"); + // we know its pad data.. + if(oldPadId[0] === "pad"){ + + // so set the new pad id for the author + oldPadId[1] = padId; + + // and create the value + var newKey = oldPadId.join(":"); // create the new key + } + + } // Write the value to the server db.set(newKey, value); - + cb(); }, function(){ callback(null, true); From 99a239fa9abf5df4c16aff0259ad4bf32256ad99 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 30 Dec 2014 00:10:08 +0100 Subject: [PATCH 10/13] remove console log --- src/node/handler/ExportHandler.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/node/handler/ExportHandler.js b/src/node/handler/ExportHandler.js index 23d1cb10c..39e7f564d 100644 --- a/src/node/handler/ExportHandler.js +++ b/src/node/handler/ExportHandler.js @@ -59,7 +59,6 @@ exports.doExport = function(req, res, padId, type) //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 if(type == "etherpad"){ - console.log("Exporting Etherpad"); exportEtherpad.getPadRaw(padId, function(err, pad){ if(!err){ res.send(pad); From ac4f9eb4cebc0e8dbaa0df425aae660e3fc22071 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 30 Dec 2014 00:12:26 +0100 Subject: [PATCH 11/13] licensing --- src/node/handler/ImportHandler.js | 1 + src/node/utils/ExportEtherpad.js | 2 +- src/node/utils/ImportEtherpad.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index 65006fa72..14cc10194 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -5,6 +5,7 @@ /* * 2011 Peter 'Pita' Martischka (Primary Technology Ltd) * 2012 Iván Eixarch + * 2014 John McLear (Etherpad Foundation / McLear Ltd) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/node/utils/ExportEtherpad.js b/src/node/utils/ExportEtherpad.js index 0bc2bf04a..36df452da 100644 --- a/src/node/utils/ExportEtherpad.js +++ b/src/node/utils/ExportEtherpad.js @@ -1,5 +1,5 @@ /** - * Copyright 2014 John McLear. + * 2014 John McLear (Etherpad Foundation / McLear Ltd) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/node/utils/ImportEtherpad.js b/src/node/utils/ImportEtherpad.js index 942f4f182..8daeb5363 100644 --- a/src/node/utils/ImportEtherpad.js +++ b/src/node/utils/ImportEtherpad.js @@ -1,5 +1,5 @@ /** - * Copyright Yaco Sistemas S.L. 2011. + * 2014 John McLear (Etherpad Foundation / McLear Ltd) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 5ba3cab445e4909275b97fc7414fa56c6c94578d Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 30 Dec 2014 00:13:01 +0100 Subject: [PATCH 12/13] better take some responsibility --- src/node/handler/ExportHandler.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/node/handler/ExportHandler.js b/src/node/handler/ExportHandler.js index 39e7f564d..0a0e51f1c 100644 --- a/src/node/handler/ExportHandler.js +++ b/src/node/handler/ExportHandler.js @@ -4,6 +4,7 @@ /* * 2011 Peter 'Pita' Martischka (Primary Technology Ltd) + * 2014 John McLear (Etherpad Foundation / McLear Ltd) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From a07d1722fc6532d5497bccac63f9196717ebce34 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 30 Dec 2014 12:12:24 +0100 Subject: [PATCH 13/13] no errors on chrome client --- src/node/handler/ImportHandler.js | 15 +++++++++++---- src/static/js/pad_impexp.js | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index 14cc10194..a511637cc 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -247,9 +247,16 @@ exports.doImport = function(req, res, padId) padManager.getPad(padId, function(err, _pad){ var pad = _pad; padManager.unloadPad(padId); - padMessageHandler.updatePadClients(pad, function(){ + + // direct Database Access means a pad user should perform a switchToPad + // and not attempt to recieve updated pad data.. + if(!directDatabaseAccess){ + padMessageHandler.updatePadClients(pad, function(){ + callback(); + }); + }else{ callback(); - }); + } }); }, @@ -282,7 +289,7 @@ exports.doImport = function(req, res, padId) } ERR(err); - + //close the connection res.send( " \ @@ -293,7 +300,7 @@ exports.doImport = function(req, res, padId) if(navigator.userAgent.indexOf('MSIE') === -1){ \ document.domain = document.domain; \ } \ - var impexp = window.parent.padimpexp.handleFrameCall('" + status + "'); \ + var impexp = window.parent.padimpexp.handleFrameCall('" + directDatabaseAccess +"', '" + status + "'); \ }) \ " , 200); diff --git a/src/static/js/pad_impexp.js b/src/static/js/pad_impexp.js index d9a8953d2..77f1eb289 100644 --- a/src/static/js/pad_impexp.js +++ b/src/static/js/pad_impexp.js @@ -237,13 +237,13 @@ var padimpexp = (function() $('#importform').submit(fileInputSubmit); $('.disabledexport').click(cantExport); }, - handleFrameCall: function(status) + handleFrameCall: function(directDatabaseAccess, status) { if (status !== "ok") { importFailed(status); } - + if(directDatabaseAccess) pad.switchToPad(clientVars.padId); importDone(); }, disable: function()