2012-02-25 00:15:57 +01:00
|
|
|
var async = require('async');
|
|
|
|
var ERR = require("async-stacktrace");
|
2012-02-25 17:23:44 +01:00
|
|
|
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) {
|
2019-02-08 23:20:57 +01:00
|
|
|
// serve read only pad
|
|
|
|
args.app.get('/ro/:id', function(req, res) {
|
2012-02-25 00:15:57 +01:00
|
|
|
var html;
|
|
|
|
var padId;
|
|
|
|
|
|
|
|
async.series([
|
2019-02-08 23:20:57 +01:00
|
|
|
// translate the read only pad to a padId
|
|
|
|
function(callback) {
|
|
|
|
readOnlyManager.getPadId(req.params.id, function(err, _padId) {
|
2013-12-05 08:41:29 +01:00
|
|
|
if(ERR(err, callback)) return;
|
2012-02-25 00:15:57 +01:00
|
|
|
|
2013-12-05 08:41:29 +01:00
|
|
|
padId = _padId;
|
2012-02-25 00:15:57 +01:00
|
|
|
|
2019-02-08 23:20:57 +01:00
|
|
|
// we need that to tell hasPadAcess about the pad
|
2013-12-05 08:41:29 +01:00
|
|
|
req.params.pad = padId;
|
2012-02-25 00:15:57 +01:00
|
|
|
|
2013-12-05 08:41:29 +01:00
|
|
|
callback();
|
|
|
|
});
|
2012-02-25 00:15:57 +01:00
|
|
|
},
|
2019-02-08 23:20:57 +01:00
|
|
|
// render the html document
|
|
|
|
function(callback) {
|
|
|
|
// return if the there is no padId
|
|
|
|
if(padId == null) {
|
2013-12-05 08:41:29 +01:00
|
|
|
callback("notfound");
|
|
|
|
return;
|
|
|
|
}
|
2012-02-25 00:15:57 +01:00
|
|
|
|
2019-02-08 23:20:57 +01:00
|
|
|
hasPadAccess(req, res, function() {
|
|
|
|
// render the html document
|
|
|
|
exporthtml.getPadHTMLDocument(padId, null, function(err, _html) {
|
2013-12-05 08:41:29 +01:00
|
|
|
if(ERR(err, callback)) return;
|
|
|
|
html = _html;
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
});
|
2012-02-25 00:15:57 +01:00
|
|
|
}
|
2019-02-08 23:20:57 +01:00
|
|
|
],
|
|
|
|
function(err) {
|
|
|
|
// throw any unexpected error
|
2012-02-25 00:15:57 +01:00
|
|
|
if(err && err != "notfound")
|
2013-12-05 08:41:29 +01:00
|
|
|
ERR(err);
|
2012-02-25 00:15:57 +01:00
|
|
|
|
|
|
|
if(err == "notfound")
|
2015-04-10 14:10:55 -05:00
|
|
|
res.status(404).send('404 - Not Found');
|
2012-02-25 00:15:57 +01:00
|
|
|
else
|
2013-12-05 08:41:29 +01:00
|
|
|
res.send(html);
|
2012-02-25 00:15:57 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-05 08:41:29 +01:00
|
|
|
}
|