This commit is contained in:
2024-01-07 00:30:53 -05:00
parent 7fad640cca
commit 1c7e2e794e
5 changed files with 548 additions and 413 deletions

View File

@ -8,7 +8,10 @@ router.get('/', async function(req, res, next){
res.json({results: await Torrent.findAll({
where:{added_by: req.query.username || req.user.username},
limit: req.query.limit,
offset: req.query.offset
offset: req.query.offset,
order: [
['createdAt', 'DESC'],
],
})});
}catch(error){
next(error);
@ -23,6 +26,14 @@ router.post("/", async function(req, res, next){
}
});
router.post("/:hashString", async function(req, res, next){
try{
res.json(await Torrent.migrate(req.params.hashString, req.user.username))
}catch(error){
next(error);
}
});
router.get('/server', async function(req, res, next){
try{
res.json(await Torrent.trClient.sessionStats())
@ -31,9 +42,9 @@ router.get('/server', async function(req, res, next){
}
});
router.get("/:id", async function(req, res, next){
router.get("/:hashString", async function(req, res, next){
try{
let torrent = await Torrent.findByPk(req.params.id);
let torrent = await Torrent.findByPk(req.params.hashString);
if('latest' in req.query){
torrent = await torrent.getTorrentData();
}
@ -43,9 +54,9 @@ router.get("/:id", async function(req, res, next){
}
});
router.delete("/:id", async function(req, res, next){
router.delete("/:hashString", async function(req, res, next){
try{
let torrent = await Torrent.findByPk(req.params.id);
let torrent = await Torrent.findByPk(req.params.hashString);
res.json({result: torrent, activity: await torrent.destroy()});
}catch(error){
@ -53,9 +64,9 @@ router.delete("/:id", async function(req, res, next){
}
});
router.post("/:id/stop", async function(req, res, next){
router.post("/:hashString/stop", async function(req, res, next){
try{
let torrent = await Torrent.findByPk(req.params.id);
let torrent = await Torrent.findByPk(req.params.hashString);
res.json({result: torrent, activity: await torrent.stop()});
}catch(error){
@ -63,9 +74,9 @@ router.post("/:id/stop", async function(req, res, next){
}
});
router.post("/:id/start", async function(req, res, next){
router.post("/:hashString/start", async function(req, res, next){
try{
let torrent = await Torrent.findByPk(req.params.id);
let torrent = await Torrent.findByPk(req.params.hashString);
res.json({result: torrent, activity: await torrent.start()});
}catch(error){