From 8f1348b40b5d33ac02029207d3e0398fedbbf5cd Mon Sep 17 00:00:00 2001 From: Guyzmo Date: Mon, 1 Apr 2013 17:18:45 +0200 Subject: [PATCH 1/3] Added getAttributePool, getRevisionOfHead and getRevisionChangeset methods to API v1.2.8 Signed-off-by: Bernard `Guyzmo` Pratz --- src/node/db/API.js | 86 ++++++++++++++++++++++++++++++++++ src/node/handler/APIHandler.js | 42 ++++++++++++++++- 2 files changed, 127 insertions(+), 1 deletion(-) diff --git a/src/node/db/API.js b/src/node/db/API.js index 3955d495..a0a84e32 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -74,6 +74,92 @@ exports.listSessionsOfAuthor = sessionManager.listSessionsOfAuthor; /**PAD CONTENT FUNCTIONS*/ /************************/ +/** +getAttributePool(padID) returns the attribute pool of a pad + +*/ +exports.getAttributePool = function (padID, callback) +{ + getPadSafe(padID, true, function(err, pad) + { + if (ERR(err, callback)) return; + callbalk(null, {pool: pad.pool}); + }); +} + +/** +getRevisionChangeset (padID, [rev]) + +*/ +exports.getRevisionChangeset = function(padID, rev, callback) +{ + // check if rev is set + if (typeof rev === "function") + { + callback = rev; + rev = undefined; + } + + // check if rev is a number + if (rev !== undefined && typeof rev !== "number") + { + // try to parse the number + if (!isNaN(parseInt(rev)) + { + rev = parseInt(rev); + } + else + { + callback(new customError("rev is not a number", "apierror")); + return; + } + } + + // ensure this is not a negative number + if (rev !== undefined && rev < 0) + { + callback(new customError("rev is not a negative number", "apierror")); + return; + } + + // ensure this is not a float value + if (rev !== undefined && !is_int(rev)) + { + callback(new customError("rev is a float value", "apierror")); + return; + } + + // get the pad + getPadSafe(padID, true, function(err, pad) + { + if(ERR(err, callback)) return; + + //the client asked for a special revision + if(rev !== undefined) + { + //check if this is a valid revision + if(rev > pad.getHeadRevisionNumber()) + { + callback(new customError("rev is higher than the head revision of the pad","apierror")); + return; + } + + //get the changeset for this revision + pad.getRevisionChangeset(rev, function(err, changeset) + { + if(ERR(err, callback)) return; + + callback(null, changeset); + }) + } + //the client wants the latest changeset, lets return it to him + else + { + callback(null, {"changeset": pad.getRevisionChangeset(pad.getHeadRevisionNumber())}); + } + }); +} + /** getText(padID, [rev]) returns the text of a pad diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index 4b7dd951..d4ea4f2c 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -180,7 +180,47 @@ var version = , "deleteGroup" : ["groupID"] , "listPads" : ["groupID"] , "listAllPads" : [] - , "createDiffHTML" : ["padID", "startRev", "endRev"] + , "createDiffHTML" : ["padID", "startRev", "endRev"] + , "createPad" : ["padID", "text"] + , "createGroupPad" : ["groupID", "padName", "text"] + , "createAuthor" : ["name"] + , "createAuthorIfNotExistsFor": ["authorMapper" , "name"] + , "listPadsOfAuthor" : ["authorID"] + , "createSession" : ["groupID", "authorID", "validUntil"] + , "deleteSession" : ["sessionID"] + , "getSessionInfo" : ["sessionID"] + , "listSessionsOfGroup" : ["groupID"] + , "listSessionsOfAuthor" : ["authorID"] + , "getText" : ["padID", "rev"] + , "setText" : ["padID", "text"] + , "getHTML" : ["padID", "rev"] + , "setHTML" : ["padID", "html"] + , "getRevisionsCount" : ["padID"] + , "getLastEdited" : ["padID"] + , "deletePad" : ["padID"] + , "getReadOnlyID" : ["padID"] + , "setPublicStatus" : ["padID", "publicStatus"] + , "getPublicStatus" : ["padID"] + , "setPassword" : ["padID", "password"] + , "isPasswordProtected" : ["padID"] + , "listAuthorsOfPad" : ["padID"] + , "padUsersCount" : ["padID"] + , "getAuthorName" : ["authorID"] + , "padUsers" : ["padID"] + , "sendClientsMessage" : ["padID", "msg"] + , "listAllGroups" : [] + , "checkToken" : [] + , "getChatHistory" : ["padID"] + , "getChatHistory" : ["padID", "start", "end"] + , "getChatHead" : ["padID"] + } +, "1.2.8": + { "createGroup" : [] + , "createGroupIfNotExistsFor" : ["groupMapper"] + , "deleteGroup" : ["groupID"] + , "listPads" : ["groupID"] + , "listAllPads" : [] + , "createDiffHTML" : ["padID", "startRev", "endRev"] , "createPad" : ["padID", "text"] , "createGroupPad" : ["groupID", "padName", "text"] , "createAuthor" : ["name"] From 3df3b90bd9687fae2fa9afcfcc7ed3ac40302fb7 Mon Sep 17 00:00:00 2001 From: Bernard `Guyzmo` Pratz Date: Thu, 4 Apr 2013 19:06:18 +0200 Subject: [PATCH 2/3] fixed missing API functions declaration in API ; fixed a typo in APIHandler. Signed-off-by: Bernard `Guyzmo` Pratz --- src/node/db/API.js | 2 +- src/node/handler/APIHandler.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/node/db/API.js b/src/node/db/API.js index a0a84e32..8aa3dff7 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -104,7 +104,7 @@ exports.getRevisionChangeset = function(padID, rev, callback) if (rev !== undefined && typeof rev !== "number") { // try to parse the number - if (!isNaN(parseInt(rev)) + if (!isNaN(parseInt(rev))) { rev = parseInt(rev); } diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index d4ea4f2c..ad14efbb 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -235,7 +235,9 @@ var version = , "setText" : ["padID", "text"] , "getHTML" : ["padID", "rev"] , "setHTML" : ["padID", "html"] + , "getAttributePool" : ["padID"] , "getRevisionsCount" : ["padID"] + , "getRevisionChangeset" : ["padID", "rev"] , "getLastEdited" : ["padID"] , "deletePad" : ["padID"] , "getReadOnlyID" : ["padID"] From 0e5a89beccde6e7e78b6277934945b2dbd2a412a Mon Sep 17 00:00:00 2001 From: Bernard `Guyzmo` Pratz Date: Thu, 4 Apr 2013 19:07:11 +0200 Subject: [PATCH 3/3] added full comments to the new API functions. Signed-off-by: Bernard `Guyzmo` Pratz --- src/node/db/API.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/node/db/API.js b/src/node/db/API.js index 8aa3dff7..dd2053f9 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -77,19 +77,51 @@ exports.listSessionsOfAuthor = sessionManager.listSessionsOfAuthor; /** getAttributePool(padID) returns the attribute pool of a pad +Example returns: +{ + "code":0, + "message":"ok", + "data": { + "pool":{ + "numToAttrib":{ + "0":["author","a.X4m8bBWJBZJnWGSh"], + "1":["author","a.TotfBPzov54ihMdH"], + "2":["author","a.StiblqrzgeNTbK05"], + "3":["bold","true"] + }, + "attribToNum":{ + "author,a.X4m8bBWJBZJnWGSh":0, + "author,a.TotfBPzov54ihMdH":1, + "author,a.StiblqrzgeNTbK05":2, + "bold,true":3 + }, + "nextNum":4 + } + } +} + */ exports.getAttributePool = function (padID, callback) { getPadSafe(padID, true, function(err, pad) { if (ERR(err, callback)) return; - callbalk(null, {pool: pad.pool}); + callback(null, {pool: pad.pool}); }); } /** getRevisionChangeset (padID, [rev]) +get the changeset at a given revision, or last revision if 'rev' is not defined. + +Example returns: +{ + "code" : 0, + "message" : "ok", + "data" : "Z:1>6b|5+6b$Welcome to Etherpad!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nGet involved with Etherpad at http://etherpad.org\n" +} + */ exports.getRevisionChangeset = function(padID, rev, callback) {