mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
for read-only pads, turned async series into waterfall to reduce state and factored out translation combinator
This commit is contained in:
parent
7b96bb7f8e
commit
c109af52e1
1 changed files with 29 additions and 12 deletions
|
@ -232,6 +232,17 @@ function sendStatic(path, res, filename, callback){
|
||||||
var filePath = path.normalize(__dirname + "/../static/" + filename);
|
var filePath = path.normalize(__dirname + "/../static/" + filename);
|
||||||
return res.sendfile(filePath, { maxAge: exports.maxAge }, callback);
|
return res.sendfile(filePath, { maxAge: exports.maxAge }, callback);
|
||||||
}
|
}
|
||||||
|
function translateRoCombinator(managers, req, ERR, callback){
|
||||||
|
return function translateRo(callback){
|
||||||
|
function padBack(err, padId){
|
||||||
|
if(ERR(err, callback)) return;
|
||||||
|
//we need that to tell hasPadAccess about the pad
|
||||||
|
req.params.pad = padId;
|
||||||
|
callback(err, padId);
|
||||||
|
}
|
||||||
|
managers.ro.getPadID(req.params.id, padBack);
|
||||||
|
};
|
||||||
|
}
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
//initalize the database
|
//initalize the database
|
||||||
setupDb,
|
setupDb,
|
||||||
|
@ -284,7 +295,7 @@ async.waterfall([
|
||||||
securityManager, req, res,
|
securityManager, req, res,
|
||||||
callback,
|
callback,
|
||||||
function errorback(err, accessObj){
|
function errorback(err, accessObj){
|
||||||
return (ERR(err, callback));
|
return ERR(err, callback);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
/*
|
/*
|
||||||
|
@ -331,28 +342,31 @@ async.waterfall([
|
||||||
{
|
{
|
||||||
res.header("Server", serverName);
|
res.header("Server", serverName);
|
||||||
|
|
||||||
var html;
|
//var html;
|
||||||
var padId;
|
//var padId;
|
||||||
var pad;
|
var pad;
|
||||||
|
|
||||||
async.series([
|
async.waterfall([
|
||||||
//translate the read only pad to a padId
|
//translate the read only pad to a padId
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
|
return translateRoCombinater({ro: readOnlyManager}, req, ERR, callback);
|
||||||
|
/*
|
||||||
readOnlyManager.getPadId(req.params.id, function(err, _padId)
|
readOnlyManager.getPadId(req.params.id, function(err, _padId)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
padId = _padId;
|
//padId = _padId;
|
||||||
|
|
||||||
//we need that to tell hasPadAcess about the pad
|
//we need that to tell hasPadAcess about the pad
|
||||||
req.params.pad = padId;
|
req.params.pad = _padId;
|
||||||
|
|
||||||
callback();
|
callback(null, _padId);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
},
|
},
|
||||||
//render the html document
|
//render the html document
|
||||||
function(callback)
|
function(padId, callback)
|
||||||
{
|
{
|
||||||
//return if the there is no padId
|
//return if the there is no padId
|
||||||
if(padId == null)
|
if(padId == null)
|
||||||
|
@ -367,10 +381,15 @@ async.waterfall([
|
||||||
exporthtml.getPadHTMLDocument(padId, null, false, function(err, _html)
|
exporthtml.getPadHTMLDocument(padId, null, false, function(err, _html)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
html = _html;
|
//html = _html;
|
||||||
callback();
|
callback(null, _html);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
function(html, callback)
|
||||||
|
{
|
||||||
|
res.send(html);
|
||||||
|
return callback(null);
|
||||||
}
|
}
|
||||||
], function(err)
|
], function(err)
|
||||||
{
|
{
|
||||||
|
@ -380,8 +399,6 @@ async.waterfall([
|
||||||
|
|
||||||
if(err == "notfound")
|
if(err == "notfound")
|
||||||
res.send('404 - Not Found', 404);
|
res.send('404 - Not Found', 404);
|
||||||
else
|
|
||||||
res.send(html);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue