pad.libre-service.eu-etherpad/src/node/hooks/express/padreadonly.js
Ray Bellis d5d28717c4 access controls: promisification
`getPadAccess()` (src/node/padaccess.js) is now "promise only", resolving to
`true` or `false` as appropriate, and throwing an exception if there's an
error.

The two call sites (padreadonly.js and importexport.js) updated to match.
2019-01-23 16:29:36 +00:00

26 lines
760 B
JavaScript

var readOnlyManager = require("../../db/ReadOnlyManager");
var hasPadAccess = require("../../padaccess");
var exporthtml = require("../../utils/ExportHtml");
exports.expressCreateServer = function (hook_name, args, cb) {
// serve read only pad
args.app.get('/ro/:id', async function(req, res) {
// translate the read only pad to a padId
let padId = await readOnlyManager.getPadId(req.params.id);
if (padId == null) {
res.status(404).send('404 - Not Found');
return;
}
// we need that to tell hasPadAcess about the pad
req.params.pad = padId;
if (await hasPadAccess(req, res)) {
// render the html document
html = await exporthtml.getPadHTMLDocument(padId, null);
res.send(html);
}
});
}