etherpad-lite/src/node/hooks/express/padreadonly.js

26 lines
783 B
JavaScript
Raw Normal View History

2020-11-23 13:24:19 -05:00
const readOnlyManager = require('../../db/ReadOnlyManager');
const hasPadAccess = require('../../padaccess');
const 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) {
// serve read only pad
2020-11-23 13:24:19 -05:00
args.app.get('/ro/:id', async (req, res) => {
// translate the read only pad to a padId
2020-11-23 13:24:19 -05:00
const padId = await readOnlyManager.getPadId(req.params.id);
if (padId == null) {
res.status(404).send('404 - Not Found');
return;
}
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
if (await hasPadAccess(req, res)) {
// render the html document
2020-11-23 13:24:19 -05:00
const html = await exporthtml.getPadHTMLDocument(padId, null);
res.send(html);
}
2012-02-25 00:15:57 +01:00
});
return cb();
2020-11-23 13:24:19 -05:00
};