mirror of
https://github.com/timvisee/send.git
synced 2025-10-04 18:19:17 +02:00
implemented download tokens
This commit is contained in:
parent
87d46f7ef5
commit
81e9d81dab
26 changed files with 271 additions and 126 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue