This commit is contained in:
2024-01-06 15:10:39 -05:00
parent abc547c642
commit 7fad640cca
7 changed files with 252 additions and 97 deletions

View File

@ -5,7 +5,11 @@ const {Torrent} = require('>/models');
router.get('/', async function(req, res, next){
try{
res.json({results: await Torrent.findAll({where:{added_by: req.user.username}})});
res.json({results: await Torrent.findAll({
where:{added_by: req.query.username || req.user.username},
limit: req.query.limit,
offset: req.query.offset
})});
}catch(error){
next(error);
}
@ -39,4 +43,36 @@ router.get("/:id", async function(req, res, next){
}
});
router.delete("/:id", async function(req, res, next){
try{
let torrent = await Torrent.findByPk(req.params.id);
res.json({result: torrent, activity: await torrent.destroy()});
}catch(error){
next(error);
}
});
router.post("/:id/stop", async function(req, res, next){
try{
let torrent = await Torrent.findByPk(req.params.id);
res.json({result: torrent, activity: await torrent.stop()});
}catch(error){
next(error);
}
});
router.post("/:id/start", async function(req, res, next){
try{
let torrent = await Torrent.findByPk(req.params.id);
res.json({result: torrent, activity: await torrent.start()});
}catch(error){
next(error);
}
});
module.exports = router;