summaryrefslogtreecommitdiff
path: root/src/node/db/API.js
diff options
context:
space:
mode:
authorJohn McLear <john@mclear.co.uk>2013-01-22 22:33:51 +0000
committerJohn McLear <john@mclear.co.uk>2013-01-22 22:33:51 +0000
commit5d416579ee3a0943ee258625cc0de4c7a56e49e3 (patch)
tree83cd802c13facb0a5600c0d15bba799bd22b8be7 /src/node/db/API.js
parentc6882aa65a20d2d7ab016acd61bc35a0f294b08c (diff)
downloadetherpad-lite-5d416579ee3a0943ee258625cc0de4c7a56e49e3.zip
bring in some padDiff stuff that doesnt suck
Diffstat (limited to 'src/node/db/API.js')
-rw-r--r--src/node/db/API.js81
1 files changed, 81 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 */
/******************************/