fox-send/server/routes/pages.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

const routes = require('../../app/routes');
const storage = require('../storage');
const state = require('../state');
function stripEvents(str) {
// For CSP we need to remove all the event handler placeholders.
// It's ok, app.js will add them when it attaches to the DOM.
return str.replace(/\son\w+=""/g, '');
}
module.exports = {
2018-11-20 20:07:47 +00:00
index: async function(req, res) {
const appState = await state(req);
res.send(stripEvents(routes().toString('/blank', appState)));
},
2018-11-20 20:07:47 +00:00
blank: async function(req, res) {
const appState = await state(req);
res.send(stripEvents(routes().toString('/blank', appState)));
},
download: async function(req, res, next) {
const id = req.params.id;
2018-11-20 20:07:47 +00:00
const appState = await state(req);
try {
const { nonce, pwd, dead, flagged } = await storage.metadata(id);
if (dead && !flagged) {
return next();
}
res.set('WWW-Authenticate', `send-v1 ${nonce}`);
res.send(
stripEvents(
routes().toString(
2018-07-31 18:09:18 +00:00
`/download/${id}`,
2018-11-20 20:07:47 +00:00
Object.assign(appState, {
downloadMetadata: { nonce, pwd, flagged }
})
)
)
);
} catch (e) {
next();
}
},
2018-11-20 20:07:47 +00:00
unsupported: async function(req, res) {
const appState = await state(req);
res.send(
stripEvents(
2019-03-07 00:37:02 +00:00
routes().toString(`/unsupported/${req.params.reason}`, appState)
)
);
},
2018-11-20 20:07:47 +00:00
legal: async function(req, res) {
const appState = await state(req);
res.send(stripEvents(routes().toString('/legal', appState)));
},
2018-11-20 20:07:47 +00:00
notfound: async function(req, res) {
const appState = await state(req);
res.status(404).send(stripEvents(routes().toString('/404', appState)));
}
};