From e0cf6098fb73833f5db85294d95875a62163f116 Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Wed, 19 Oct 2011 21:46:28 +0200 Subject: [PATCH 01/16] fixing issues with bad import uploads, fixed #186 --- node/handler/ImportHandler.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/node/handler/ImportHandler.js b/node/handler/ImportHandler.js index 8936e488a..a1ddf9924 100644 --- a/node/handler/ImportHandler.js +++ b/node/handler/ImportHandler.js @@ -61,10 +61,19 @@ exports.doImport = function(req, res, padId) form.parse(req, function(err, fields, files) { - //save the path of the uploaded file - srcFile = files.file.path; - - callback(err); + //the upload failed, stop at this point + if(err || files.file === undefined) + { + console.warn("Uploading Error: " + err.stack); + callback("uploadFailed"); + } + //everything ok, continue + else + { + //save the path of the uploaded file + srcFile = files.file.path; + callback(); + } }); }, @@ -157,6 +166,13 @@ exports.doImport = function(req, res, padId) } ], function(err) { + //the upload failed, there is nothing we can do, send a 500 + if(err == "uploadFailed") + { + res.send(500); + return; + } + if(err) throw err; //close the connection From 0f559347eee8857ea7ecc36f595d8bc872a7dabc Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Wed, 19 Oct 2011 21:48:36 +0200 Subject: [PATCH 02/16] Fixing a bug that happens when a socket.io connection closes very early after a CLIENT_READY message --- node/handler/PadMessageHandler.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/node/handler/PadMessageHandler.js b/node/handler/PadMessageHandler.js index f89f4934c..438f0ff36 100644 --- a/node/handler/PadMessageHandler.js +++ b/node/handler/PadMessageHandler.js @@ -809,10 +809,15 @@ function handleClientReady(client, message) //Send the clientVars to the Client client.json.send(clientVars); - //Save the revision and the author id in sessioninfos - sessioninfos[client.id].rev = pad.getHeadRevisionNumber(); - sessioninfos[client.id].author = author; - + //sometimes the client disconnects very early and the session of it is already removed + //thats why we have to check that case + if(sessioninfos[client.id] !== undefined) + { + //Save the revision and the author id in sessioninfos + sessioninfos[client.id].rev = pad.getHeadRevisionNumber(); + sessioninfos[client.id].author = author; + } + //prepare the notification for the other users on the pad, that this user joined var messageToTheOtherUsers = { "type": "COLLABROOM", From 2cc7dcb751bf15c0c76fe51fb35801228b11953e Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 26 Oct 2011 20:13:10 +0200 Subject: [PATCH 03/16] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b90f789a7..322fb9139 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description" : "A Etherpad based on node.js", "homepage" : "https://github.com/Pita/etherpad-lite", "keywords" : ["etherpad", "realtime", "collaborative", "editor"], - "author" : "Peter 'Pita' Martischka ", + "author" : "Peter 'Pita' Martischka - Primary Technology Ltd", "contributors": [ { "name": "John McLear", "name": "Hans Pinckaers", From e4481ea22b911d9818750e74ad30c7983d1a34dc Mon Sep 17 00:00:00 2001 From: Lorenzo Gil Date: Mon, 31 Oct 2011 11:18:44 +0100 Subject: [PATCH 04/16] Allow to get the HTML of the pad with the API --- node/db/API.js | 85 ++++++++++++++++++++++++++++++++++++++ node/handler/APIHandler.js | 1 + node/utils/ExportHtml.js | 2 + 3 files changed, 88 insertions(+) diff --git a/node/db/API.js b/node/db/API.js index 9912b098d..2069ce688 100644 --- a/node/db/API.js +++ b/node/db/API.js @@ -25,6 +25,7 @@ var groupManager = require("./GroupManager"); var authorManager = require("./AuthorManager"); var sessionManager = require("./SessionManager"); var async = require("async"); +var exportHtml = require("../utils/ExportHtml"); /**********************/ /**GROUP FUNCTIONS*****/ @@ -169,6 +170,90 @@ exports.setText = function(padID, text, callback) }); } +/** +getHTML(padID, [rev]) returns the html of a pad + +Example returns: + +{code: 0, message:"ok", data: {text:"Welcome Text"}} +{code: 1, message:"padID does not exist", data: null} +*/ +exports.getHTML = function(padID, rev, callback) +{ + if(typeof rev == "function") + { + callback = rev; + rev = undefined; + } + + if (rev !== undefined && typeof rev != "number") + { + if (!isNaN(parseInt(rev))) + { + rev = parseInt(rev); + } + else + { + callback({stop: "rev is not a number"}); + return; + } + } + + if(rev !== undefined && rev < 0) + { + callback({stop: "rev is a negative number"}); + return; + } + + if(rev !== undefined && !is_int(rev)) + { + callback({stop: "rev is a float value"}); + return; + } + + getPadSafe(padID, true, function(err, pad) + { + if(err) + { + callback(err); + return; + } + + //the client asked for a special revision + if(rev !== undefined) + { + //check if this is a valid revision + if(rev > pad.getHeadRevisionNumber()) + { + callback({stop: "rev is higher than the head revision of the pad"}); + return; + } + + //get the html of this revision + exportHtml.getPadHTML(pad, rev, function(err, html) + { + if(!err) + { + data = {html: html}; + } + callback(err, data); + }); + } + //the client wants the latest text, lets return it to him + else + { + exportHtml.getPadHTML(pad, undefined, function (err, html) + { + if(!err) + { + data = {html: html}; + } + callback(err, data); + }); + } + }); +} + /*****************/ /**PAD FUNCTIONS */ /*****************/ diff --git a/node/handler/APIHandler.js b/node/handler/APIHandler.js index 34d63f18d..57eeeb734 100644 --- a/node/handler/APIHandler.js +++ b/node/handler/APIHandler.js @@ -50,6 +50,7 @@ var functions = { "listSessionsOfAuthor" : ["authorID"], "getText" : ["padID", "rev"], "setText" : ["padID", "text"], + "getHTML" : ["padID", "rev"], "getRevisionsCount" : ["padID"], "deletePad" : ["padID"], "getReadOnlyID" : ["padID"], diff --git a/node/utils/ExportHtml.js b/node/utils/ExportHtml.js index dce156ec8..354757e1e 100644 --- a/node/utils/ExportHtml.js +++ b/node/utils/ExportHtml.js @@ -85,6 +85,8 @@ function getPadHTML(pad, revNum, callback) }); } +exports.getPadHTML = getPadHTML; + function getHTMLFromAtext(pad, atext) { var apool = pad.apool(); From 90ba811bb556b9dd9e436961087f14a310ce98bc Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Fri, 4 Nov 2011 03:15:26 +0100 Subject: [PATCH 05/16] Fixed a bug that creates invalid HTML at Export that lets Abiwords parser crash --- node/utils/ExportHtml.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/node/utils/ExportHtml.js b/node/utils/ExportHtml.js index dce156ec8..c02e12992 100644 --- a/node/utils/ExportHtml.js +++ b/node/utils/ExportHtml.js @@ -119,8 +119,10 @@ function getHTMLFromAtext(pad, atext) var taker = Changeset.stringIterator(text); var assem = Changeset.stringAssembler(); + var openTags = []; function emitOpenTag(i) { + openTags.unshift(i); assem.append('<'); assem.append(tags[i]); assem.append('>'); @@ -128,10 +130,27 @@ function getHTMLFromAtext(pad, atext) function emitCloseTag(i) { + openTags.shift(); assem.append(''); } + + function orderdCloseTags(tags2close) + { + for(var i=0;i= 0; i--) { if (propVals[i] === LEAVE) { - emitCloseTag(i); + //emitCloseTag(i); + tags2close.push(i); propVals[i] = false; } else if (propVals[i] === STAY) { - emitCloseTag(i); + //emitCloseTag(i); + tags2close.push(i); } } + + orderdCloseTags(tags2close); + for (var i = 0; i < propVals.length; i++) { if (propVals[i] === ENTER || propVals[i] === STAY) @@ -235,14 +261,18 @@ function getHTMLFromAtext(pad, atext) assem.append(_escapeHTML(s)); } // end iteration over spans in line + + var tags2close = []; for (var i = propVals.length - 1; i >= 0; i--) { if (propVals[i]) { - emitCloseTag(i); + tags2close.push(i); propVals[i] = false; } } + + orderdCloseTags(tags2close); } // end processNextChars if (urls) { From f6165eb2ea04493141d4622860cb141cfcdfd062 Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Sat, 5 Nov 2011 19:34:01 +0100 Subject: [PATCH 06/16] Fixed another bug that breaked the abiword parser --- node/utils/ExportHtml.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/node/utils/ExportHtml.js b/node/utils/ExportHtml.js index c02e12992..9b7ac9038 100644 --- a/node/utils/ExportHtml.js +++ b/node/utils/ExportHtml.js @@ -257,8 +257,13 @@ function getHTMLFromAtext(pad, atext) { chars--; // exclude newline at end of line, if present } + var s = taker.take(chars); - + + //removes the characters with the code 12. Don't know where they come + //from but they break the abiword parser and are completly useless + s = s.replace(String.fromCharCode(12), ""); + assem.append(_escapeHTML(s)); } // end iteration over spans in line From bf0fe9377d006efe361a985dd55a1e945cd4a283 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 6 Nov 2011 12:06:16 +0000 Subject: [PATCH 07/16] Input fix for Wikinaut --- static/css/pad.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/css/pad.css b/static/css/pad.css index 45385a5b7..3d170c3dd 100644 --- a/static/css/pad.css +++ b/static/css/pad.css @@ -93,7 +93,7 @@ a img } input[type="file"] { - color: #fff; + color: #000; } #editbar ul li.separator From 4fc4a3538148bc995fff989794e91779ed4c847f Mon Sep 17 00:00:00 2001 From: jaseg Date: Wed, 9 Nov 2011 17:19:00 +0100 Subject: [PATCH 08/16] Spelling fixes in log messages, made a delay windows-only which according to a comment should be windows-only, fixed a random filename generator. --- node/handler/ExportHandler.js | 16 +++++++++------- node/handler/PadMessageHandler.js | 22 +++++++++++----------- node/handler/TimesliderMessageHandler.js | 14 +++++++------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/node/handler/ExportHandler.js b/node/handler/ExportHandler.js index a87219bb7..8cc74747d 100644 --- a/node/handler/ExportHandler.js +++ b/node/handler/ExportHandler.js @@ -81,10 +81,9 @@ exports.doExport = function(req, res, padId, type) res.send(html); callback("stop"); } - //write the html export to a file - else + else //write the html export to a file { - randNum = Math.floor(Math.random()*new Date().getTime()); + randNum = Math.floor(Math.random()*0xFFFFFFFF); srcFile = tempDirectory + "/eplite_export_" + randNum + ".html"; fs.writeFile(srcFile, html, callback); } @@ -114,10 +113,13 @@ exports.doExport = function(req, res, padId, type) function(callback) { //100ms delay to accomidate for slow windows fs - setTimeout(function() - { - fs.unlink(destFile, callback); - }, 100); + if(os.type().indexOf("Windows") > -1) + { + setTimeout(function() + { + fs.unlink(destFile, callback); + }, 100); + } } ], callback); } diff --git a/node/handler/PadMessageHandler.js b/node/handler/PadMessageHandler.js index 438f0ff36..0fdece233 100644 --- a/node/handler/PadMessageHandler.js +++ b/node/handler/PadMessageHandler.js @@ -193,7 +193,7 @@ exports.handleMessage = function(client, message) //if the message type is unkown, throw an exception else { - messageLogger.warn("Droped message, unkown Message Type " + message.type); + messageLogger.warn("Dropped message, unkown Message Type " + message.type); } } @@ -272,12 +272,12 @@ function handleSuggestUserName(client, message) //check if all ok if(message.data.payload.newName == null) { - messageLogger.warn("Droped message, suggestUserName Message has no newName!"); + messageLogger.warn("Dropped message, suggestUserName Message has no newName!"); return; } if(message.data.payload.unnamedId == null) { - messageLogger.warn("Droped message, suggestUserName Message has no unnamedId!"); + messageLogger.warn("Dropped message, suggestUserName Message has no unnamedId!"); return; } @@ -304,7 +304,7 @@ function handleUserInfoUpdate(client, message) //check if all ok if(message.data.userInfo.colorId == null) { - messageLogger.warn("Droped message, USERINFO_UPDATE Message has no colorId!"); + messageLogger.warn("Dropped message, USERINFO_UPDATE Message has no colorId!"); return; } @@ -348,17 +348,17 @@ function handleUserChanges(client, message) //check if all ok if(message.data.baseRev == null) { - messageLogger.warn("Droped message, USER_CHANGES Message has no baseRev!"); + messageLogger.warn("Dropped message, USER_CHANGES Message has no baseRev!"); return; } if(message.data.apool == null) { - messageLogger.warn("Droped message, USER_CHANGES Message has no apool!"); + messageLogger.warn("Dropped message, USER_CHANGES Message has no apool!"); return; } if(message.data.changeset == null) { - messageLogger.warn("Droped message, USER_CHANGES Message has no changeset!"); + messageLogger.warn("Dropped message, USER_CHANGES Message has no changeset!"); return; } @@ -600,22 +600,22 @@ function handleClientReady(client, message) //check if all ok if(!message.token) { - messageLogger.warn("Droped message, CLIENT_READY Message has no token!"); + messageLogger.warn("Dropped message, CLIENT_READY message has no token!"); return; } if(!message.padId) { - messageLogger.warn("Droped message, CLIENT_READY Message has no padId!"); + messageLogger.warn("Dropped message, CLIENT_READY message has no padId!"); return; } if(!message.protocolVersion) { - messageLogger.warn("Droped message, CLIENT_READY Message has no protocolVersion!"); + messageLogger.warn("Dropped message, CLIENT_READY message has no protocolVersion!"); return; } if(message.protocolVersion != 2) { - messageLogger.warn("Droped message, CLIENT_READY Message has a unkown protocolVersion '" + message.protocolVersion + "'!"); + messageLogger.warn("Dropped message, CLIENT_READY message has an unkown protocolVersion '" + message.protocolVersion + "'!"); return; } diff --git a/node/handler/TimesliderMessageHandler.js b/node/handler/TimesliderMessageHandler.js index a06ab54c8..fa272cc91 100644 --- a/node/handler/TimesliderMessageHandler.js +++ b/node/handler/TimesliderMessageHandler.js @@ -77,7 +77,7 @@ exports.handleMessage = function(client, message) //if the message type is unkown, throw an exception else { - messageLogger.warn("Droped message, unkown Message Type: '" + message.type + "'"); + messageLogger.warn("Dropped message, unkown Message Type: '" + message.type + "'"); } } @@ -85,7 +85,7 @@ function handleClientReady(client, message) { if(message.padId == null) { - messageLogger.warn("Droped message, changeset request has no padId!"); + messageLogger.warn("Dropped message, changeset request has no padId!"); return; } @@ -106,27 +106,27 @@ function handleChangesetRequest(client, message) //check if all ok if(message.data == null) { - messageLogger.warn("Droped message, changeset request has no data!"); + messageLogger.warn("Dropped message, changeset request has no data!"); return; } if(message.padId == null) { - messageLogger.warn("Droped message, changeset request has no padId!"); + messageLogger.warn("Dropped message, changeset request has no padId!"); return; } if(message.data.granularity == null) { - messageLogger.warn("Droped message, changeset request has no granularity!"); + messageLogger.warn("Dropped message, changeset request has no granularity!"); return; } if(message.data.start == null) { - messageLogger.warn("Droped message, changeset request has no start!"); + messageLogger.warn("Dropped message, changeset request has no start!"); return; } if(message.data.requestID == null) { - messageLogger.warn("Droped message, changeset request has no requestID!"); + messageLogger.warn("Dropped message, changeset request has no requestID!"); return; } From eecb45cbfd230062d11aeb95a68f62889c39bf88 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sat, 12 Nov 2011 18:30:38 +0000 Subject: [PATCH 09/16] Focus on input box onLoad --- static/index.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/static/index.html b/static/index.html index e995cdb2f..86b33acc0 100644 --- a/static/index.html +++ b/static/index.html @@ -86,12 +86,13 @@ input[type="submit"]::-moz-focus-inner { border: 0 } @-moz-document url-prefix() { input[type="submit"] { padding: 7px } } +
New Pad

or create/open a Pad with the name
-
- + +
@@ -123,4 +124,5 @@ //start the costum js if(typeof costumStart == "function") costumStart(); + \ No newline at end of file From 08e0c91204b2d199d6244e794b3778ced2f54492 Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Sat, 12 Nov 2011 16:46:10 -0800 Subject: [PATCH 10/16] removed the node v0.4 check, it works now with node v0.6 --- bin/installDeps.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/bin/installDeps.sh b/bin/installDeps.sh index cb3676063..3fd6da747 100755 --- a/bin/installDeps.sh +++ b/bin/installDeps.sh @@ -20,13 +20,6 @@ hash node > /dev/null 2>&1 || { exit 1 } -#check node version -NODE_VERSION=$(node --version) -if [ ! $(echo $NODE_VERSION | cut -d "." -f 1-2) = "v0.4" ]; then - echo "You're running a wrong version of node, you're using $NODE_VERSION, we need v0.4.x" >&2 - exit 1 -fi - #Is npm installed? hash npm > /dev/null 2>&1 || { echo "Please install npm ( http://npmjs.org )" >&2 From 08fbc3c3bc324765a1e32dc10227057759450b7c Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Sat, 12 Nov 2011 16:46:26 -0800 Subject: [PATCH 11/16] Updated all dependencies --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 322fb9139..7be586830 100644 --- a/package.json +++ b/package.json @@ -10,16 +10,16 @@ "name": "Robin Buse"} ], "dependencies" : { - "socket.io" : "0.7.9", + "socket.io" : "0.8.7", "ueberDB" : "0.1.2", - "async" : "0.1.9", - "joose" : "3.18.0", - "express" : "2.4.5", + "async" : "0.1.15", + "joose" : "3.50.0", + "express" : "2.5.0", "clean-css" : "0.2.4", - "uglify-js" : "1.0.7", + "uglify-js" : "1.1.1", "gzip" : "0.1.0", - "formidable" : "1.0.2", - "log4js" : "0.3.8" + "formidable" : "1.0.7", + "log4js" : "0.3.9" }, "version" : "1.0.0" } From 820326dc2bb70c298325fd03145bbd6a5f691f79 Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Sat, 12 Nov 2011 16:47:01 -0800 Subject: [PATCH 12/16] Output more informations on message dropped --- node/handler/PadMessageHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/handler/PadMessageHandler.js b/node/handler/PadMessageHandler.js index 0fdece233..af4aa6426 100644 --- a/node/handler/PadMessageHandler.js +++ b/node/handler/PadMessageHandler.js @@ -193,7 +193,7 @@ exports.handleMessage = function(client, message) //if the message type is unkown, throw an exception else { - messageLogger.warn("Dropped message, unkown Message Type " + message.type); + messageLogger.warn("Dropped message, unkown Message Type " + message.type + ": " + JSON.stringify(message)); } } From 5f12744446792045446d652e2fd4b38faac8db25 Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Sat, 12 Nov 2011 17:32:30 -0800 Subject: [PATCH 13/16] update ueberDB --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7be586830..f1c30caa7 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ ], "dependencies" : { "socket.io" : "0.8.7", - "ueberDB" : "0.1.2", + "ueberDB" : "0.1.3", "async" : "0.1.15", "joose" : "3.50.0", "express" : "2.5.0", From dac828e8f6213c19247a698bf092c97a82a94d2e Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 13 Nov 2011 14:32:21 +0000 Subject: [PATCH 14/16] Update static/index.html --- static/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/index.html b/static/index.html index 86b33acc0..2bed58f98 100644 --- a/static/index.html +++ b/static/index.html @@ -91,7 +91,7 @@
New Pad

or create/open a Pad with the name
-
+
From a5a9592031e2833a18f89556fc0e92b5d00edba2 Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Sun, 13 Nov 2011 20:25:22 -0800 Subject: [PATCH 15/16] Revert "Fixing a bug that happens when a socket.io connection closes very early after a CLIENT_READY message" This reverts commit 0f559347eee8857ea7ecc36f595d8bc872a7dabc. --- node/handler/PadMessageHandler.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/node/handler/PadMessageHandler.js b/node/handler/PadMessageHandler.js index af4aa6426..6e24db6b5 100644 --- a/node/handler/PadMessageHandler.js +++ b/node/handler/PadMessageHandler.js @@ -809,15 +809,10 @@ function handleClientReady(client, message) //Send the clientVars to the Client client.json.send(clientVars); - //sometimes the client disconnects very early and the session of it is already removed - //thats why we have to check that case - if(sessioninfos[client.id] !== undefined) - { - //Save the revision and the author id in sessioninfos - sessioninfos[client.id].rev = pad.getHeadRevisionNumber(); - sessioninfos[client.id].author = author; - } - + //Save the revision and the author id in sessioninfos + sessioninfos[client.id].rev = pad.getHeadRevisionNumber(); + sessioninfos[client.id].author = author; + //prepare the notification for the other users on the pad, that this user joined var messageToTheOtherUsers = { "type": "COLLABROOM", From 9eac04aaa61d6199ae5833c676447b4eef0c459e Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Sun, 13 Nov 2011 20:33:13 -0800 Subject: [PATCH 16/16] Fixed a huge problem with the sessioninfos array --- node/handler/PadMessageHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/handler/PadMessageHandler.js b/node/handler/PadMessageHandler.js index 6e24db6b5..5dccafc54 100644 --- a/node/handler/PadMessageHandler.js +++ b/node/handler/PadMessageHandler.js @@ -136,7 +136,7 @@ exports.handleDisconnect = function(client) { if(pad2sessions[sessionPad][i] == client.id) { - delete pad2sessions[sessionPad][i]; + pad2sessions[sessionPad].splice(i, 1); break; } }