Merge pull request #191 from Yaco-Sistemas/master
Get the HTML of a Pad via the API
This commit is contained in:
commit
17666339d0
|
@ -25,6 +25,7 @@ var groupManager = require("./GroupManager");
|
|||
var authorManager = require("./AuthorManager");
|
||||
var sessionManager = require("./SessionManager");
|
||||
var async = require("async");
|
||||
var exportHtml = require("../utils/ExportHtml");
|
||||
|
||||
/**********************/
|
||||
/**GROUP FUNCTIONS*****/
|
||||
|
@ -169,6 +170,90 @@ exports.setText = function(padID, text, callback)
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
getHTML(padID, [rev]) returns the html of a pad
|
||||
|
||||
Example returns:
|
||||
|
||||
{code: 0, message:"ok", data: {text:"Welcome <strong>Text</strong>"}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getHTML = function(padID, rev, callback)
|
||||
{
|
||||
if(typeof rev == "function")
|
||||
{
|
||||
callback = rev;
|
||||
rev = undefined;
|
||||
}
|
||||
|
||||
if (rev !== undefined && typeof rev != "number")
|
||||
{
|
||||
if (!isNaN(parseInt(rev)))
|
||||
{
|
||||
rev = parseInt(rev);
|
||||
}
|
||||
else
|
||||
{
|
||||
callback({stop: "rev is not a number"});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(rev !== undefined && rev < 0)
|
||||
{
|
||||
callback({stop: "rev is a negative number"});
|
||||
return;
|
||||
}
|
||||
|
||||
if(rev !== undefined && !is_int(rev))
|
||||
{
|
||||
callback({stop: "rev is a float value"});
|
||||
return;
|
||||
}
|
||||
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
//the client asked for a special revision
|
||||
if(rev !== undefined)
|
||||
{
|
||||
//check if this is a valid revision
|
||||
if(rev > pad.getHeadRevisionNumber())
|
||||
{
|
||||
callback({stop: "rev is higher than the head revision of the pad"});
|
||||
return;
|
||||
}
|
||||
|
||||
//get the html of this revision
|
||||
exportHtml.getPadHTML(pad, rev, function(err, html)
|
||||
{
|
||||
if(!err)
|
||||
{
|
||||
data = {html: html};
|
||||
}
|
||||
callback(err, data);
|
||||
});
|
||||
}
|
||||
//the client wants the latest text, lets return it to him
|
||||
else
|
||||
{
|
||||
exportHtml.getPadHTML(pad, undefined, function (err, html)
|
||||
{
|
||||
if(!err)
|
||||
{
|
||||
data = {html: html};
|
||||
}
|
||||
callback(err, data);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*****************/
|
||||
/**PAD FUNCTIONS */
|
||||
/*****************/
|
||||
|
|
|
@ -50,6 +50,7 @@ var functions = {
|
|||
"listSessionsOfAuthor" : ["authorID"],
|
||||
"getText" : ["padID", "rev"],
|
||||
"setText" : ["padID", "text"],
|
||||
"getHTML" : ["padID", "rev"],
|
||||
"getRevisionsCount" : ["padID"],
|
||||
"deletePad" : ["padID"],
|
||||
"getReadOnlyID" : ["padID"],
|
||||
|
|
|
@ -85,6 +85,8 @@ function getPadHTML(pad, revNum, callback)
|
|||
});
|
||||
}
|
||||
|
||||
exports.getPadHTML = getPadHTML;
|
||||
|
||||
function getHTMLFromAtext(pad, atext)
|
||||
{
|
||||
var apool = pad.apool();
|
||||
|
|
Loading…
Reference in New Issue