bring in some padDiff stuff that doesnt suck
parent
c6882aa65a
commit
5d416579ee
|
@ -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 */
|
||||
/******************************/
|
||||
|
|
|
@ -24,6 +24,7 @@ var fs = require("fs");
|
|||
var api = require("../db/API");
|
||||
var padManager = require("../db/PadManager");
|
||||
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
||||
var padDiff = require("../utils/padDiff");
|
||||
|
||||
//ensure we have an apikey
|
||||
var apikey = null;
|
||||
|
@ -174,6 +175,43 @@ var version =
|
|||
, "listAllGroups" : []
|
||||
, "checkToken" : []
|
||||
}
|
||||
, "1.2.2":
|
||||
{ "createGroup" : []
|
||||
, "createGroupIfNotExistsFor" : ["groupMapper"]
|
||||
, "deleteGroup" : ["groupID"]
|
||||
, "listPads" : ["groupID"]
|
||||
, "listAllPads" : []
|
||||
, "createDiff" : ["padID", "startRev", "endRev"]
|
||||
, "createPad" : ["padID", "text"]
|
||||
, "createGroupPad" : ["groupID", "padName", "text"]
|
||||
, "createAuthor" : ["name"]
|
||||
, "createAuthorIfNotExistsFor": ["authorMapper" , "name"]
|
||||
, "listPadsOfAuthor" : ["authorID"]
|
||||
, "createSession" : ["groupID", "authorID", "validUntil"]
|
||||
, "deleteSession" : ["sessionID"]
|
||||
, "getSessionInfo" : ["sessionID"]
|
||||
, "listSessionsOfGroup" : ["groupID"]
|
||||
, "listSessionsOfAuthor" : ["authorID"]
|
||||
, "getText" : ["padID", "rev"]
|
||||
, "setText" : ["padID", "text"]
|
||||
, "getHTML" : ["padID", "rev"]
|
||||
, "setHTML" : ["padID", "html"]
|
||||
, "getRevisionsCount" : ["padID"]
|
||||
, "getLastEdited" : ["padID"]
|
||||
, "deletePad" : ["padID"]
|
||||
, "getReadOnlyID" : ["padID"]
|
||||
, "setPublicStatus" : ["padID", "publicStatus"]
|
||||
, "getPublicStatus" : ["padID"]
|
||||
, "setPassword" : ["padID", "password"]
|
||||
, "isPasswordProtected" : ["padID"]
|
||||
, "listAuthorsOfPad" : ["padID"]
|
||||
, "padUsersCount" : ["padID"]
|
||||
, "getAuthorName" : ["authorID"]
|
||||
, "padUsers" : ["padID"]
|
||||
, "sendClientsMessage" : ["padID", "msg"]
|
||||
, "listAllGroups" : []
|
||||
, "checkToken" : []
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
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})
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue