Add a saveRevision API function
Calling saveRevision create an author which name is "API"pull/2527/head
parent
a08c50a77d
commit
845788c39d
|
@ -420,6 +420,15 @@ returns the list of saved revisions of this pad
|
||||||
* `{code: 0, message:"ok", data: {savedRevisions: [2, 42, 1337]}}`
|
* `{code: 0, message:"ok", data: {savedRevisions: [2, 42, 1337]}}`
|
||||||
* `{code: 1, message:"padID does not exist", data: null}`
|
* `{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)
|
#### padUsersCount(padID)
|
||||||
* API >= 1
|
* API >= 1
|
||||||
|
|
||||||
|
|
|
@ -555,6 +555,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
|
getLastEdited(padID) returns the timestamp of the last revision of the pad
|
||||||
|
|
||||||
|
|
|
@ -370,6 +370,7 @@ var version =
|
||||||
, "getRevisionsCount" : ["padID"]
|
, "getRevisionsCount" : ["padID"]
|
||||||
, "getSavedRevisionsCount" : ["padID"]
|
, "getSavedRevisionsCount" : ["padID"]
|
||||||
, "listSavedRevisions" : ["padID"]
|
, "listSavedRevisions" : ["padID"]
|
||||||
|
, "saveRevision" : ["padID", "rev"]
|
||||||
, "getRevisionChangeset" : ["padID", "rev"]
|
, "getRevisionChangeset" : ["padID", "rev"]
|
||||||
, "getLastEdited" : ["padID"]
|
, "getLastEdited" : ["padID"]
|
||||||
, "deletePad" : ["padID"]
|
, "deletePad" : ["padID"]
|
||||||
|
|
Loading…
Reference in New Issue