From ab0d3c87cb6b34a3545c58226d8c5c52a08762ec Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Wed, 27 Jun 2012 09:55:03 -0700 Subject: [PATCH] Add in getLastEdited API call This new HTTP API call, getLastEdited, will return the time of the last revision, in UNIX timestamp format. --- src/node/db/API.js | 18 ++++++++++++++++++ src/node/db/Pad.js | 8 +++++++- src/node/handler/APIHandler.js | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/node/db/API.js b/src/node/db/API.js index 37fd3f16..b3cffbe3 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -282,6 +282,24 @@ exports.getRevisionsCount = function(padID, callback) }); } +/** +getLastEdited(padID) returns the timestamp of the last revision of the pad + +Example returns: + +{code: 0, message:"ok", data: {lastEdited: 1340815946602}} +{code: 1, message:"padID does not exist", data: null} +*/ +exports.getLastEdited = function(padID, callback) +{ + //get the pad + getPadSafe(padID, true, function(err, pad) + { + if(ERR(err, callback)) return; + callback(null, {lastEdited: pad.getLastEdited()}); + }); +} + /** createPad(padName [, text]) creates a new pad in this group diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index b4a39c17..b486a44d 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -80,7 +80,7 @@ Pad.prototype.appendRevision = function appendRevision(aChangeset, author) { newRevData.meta.atext = this.atext; } - db.set("pad:"+this.id+":revs:"+newRev, newRevData); + db.set("pad:"+this.id+":revs:"+newRev, newRevData); this.saveToDatabase(); }; @@ -102,6 +102,12 @@ Pad.prototype.saveToDatabase = function saveToDatabase(){ db.set("pad:"+this.id, dbObject); } +// get time of last edit (changeset application) +Pad.prototype.getLastEdit = function getLastEdit(callback){ + var revNum = this.getHeadRevisionNumber(); + db.getSub("pad:"+this.id+":revs:"+revNum, ["meta", "timestamp"], callback); +} + Pad.prototype.getRevisionChangeset = function getRevisionChangeset(revNum, callback) { db.getSub("pad:"+this.id+":revs:"+revNum, ["changeset"], callback); }; diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index 98b1ed16..a7b1a8ab 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -57,6 +57,7 @@ var functions = { "getHTML" : ["padID", "rev"], "setHTML" : ["padID", "html"], "getRevisionsCount" : ["padID"], + "getLastEdited" : ["padID"], "deletePad" : ["padID"], "getReadOnlyID" : ["padID"], "setPublicStatus" : ["padID", "publicStatus"],