diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-05-21 19:30:22 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-05-21 19:30:22 +0200 |
commit | 68ce3ae021c9bc11b155044df6d23ba60e91eee4 (patch) | |
tree | 7cb162a57994f96703ef8387babdeda17d3b58bc /server/controllers/api/v1 | |
parent | 501bc6c2b186f6a724a5b619d15aa44791f13995 (diff) | |
download | PeerTube-68ce3ae021c9bc11b155044df6d23ba60e91eee4.tar.gz PeerTube-68ce3ae021c9bc11b155044df6d23ba60e91eee4.tar.zst PeerTube-68ce3ae021c9bc11b155044df6d23ba60e91eee4.zip |
Add total results field and wrap videos in data field when listing
videos
Diffstat (limited to 'server/controllers/api/v1')
-rw-r--r-- | server/controllers/api/v1/videos.js | 19 |
1 files changed, 11 insertions, 8 deletions
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('/', | |||
62 | ) | 62 | ) |
63 | router.get('/:id', | 63 | router.get('/:id', |
64 | reqValidatorVideos.videosGet, | 64 | reqValidatorVideos.videosGet, |
65 | getVideos | 65 | getVideo |
66 | ) | 66 | ) |
67 | router.delete('/:id', | 67 | router.delete('/:id', |
68 | oAuth2.authenticate, | 68 | oAuth2.authenticate, |
@@ -165,7 +165,7 @@ function addVideo (req, res, next) { | |||
165 | }) | 165 | }) |
166 | } | 166 | } |
167 | 167 | ||
168 | function getVideos (req, res, next) { | 168 | function getVideo (req, res, next) { |
169 | Videos.get(req.params.id, function (err, videoObj) { | 169 | Videos.get(req.params.id, function (err, videoObj) { |
170 | if (err) return next(err) | 170 | if (err) return next(err) |
171 | 171 | ||
@@ -179,10 +179,10 @@ function getVideos (req, res, next) { | |||
179 | } | 179 | } |
180 | 180 | ||
181 | function listVideos (req, res, next) { | 181 | function listVideos (req, res, next) { |
182 | Videos.list(req.query.start, req.query.count, req.query.sort, function (err, videosList) { | 182 | Videos.list(req.query.start, req.query.count, req.query.sort, function (err, videosList, totalVideos) { |
183 | if (err) return next(err) | 183 | if (err) return next(err) |
184 | 184 | ||
185 | res.json(getFormatedVideos(videosList)) | 185 | res.json(getFormatedVideos(videosList, totalVideos)) |
186 | }) | 186 | }) |
187 | } | 187 | } |
188 | 188 | ||
@@ -237,10 +237,10 @@ function removeVideo (req, res, next) { | |||
237 | } | 237 | } |
238 | 238 | ||
239 | function searchVideos (req, res, next) { | 239 | function searchVideos (req, res, next) { |
240 | Videos.search(req.params.name, req.query.start, req.query.count, req.query.sort, function (err, videosList) { | 240 | Videos.search(req.params.name, req.query.start, req.query.count, req.query.sort, function (err, videosList, totalVideos) { |
241 | if (err) return next(err) | 241 | if (err) return next(err) |
242 | 242 | ||
243 | res.json(getFormatedVideos(videosList)) | 243 | res.json(getFormatedVideos(videosList, totalVideos)) |
244 | }) | 244 | }) |
245 | } | 245 | } |
246 | 246 | ||
@@ -263,14 +263,17 @@ function getFormatedVideo (videoObj) { | |||
263 | return formatedVideo | 263 | return formatedVideo |
264 | } | 264 | } |
265 | 265 | ||
266 | function getFormatedVideos (videosObj) { | 266 | function getFormatedVideos (videosObj, totalVideos) { |
267 | const formatedVideos = [] | 267 | const formatedVideos = [] |
268 | 268 | ||
269 | videosObj.forEach(function (videoObj) { | 269 | videosObj.forEach(function (videoObj) { |
270 | formatedVideos.push(getFormatedVideo(videoObj)) | 270 | formatedVideos.push(getFormatedVideo(videoObj)) |
271 | }) | 271 | }) |
272 | 272 | ||
273 | return formatedVideos | 273 | return { |
274 | total: totalVideos, | ||
275 | data: formatedVideos | ||
276 | } | ||
274 | } | 277 | } |
275 | 278 | ||
276 | // Maybe the torrent is not seeded, but we catch the error to don't stop the removing process | 279 | // Maybe the torrent is not seeded, but we catch the error to don't stop the removing process |