aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/v1
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-13 18:10:46 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-13 18:10:46 +0200
commitfbf1134e3e6b386c9ec5a3946c61f3faf84397fb (patch)
tree9071ea72c86e83bb07d8ec681a54daff2e0eb7b9 /server/controllers/api/v1
parentf67e976fdccbfe6432c1176148d194c980a5585a (diff)
downloadPeerTube-fbf1134e3e6b386c9ec5a3946c61f3faf84397fb.tar.gz
PeerTube-fbf1134e3e6b386c9ec5a3946c61f3faf84397fb.tar.zst
PeerTube-fbf1134e3e6b386c9ec5a3946c61f3faf84397fb.zip
Introduce paginations in videos listing
Diffstat (limited to 'server/controllers/api/v1')
-rw-r--r--server/controllers/api/v1/videos.js40
1 files changed, 32 insertions, 8 deletions
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js
index b6e3de08f..0e058836e 100644
--- a/server/controllers/api/v1/videos.js
+++ b/server/controllers/api/v1/videos.js
@@ -11,7 +11,10 @@ const logger = require('../../../helpers/logger')
11const friends = require('../../../lib/friends') 11const friends = require('../../../lib/friends')
12const middlewares = require('../../../middlewares') 12const middlewares = require('../../../middlewares')
13const oAuth2 = middlewares.oauth2 13const oAuth2 = middlewares.oauth2
14const reqValidator = middlewares.reqValidators.videos 14const pagination = middlewares.pagination
15const reqValidator = middlewares.reqValidators
16const reqValidatorPagination = reqValidator.pagination
17const reqValidatorVideos = reqValidator.videos
15const utils = require('../../../helpers/utils') 18const utils = require('../../../helpers/utils')
16const Videos = require('../../../models/videos') // model 19const Videos = require('../../../models/videos') // model
17const videos = require('../../../lib/videos') 20const videos = require('../../../lib/videos')
@@ -41,11 +44,32 @@ const storage = multer.diskStorage({
41const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) 44const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
42const thumbnailsDir = path.join(__dirname, '..', '..', '..', '..', config.get('storage.thumbnails')) 45const thumbnailsDir = path.join(__dirname, '..', '..', '..', '..', config.get('storage.thumbnails'))
43 46
44router.get('/', listVideos) 47router.get('/',
45router.post('/', oAuth2.authenticate, reqFiles, reqValidator.videosAdd, addVideo) 48 reqValidatorPagination.pagination,
46router.get('/:id', reqValidator.videosGet, getVideos) 49 pagination.setPagination,
47router.delete('/:id', oAuth2.authenticate, reqValidator.videosRemove, removeVideo) 50 listVideos
48router.get('/search/:name', reqValidator.videosSearch, searchVideos) 51)
52router.post('/',
53 oAuth2.authenticate,
54 reqFiles,
55 reqValidatorVideos.videosAdd,
56 addVideo
57)
58router.get('/:id',
59 reqValidatorVideos.videosGet,
60 getVideos
61)
62router.delete('/:id',
63 oAuth2.authenticate,
64 reqValidatorVideos.videosRemove,
65 removeVideo
66)
67router.get('/search/:name',
68 reqValidatorVideos.videosSearch,
69 reqValidatorPagination.pagination,
70 pagination.setPagination,
71 searchVideos
72)
49 73
50// --------------------------------------------------------------------------- 74// ---------------------------------------------------------------------------
51 75
@@ -129,7 +153,7 @@ function getVideos (req, res, next) {
129} 153}
130 154
131function listVideos (req, res, next) { 155function listVideos (req, res, next) {
132 Videos.list(function (err, videosList) { 156 Videos.list(req.query.start, req.query.count, function (err, videosList) {
133 if (err) return next(err) 157 if (err) return next(err)
134 158
135 res.json(getFormatedVideos(videosList)) 159 res.json(getFormatedVideos(videosList))
@@ -162,7 +186,7 @@ function removeVideo (req, res, next) {
162} 186}
163 187
164function searchVideos (req, res, next) { 188function searchVideos (req, res, next) {
165 Videos.search(req.params.name, function (err, videosList) { 189 Videos.search(req.params.name, req.query.start, req.query.count, function (err, videosList) {
166 if (err) return next(err) 190 if (err) return next(err)
167 191
168 res.json(getFormatedVideos(videosList)) 192 res.json(getFormatedVideos(videosList))