implemented download tokens

This commit is contained in:
Danny Coates 2020-07-27 11:18:52 -07:00
parent 87d46f7ef5
commit 81e9d81dab
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
26 changed files with 271 additions and 126 deletions

View file

@ -75,5 +75,22 @@ module.exports = {
} else {
res.sendStatus(401);
}
},
dlToken: async function(req, res, next) {
const authHeader = req.header('Authorization');
if (authHeader && /^Bearer\s/i.test(authHeader)) {
const token = authHeader.split(' ')[1];
const id = req.params.id;
req.meta = await storage.metadata(id);
if (!req.meta || req.meta.dead) {
return res.sendStatus(404);
}
req.authorized = await req.meta.verifyDownloadToken(token);
}
if (req.authorized) {
next();
} else {
res.sendStatus(401);
}
}
};