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 = {
|
2018-11-20 21:07:47 +01:00
|
|
|
index: async function(req, res) {
|
|
|
|
const appState = await state(req);
|
2019-01-08 20:24:07 +01:00
|
|
|
res.send(stripEvents(routes().toString('/blank', appState)));
|
2017-08-24 23:54:02 +02:00
|
|
|
},
|
|
|
|
|
2018-11-20 21:07:47 +01:00
|
|
|
blank: async function(req, res) {
|
|
|
|
const appState = await state(req);
|
|
|
|
res.send(stripEvents(routes().toString('/blank', appState)));
|
2017-08-24 23:54:02 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
download: async function(req, res, next) {
|
|
|
|
const id = req.params.id;
|
2018-11-20 21:07:47 +01:00
|
|
|
const appState = await state(req);
|
2017-08-24 23:54:02 +02:00
|
|
|
try {
|
2020-07-13 19:21:28 +02:00
|
|
|
const { nonce, pwd, dead, flagged } = await storage.metadata(id);
|
|
|
|
if (dead && !flagged) {
|
|
|
|
return next();
|
|
|
|
}
|
2017-08-31 18:43:36 +02:00
|
|
|
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}`,
|
2018-11-20 21:07:47 +01:00
|
|
|
Object.assign(appState, {
|
2020-07-13 19:21:28 +02:00
|
|
|
downloadMetadata: { nonce, pwd, flagged }
|
2017-08-24 23:54:02 +02:00
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-11-20 21:07:47 +01:00
|
|
|
unsupported: async function(req, res) {
|
|
|
|
const appState = await state(req);
|
2017-08-24 23:54:02 +02:00
|
|
|
res.send(
|
|
|
|
stripEvents(
|
2019-03-07 01:37:02 +01:00
|
|
|
routes().toString(`/unsupported/${req.params.reason}`, appState)
|
2017-08-24 23:54:02 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2018-11-20 21:07:47 +01:00
|
|
|
legal: async function(req, res) {
|
|
|
|
const appState = await state(req);
|
|
|
|
res.send(stripEvents(routes().toString('/legal', appState)));
|
2017-08-24 23:54:02 +02:00
|
|
|
},
|
|
|
|
|
2018-11-20 21:07:47 +01:00
|
|
|
notfound: async function(req, res) {
|
|
|
|
const appState = await state(req);
|
|
|
|
res.status(404).send(stripEvents(routes().toString('/404', appState)));
|
2017-08-24 23:54:02 +02:00
|
|
|
}
|
|
|
|
};
|