From 68ce3ae021c9bc11b155044df6d23ba60e91eee4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 21 May 2016 19:30:22 +0200 Subject: Add total results field and wrap videos in data field when listing videos --- server/controllers/api/v1/videos.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js index e903cbcf4..f7aeea453 100644 --- a/server/controllers/api/v1/videos.js +++ b/server/controllers/api/v1/videos.js @@ -62,7 +62,7 @@ router.post('/', ) router.get('/:id', reqValidatorVideos.videosGet, - getVideos + getVideo ) router.delete('/:id', oAuth2.authenticate, @@ -165,7 +165,7 @@ function addVideo (req, res, next) { }) } -function getVideos (req, res, next) { +function getVideo (req, res, next) { Videos.get(req.params.id, function (err, videoObj) { if (err) return next(err) @@ -179,10 +179,10 @@ function getVideos (req, res, next) { } function listVideos (req, res, next) { - Videos.list(req.query.start, req.query.count, req.query.sort, function (err, videosList) { + Videos.list(req.query.start, req.query.count, req.query.sort, function (err, videosList, totalVideos) { if (err) return next(err) - res.json(getFormatedVideos(videosList)) + res.json(getFormatedVideos(videosList, totalVideos)) }) } @@ -237,10 +237,10 @@ function removeVideo (req, res, next) { } function searchVideos (req, res, next) { - Videos.search(req.params.name, req.query.start, req.query.count, req.query.sort, function (err, videosList) { + Videos.search(req.params.name, req.query.start, req.query.count, req.query.sort, function (err, videosList, totalVideos) { if (err) return next(err) - res.json(getFormatedVideos(videosList)) + res.json(getFormatedVideos(videosList, totalVideos)) }) } @@ -263,14 +263,17 @@ function getFormatedVideo (videoObj) { return formatedVideo } -function getFormatedVideos (videosObj) { +function getFormatedVideos (videosObj, totalVideos) { const formatedVideos = [] videosObj.forEach(function (videoObj) { formatedVideos.push(getFormatedVideo(videoObj)) }) - return formatedVideos + return { + total: totalVideos, + data: formatedVideos + } } // Maybe the torrent is not seeded, but we catch the error to don't stop the removing process -- cgit v1.2.3