summaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
Diffstat (limited to 'src/node')
-rw-r--r--src/node/db/API.js81
-rw-r--r--src/node/handler/APIHandler.js38
-rw-r--r--src/node/utils/padDiff.js72
3 files changed, 191 insertions, 0 deletions
diff --git a/src/node/db/API.js b/src/node/db/API.js
index 9cad415d..9cecdbd3 100644
--- a/src/node/db/API.js
+++ b/src/node/db/API.js
@@ -568,6 +568,87 @@ exports.checkToken = function(callback)
}
+/**
+createDiff(padID, startRev, endRev) returns an object of diffs from 2 points in a pad
+
+Example returns:
+
+TODO {"code":0,"message":"ok","data":null}
+TODO {"code":4,"message":"no or wrong API Key","data":null}
+*/
+exports.createDiff = function(padID, startRev, endRev, callback){
+ //check if rev is a number
+ if(startRev !== undefined && typeof startRev != "number")
+ {
+ //try to parse the number
+ if(!isNaN(parseInt(startRev)))
+ {
+ startRev = parseInt(startRev, 10);
+ }
+ else
+ {
+ callback({stop: "startRev is not a number"});
+ return;
+ }
+ }
+
+ //check if rev is a number
+ if(endRev !== undefined && typeof endRev != "number")
+ {
+ //try to parse the number
+ if(!isNaN(parseInt(endRev)))
+ {
+ endRev = parseInt(endRev, 10);
+ }
+ else
+ {
+ callback({stop: "endRev is not a number"});
+ return;
+ }
+ }
+
+ //get the pad
+ getPadSafe(padID, true, function(err, pad)
+ {
+ if(err){
+ return callback(err);
+ }
+
+ try {
+ var padDiff = new PadDiff(pad, startRev, endRev);
+ } catch(e) {
+ return callback({stop:e.message});
+ }
+
+ var html, authors;
+
+ async.series([
+ function(callback){
+ padDiff.getHtml(function(err, _html){
+ if(err){
+ return callback(err);
+ }
+
+ html = _html;
+ callback();
+ });
+ },
+ function(callback){
+ padDiff.getAuthors(function(err, _authors){
+ if(err){
+ return callback(err);
+ }
+
+ authors = _authors;
+ callback();
+ });
+ }
+ ], function(err){
+ callback(err, {html: html, authors: authors})
+ });
+ });
+}
+
/******************************/
/** INTERNAL HELPER FUNCTIONS */
/******************************/
diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js
index ae93e933..ec7e9f8d 100644
--- a/src/node/handler/APIHandler.js
+++ b/src/node/handler/APIHandler.js
@@ -24,6 +24,7 @@ var fs = require("fs");
var api = require("../db/API");
var padManager = require("../db/PadManager");
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
+var padDiff = require("../utils/padDiff");
//ensure we have an apikey
var apikey = null;
@@ -174,6 +175,43 @@ var version =
, "listAllGroups" : []
, "checkToken" : []
}
+, "1.2.2":
+ { "createGroup" : []
+ , "createGroupIfNotExistsFor" : ["groupMapper"]
+ , "deleteGroup" : ["groupID"]
+ , "listPads" : ["groupID"]
+ , "listAllPads" : []
+ , "createDiff" : ["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" : []
+ }
};
/**
diff --git a/src/node/utils/padDiff.js b/src/node/utils/padDiff.js
new file mode 100644
index 00000000..15957b82
--- /dev/null
+++ b/src/node/utils/padDiff.js
@@ -0,0 +1,72 @@
+exports.createDiff = function(padID, startRev, endRev, callback){
+ //check if rev is a number
+ if(startRev !== undefined && typeof startRev != "number")
+ {
+ //try to parse the number
+ if(!isNaN(parseInt(startRev)))
+ {
+ startRev = parseInt(startRev, 10);
+ }
+ else
+ {
+ callback({stop: "startRev is not a number"});
+ return;
+ }
+ }
+
+ //check if rev is a number
+ if(endRev !== undefined && typeof endRev != "number")
+ {
+ //try to parse the number
+ if(!isNaN(parseInt(endRev)))
+ {
+ endRev = parseInt(endRev, 10);
+ }
+ else
+ {
+ callback({stop: "endRev is not a number"});
+ return;
+ }
+ }
+
+ //get the pad
+ getPadSafe(padID, true, function(err, pad)
+ {
+ if(err){
+ return callback(err);
+ }
+
+ try {
+ var padDiff = new PadDiff(pad, startRev, endRev);
+ } catch(e) {
+ return callback({stop:e.message});
+ }
+
+ var html, authors;
+
+ async.series([
+ function(callback){
+ padDiff.getHtml(function(err, _html){
+ if(err){
+ return callback(err);
+ }
+
+ html = _html;
+ callback();
+ });
+ },
+ function(callback){
+ padDiff.getAuthors(function(err, _authors){
+ if(err){
+ return callback(err);
+ }
+
+ authors = _authors;
+ callback();
+ });
+ }
+ ], function(err){
+ callback(err, {html: html, authors: authors})
+ });
+ });
+}