summaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorJohn McLear <john@mclear.co.uk>2015-02-27 12:03:03 +0000
committerJohn McLear <john@mclear.co.uk>2015-02-27 12:03:03 +0000
commit152f51aeab8c9f9fd76832db4cfb1f04b1687910 (patch)
tree7756ecd99e5bf334e30d798d79f78d8f2b388313 /src/node
parent38a4f1be5f08784d94080adf55f83d5f146364a1 (diff)
parent92022e493ee882f486e2ad9e5e0986b1af90f614 (diff)
downloadetherpad-lite-152f51aeab8c9f9fd76832db4cfb1f04b1687910.zip
Merge pull request #2527 from ldidry/issue-1870-get-saved-revisions-count
Fixes #1870
Diffstat (limited to 'src/node')
-rw-r--r--src/node/db/API.js111
-rw-r--r--src/node/db/Pad.js15
-rw-r--r--src/node/handler/APIHandler.js3
3 files changed, 129 insertions, 0 deletions
diff --git a/src/node/db/API.js b/src/node/db/API.js
index 81dedcfe..69a380c7 100644
--- a/src/node/db/API.js
+++ b/src/node/db/API.js
@@ -518,6 +518,117 @@ exports.getRevisionsCount = function(padID, callback)
}
/**
+getSavedRevisionsCount(padID) returns the number of saved revisions of this pad
+
+Example returns:
+
+{code: 0, message:"ok", data: {savedRevisions: 42}}
+{code: 1, message:"padID does not exist", data: null}
+*/
+exports.getSavedRevisionsCount = function(padID, callback)
+{
+ //get the pad
+ getPadSafe(padID, true, function(err, pad)
+ {
+ if(ERR(err, callback)) return;
+
+ callback(null, {savedRevisions: pad.getSavedRevisionsNumber()});
+ });
+}
+
+/**
+listSavedRevisions(padID) returns the list of saved revisions of this pad
+
+Example returns:
+
+{code: 0, message:"ok", data: {savedRevisions: [2, 42, 1337]}}
+{code: 1, message:"padID does not exist", data: null}
+*/
+exports.listSavedRevisions = function(padID, callback)
+{
+ //get the pad
+ getPadSafe(padID, true, function(err, pad)
+ {
+ if(ERR(err, callback)) return;
+
+ callback(null, {savedRevisions: pad.getSavedRevisionsList()});
+ });
+}
+
+/**
+saveRevision(padID) returns the list of saved revisions of this pad
+
+Example returns:
+
+{code: 0, message:"ok", data: null}
+{code: 1, message:"padID does not exist", data: null}
+*/
+exports.saveRevision = 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 negativ number
+ if(rev !== undefined && rev < 0)
+ {
+ callback(new customError("rev is a negativ 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;
+ }
+ } else {
+ rev = pad.getHeadRevisionNumber();
+ }
+
+ authorManager.createAuthor('API', function(err, author) {
+ if(ERR(err, callback)) return;
+
+ pad.addSavedRevision(rev, author.authorID, 'Saved through API call');
+ callback();
+ });
+ });
+}
+
+/**
getLastEdited(padID) returns the timestamp of the last revision of the pad
Example returns:
diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js
index 2f5860f8..53847600 100644
--- a/src/node/db/Pad.js
+++ b/src/node/db/Pad.js
@@ -54,6 +54,21 @@ Pad.prototype.getHeadRevisionNumber = function getHeadRevisionNumber() {
return this.head;
};
+Pad.prototype.getSavedRevisionsNumber = function getSavedRevisionsNumber() {
+ return this.savedRevisions.length;
+};
+
+Pad.prototype.getSavedRevisionsList = function getSavedRevisionsList() {
+ var savedRev = new Array();
+ for(var rev in this.savedRevisions){
+ savedRev.push(this.savedRevisions[rev].revNum);
+ }
+ savedRev.sort(function(a, b) {
+ return a - b;
+ });
+ return savedRev;
+};
+
Pad.prototype.getPublicStatus = function getPublicStatus() {
return this.publicStatus;
};
diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js
index a26dd2cf..232b0b46 100644
--- a/src/node/handler/APIHandler.js
+++ b/src/node/handler/APIHandler.js
@@ -368,6 +368,9 @@ var version =
, "setHTML" : ["padID", "html"]
, "getAttributePool" : ["padID"]
, "getRevisionsCount" : ["padID"]
+ , "getSavedRevisionsCount" : ["padID"]
+ , "listSavedRevisions" : ["padID"]
+ , "saveRevision" : ["padID", "rev"]
, "getRevisionChangeset" : ["padID", "rev"]
, "getLastEdited" : ["padID"]
, "deletePad" : ["padID"]