Merge pull request #191 from Yaco-Sistemas/master

Get the HTML of a Pad via the API
This commit is contained in:
Peter 'Pita' Martischka 2011-11-12 15:04:53 -08:00
commit 17666339d0
3 changed files with 88 additions and 0 deletions

View File

@ -25,6 +25,7 @@ var groupManager = require("./GroupManager");
var authorManager = require("./AuthorManager"); var authorManager = require("./AuthorManager");
var sessionManager = require("./SessionManager"); var sessionManager = require("./SessionManager");
var async = require("async"); var async = require("async");
var exportHtml = require("../utils/ExportHtml");
/**********************/ /**********************/
/**GROUP FUNCTIONS*****/ /**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 */ /**PAD FUNCTIONS */
/*****************/ /*****************/

View File

@ -50,6 +50,7 @@ var functions = {
"listSessionsOfAuthor" : ["authorID"], "listSessionsOfAuthor" : ["authorID"],
"getText" : ["padID", "rev"], "getText" : ["padID", "rev"],
"setText" : ["padID", "text"], "setText" : ["padID", "text"],
"getHTML" : ["padID", "rev"],
"getRevisionsCount" : ["padID"], "getRevisionsCount" : ["padID"],
"deletePad" : ["padID"], "deletePad" : ["padID"],
"getReadOnlyID" : ["padID"], "getReadOnlyID" : ["padID"],

View File

@ -85,6 +85,8 @@ function getPadHTML(pad, revNum, callback)
}); });
} }
exports.getPadHTML = getPadHTML;
function getHTMLFromAtext(pad, atext) function getHTMLFromAtext(pad, atext)
{ {
var apool = pad.apool(); var apool = pad.apool();