mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
factored out read only pad getter
This commit is contained in:
parent
c5c548db11
commit
a4795eb88d
1 changed files with 34 additions and 32 deletions
|
@ -238,27 +238,27 @@ function translateRoCombinator(managers, req, ERR){
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
//we need that to tell hasPadAccess about the pad
|
//we need that to tell hasPadAccess about the pad
|
||||||
req.params.pad = padId;
|
req.params.pad = padId;
|
||||||
callback(err, padId);
|
return callback(err, padId);
|
||||||
}
|
}
|
||||||
managers.ro.getPadID(req.params.id, padBack);
|
return managers.ro.getPadID(req.params.id, padBack);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function roAsyncOutCombinator(ERR, callback){
|
function roAsyncOutCombinator(ERR, callback){
|
||||||
return function(err, data){
|
return function(err, data){
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
callback(err, data);
|
return callback(err, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function roAccessbackCombinator(exporthtml, padId, callback){
|
function roAccessbackCombinator(exporthtml, padId, callback){
|
||||||
return function(){
|
return function accessBack(){
|
||||||
exporthtml.getPadHTMLDocument(padId, null, false, callback);
|
return exporthtml.getPadHTMLDocument(padId, null, false, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function roRenderCombinator(padAccessp, req, res, exporthtml, ERR){
|
function roRenderCombinator(padAccessp, req, res, exporthtml, ERR){
|
||||||
return function(padId, callback){
|
return function(padId, callback){
|
||||||
if(null == padId)
|
if(null == padId)
|
||||||
return callback("notfound");
|
return callback("notfound");
|
||||||
padAccessp(
|
return padAccessp(
|
||||||
req, res,
|
req, res,
|
||||||
roAccessbackCombinator(
|
roAccessbackCombinator(
|
||||||
exporthtml, padId,
|
exporthtml, padId,
|
||||||
|
@ -269,6 +269,33 @@ function roRenderCombinator(padAccessp, req, res, exporthtml, ERR){
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function roBindSendBackCombinator(res){
|
||||||
|
return function(html, callback){
|
||||||
|
res.send(html);
|
||||||
|
return callback(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function roErrBackCombinator(ERR, res){
|
||||||
|
return function(err){
|
||||||
|
if(!err) return
|
||||||
|
if("notfound" == err)
|
||||||
|
return res.send("404 - Not Found", 404);
|
||||||
|
return ERR(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getRoCombinator(serverName, managers, padAccessp, ERR, exporthtml){
|
||||||
|
return function(req, res){
|
||||||
|
res.header("Server", serverName);
|
||||||
|
return async.waterfall(
|
||||||
|
[
|
||||||
|
translateRoCombinator(managers),
|
||||||
|
roRenderCombinator(padAccessp, req, res, exporthtml, ERR),
|
||||||
|
roBindSendBackCombinator(res)
|
||||||
|
],
|
||||||
|
roErrBackCombinator(ERR, res))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
//initalize the database
|
//initalize the database
|
||||||
setupDb,
|
setupDb,
|
||||||
|
@ -364,32 +391,7 @@ async.waterfall([
|
||||||
}
|
}
|
||||||
|
|
||||||
//serve read only pad
|
//serve read only pad
|
||||||
app.get('/ro/:id', function(req, res)
|
app.get('/ro/:id', getRoCombinator(serverName, {ro: readOnlyManager}, hasPadAccess, ERR, exporthtml));
|
||||||
{
|
|
||||||
res.header("Server", serverName);
|
|
||||||
|
|
||||||
//var html;
|
|
||||||
//var padId;
|
|
||||||
var pad;
|
|
||||||
|
|
||||||
async.waterfall([
|
|
||||||
translateRoCombinater({ro: readOnlyManager}, req, ERR),
|
|
||||||
roRenderCombinator(hasPadAccess, req, res, exporthtml, ERR),
|
|
||||||
function(html, callback)
|
|
||||||
{
|
|
||||||
res.send(html);
|
|
||||||
return callback(null);
|
|
||||||
}
|
|
||||||
], function(err)
|
|
||||||
{
|
|
||||||
//throw any unexpected error
|
|
||||||
if(err && err != "notfound")
|
|
||||||
ERR(err);
|
|
||||||
|
|
||||||
if(err == "notfound")
|
|
||||||
res.send('404 - Not Found', 404);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
//redirects browser to the pad's sanitized url if needed. otherwise, renders the html
|
//redirects browser to the pad's sanitized url if needed. otherwise, renders the html
|
||||||
function goToPad(req, res, render) {
|
function goToPad(req, res, render) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue