added /api/info/:id route
This commit is contained in:
parent
81534d2c13
commit
97ad674be2
20 changed files with 74 additions and 38 deletions
|
@ -95,6 +95,7 @@ module.exports = function(app) {
|
|||
app.post('/api/delete/:id', require('./delete'));
|
||||
app.post('/api/password/:id', require('./password'));
|
||||
app.post('/api/params/:id', require('./params'));
|
||||
app.post('/api/info/:id', require('./info'));
|
||||
|
||||
app.get('/__version__', function(req, res) {
|
||||
res.sendFile(require.resolve('../../dist/version.json'));
|
||||
|
|
31
server/routes/info.js
Normal file
31
server/routes/info.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
const storage = require('../storage');
|
||||
|
||||
function validateID(route_id) {
|
||||
return route_id.match(/^[0-9a-fA-F]{10}$/) !== null;
|
||||
}
|
||||
|
||||
module.exports = async function(req, res) {
|
||||
const id = req.params.id;
|
||||
if (!validateID(id)) {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
const ownerToken = req.body.owner_token;
|
||||
if (!ownerToken) {
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
|
||||
try {
|
||||
const meta = await storage.metadata(id);
|
||||
if (meta.owner !== ownerToken) {
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
const ttl = await storage.ttl(id);
|
||||
return res.send({
|
||||
dlimit: meta.dlimit,
|
||||
dtotal: meta.dl,
|
||||
ttl
|
||||
});
|
||||
} catch (e) {
|
||||
res.sendStatus(404);
|
||||
}
|
||||
};
|
|
@ -29,8 +29,7 @@ module.exports = async function(req, res) {
|
|||
const ttl = await storage.ttl(id);
|
||||
res.send({
|
||||
metadata: meta.metadata,
|
||||
dtotal: +meta.dl,
|
||||
dlimit: +meta.dlimit,
|
||||
finalDownload: +meta.dl + 1 === +meta.dlimit,
|
||||
size,
|
||||
ttl
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue