forked from mozilla/send
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpages.js
61 lines (54 loc) · 1.62 KB
/
pages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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: async function(req, res) {
const appState = await state(req);
res.send(stripEvents(routes().toString('/blank', appState)));
},
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;
const appState = await state(req);
try {
const { nonce, pwd } = await storage.metadata(id);
res.set('WWW-Authenticate', `send-v1 ${nonce}`);
res.send(
stripEvents(
routes().toString(
`/download/${id}`,
Object.assign(appState, {
downloadMetadata: { nonce, pwd }
})
)
)
);
} catch (e) {
next();
}
},
unsupported: async function(req, res) {
const appState = await state(req);
res.send(
stripEvents(
routes().toString(`/unsupported/${req.params.reason}`, appState)
)
);
},
legal: async function(req, res) {
const appState = await state(req);
res.send(stripEvents(routes().toString('/legal', appState)));
},
notfound: async function(req, res) {
const appState = await state(req);
res.status(404).send(stripEvents(routes().toString('/404', appState)));
}
};