2017-08-24 23:54:02 +02:00
|
|
|
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 = {
|
|
|
|
index: function(req, res) {
|
2018-09-19 01:23:58 +02:00
|
|
|
res.send(stripEvents(routes().toString('/', state(req))));
|
2017-08-24 23:54:02 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
blank: function(req, res) {
|
2018-09-19 01:23:58 +02:00
|
|
|
res.send(stripEvents(routes().toString('/blank', state(req))));
|
2017-08-24 23:54:02 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
download: async function(req, res, next) {
|
|
|
|
const id = req.params.id;
|
|
|
|
try {
|
2017-08-31 18:43:36 +02:00
|
|
|
const { nonce, pwd } = await storage.metadata(id);
|
|
|
|
res.set('WWW-Authenticate', `send-v1 ${nonce}`);
|
2017-08-24 23:54:02 +02:00
|
|
|
res.send(
|
|
|
|
stripEvents(
|
2018-09-19 01:23:58 +02:00
|
|
|
routes().toString(
|
2018-07-31 20:09:18 +02:00
|
|
|
`/download/${id}`,
|
2017-08-24 23:54:02 +02:00
|
|
|
Object.assign(state(req), {
|
2018-08-08 00:40:17 +02:00
|
|
|
downloadMetadata: { nonce, pwd }
|
2017-08-24 23:54:02 +02:00
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
unsupported: function(req, res) {
|
|
|
|
res.send(
|
|
|
|
stripEvents(
|
2018-09-19 01:23:58 +02:00
|
|
|
routes().toString(
|
2017-08-24 23:54:02 +02:00
|
|
|
`/unsupported/${req.params.reason}`,
|
|
|
|
Object.assign(state(req), { fira: true })
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
legal: function(req, res) {
|
2018-09-19 01:23:58 +02:00
|
|
|
res.send(stripEvents(routes().toString('/legal', state(req))));
|
2017-08-24 23:54:02 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
notfound: function(req, res) {
|
2018-09-19 01:23:58 +02:00
|
|
|
res.status(404).send(stripEvents(routes().toString('/404', state(req))));
|
2017-08-24 23:54:02 +02:00
|
|
|
}
|
|
|
|
};
|