diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-05-13 18:10:46 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-05-13 18:10:46 +0200 |
commit | fbf1134e3e6b386c9ec5a3946c61f3faf84397fb (patch) | |
tree | 9071ea72c86e83bb07d8ec681a54daff2e0eb7b9 /server/controllers | |
parent | f67e976fdccbfe6432c1176148d194c980a5585a (diff) | |
download | PeerTube-fbf1134e3e6b386c9ec5a3946c61f3faf84397fb.tar.gz PeerTube-fbf1134e3e6b386c9ec5a3946c61f3faf84397fb.tar.zst PeerTube-fbf1134e3e6b386c9ec5a3946c61f3faf84397fb.zip |
Introduce paginations in videos listing
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/v1/videos.js | 40 |
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') | |||
11 | const friends = require('../../../lib/friends') | 11 | const friends = require('../../../lib/friends') |
12 | const middlewares = require('../../../middlewares') | 12 | const middlewares = require('../../../middlewares') |
13 | const oAuth2 = middlewares.oauth2 | 13 | const oAuth2 = middlewares.oauth2 |
14 | const reqValidator = middlewares.reqValidators.videos | 14 | const pagination = middlewares.pagination |
15 | const reqValidator = middlewares.reqValidators | ||
16 | const reqValidatorPagination = reqValidator.pagination | ||
17 | const reqValidatorVideos = reqValidator.videos | ||
15 | const utils = require('../../../helpers/utils') | 18 | const utils = require('../../../helpers/utils') |
16 | const Videos = require('../../../models/videos') // model | 19 | const Videos = require('../../../models/videos') // model |
17 | const videos = require('../../../lib/videos') | 20 | const videos = require('../../../lib/videos') |
@@ -41,11 +44,32 @@ const storage = multer.diskStorage({ | |||
41 | const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) | 44 | const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) |
42 | const thumbnailsDir = path.join(__dirname, '..', '..', '..', '..', config.get('storage.thumbnails')) | 45 | const thumbnailsDir = path.join(__dirname, '..', '..', '..', '..', config.get('storage.thumbnails')) |
43 | 46 | ||
44 | router.get('/', listVideos) | 47 | router.get('/', |
45 | router.post('/', oAuth2.authenticate, reqFiles, reqValidator.videosAdd, addVideo) | 48 | reqValidatorPagination.pagination, |
46 | router.get('/:id', reqValidator.videosGet, getVideos) | 49 | pagination.setPagination, |
47 | router.delete('/:id', oAuth2.authenticate, reqValidator.videosRemove, removeVideo) | 50 | listVideos |
48 | router.get('/search/:name', reqValidator.videosSearch, searchVideos) | 51 | ) |
52 | router.post('/', | ||
53 | oAuth2.authenticate, | ||
54 | reqFiles, | ||
55 | reqValidatorVideos.videosAdd, | ||
56 | addVideo | ||
57 | ) | ||
58 | router.get('/:id', | ||
59 | reqValidatorVideos.videosGet, | ||
60 | getVideos | ||
61 | ) | ||
62 | router.delete('/:id', | ||
63 | oAuth2.authenticate, | ||
64 | reqValidatorVideos.videosRemove, | ||
65 | removeVideo | ||
66 | ) | ||
67 | router.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 | ||
131 | function listVideos (req, res, next) { | 155 | function 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 | ||
164 | function searchVideos (req, res, next) { | 188 | function 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)) |