pad.libre-service.eu-etherpad/src/node/hooks/express/padreadonly.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

2012-02-25 00:15:57 +01:00
var async = require('async');
var ERR = require("async-stacktrace");
var readOnlyManager = require("../../db/ReadOnlyManager");
var hasPadAccess = require("../../padaccess");
var exporthtml = require("../../utils/ExportHtml");
2012-02-25 00:15:57 +01:00
2012-02-25 16:53:15 +01:00
exports.expressCreateServer = function (hook_name, args, cb) {
2012-02-25 00:15:57 +01:00
//serve read only pad
args.app.get('/ro/:id', function(req, res)
{
var html;
var padId;
var pad;
async.series([
//translate the read only pad to a padId
function(callback)
{
readOnlyManager.getPadId(req.params.id, function(err, _padId)
{
if(ERR(err, callback)) return;
2012-02-25 00:15:57 +01:00
padId = _padId;
2012-02-25 00:15:57 +01:00
//we need that to tell hasPadAcess about the pad
req.params.pad = padId;
2012-02-25 00:15:57 +01:00
callback();
});
2012-02-25 00:15:57 +01:00
},
//render the html document
function(callback)
{
//return if the there is no padId
if(padId == null)
{
callback("notfound");
return;
}
2012-02-25 00:15:57 +01:00
hasPadAccess(req, res, function()
{
//render the html document
exporthtml.getPadHTMLDocument(padId, null, false, function(err, _html)
{
if(ERR(err, callback)) return;
html = _html;
callback();
});
});
2012-02-25 00:15:57 +01:00
}
], function(err)
{
//throw any unexpected error
if(err && err != "notfound")
ERR(err);
2012-02-25 00:15:57 +01:00
if(err == "notfound")
res.send(404, '404 - Not Found');
2012-02-25 00:15:57 +01:00
else
res.send(html);
2012-02-25 00:15:57 +01:00
});
});
}