summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuc Didry <luc@didry.org>2015-02-25 01:04:27 +0100
committerLuc Didry <luc@didry.org>2015-02-25 01:04:27 +0100
commit845788c39df0b9674c516e7673a8ba7bb43495b1 (patch)
treed003a308776ddb335a1f4662f23d1c55d7b1347e
parenta08c50a77dc897009f9e40d9d0bdab0a219d59fa (diff)
downloadetherpad-lite-845788c39df0b9674c516e7673a8ba7bb43495b1.zip
Add a saveRevision API function
Calling saveRevision create an author which name is "API"
-rw-r--r--doc/api/http_api.md9
-rw-r--r--src/node/db/API.js73
-rw-r--r--src/node/handler/APIHandler.js1
3 files changed, 83 insertions, 0 deletions
diff --git a/doc/api/http_api.md b/doc/api/http_api.md
index d6432e3c..2ae674d8 100644
--- a/doc/api/http_api.md
+++ b/doc/api/http_api.md
@@ -420,6 +420,15 @@ returns the list of saved revisions of this pad
* `{code: 0, message:"ok", data: {savedRevisions: [2, 42, 1337]}}`
* `{code: 1, message:"padID does not exist", data: null}`
+#### saveRevision(padID [, rev])
+ * API >= 1.2.11
+
+saves a revision
+
+*Example returns:*
+ * `{code: 0, message:"ok", data: null}`
+ * `{code: 1, message:"padID does not exist", data: null}`
+
#### padUsersCount(padID)
* API >= 1
diff --git a/src/node/db/API.js b/src/node/db/API.js
index ab8a1d40..69a380c7 100644
--- a/src/node/db/API.js
+++ b/src/node/db/API.js
@@ -556,6 +556,79 @@ exports.listSavedRevisions = function(padID, callback)
}
/**
+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/handler/APIHandler.js b/src/node/handler/APIHandler.js
index a68a4472..232b0b46 100644
--- a/src/node/handler/APIHandler.js
+++ b/src/node/handler/APIHandler.js
@@ -370,6 +370,7 @@ var version =
, "getRevisionsCount" : ["padID"]
, "getSavedRevisionsCount" : ["padID"]
, "listSavedRevisions" : ["padID"]
+ , "saveRevision" : ["padID", "rev"]
, "getRevisionChangeset" : ["padID", "rev"]
, "getLastEdited" : ["padID"]
, "deletePad" : ["padID"]