aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-17 21:03:00 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-17 21:03:00 +0200
commita877d5acc5c52b8667c65f725bbca9a52e40ec48 (patch)
tree20b5dd56f71c7572360807f894e85e0ab729629f /server/middlewares
parent479f229198bdfcfd3a63d02babdddaa8b2209ccb (diff)
downloadPeerTube-a877d5acc5c52b8667c65f725bbca9a52e40ec48.tar.gz
PeerTube-a877d5acc5c52b8667c65f725bbca9a52e40ec48.tar.zst
PeerTube-a877d5acc5c52b8667c65f725bbca9a52e40ec48.zip
Add ability to sort videos list
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/index.js2
-rw-r--r--server/middlewares/reqValidators/index.js2
-rw-r--r--server/middlewares/reqValidators/pagination.js6
-rw-r--r--server/middlewares/reqValidators/sort.js23
-rw-r--r--server/middlewares/sort.js15
5 files changed, 45 insertions, 3 deletions
diff --git a/server/middlewares/index.js b/server/middlewares/index.js
index f0fad3418..35858da2c 100644
--- a/server/middlewares/index.js
+++ b/server/middlewares/index.js
@@ -3,12 +3,14 @@
3const oauth2 = require('./oauth2') 3const oauth2 = require('./oauth2')
4const pagination = require('./pagination') 4const pagination = require('./pagination')
5const reqValidatorsMiddleware = require('./reqValidators') 5const reqValidatorsMiddleware = require('./reqValidators')
6const sort = require('./sort')
6const secureMiddleware = require('./secure') 7const secureMiddleware = require('./secure')
7 8
8const middlewares = { 9const middlewares = {
9 oauth2: oauth2, 10 oauth2: oauth2,
10 pagination: pagination, 11 pagination: pagination,
11 reqValidators: reqValidatorsMiddleware, 12 reqValidators: reqValidatorsMiddleware,
13 sort: sort,
12 secure: secureMiddleware 14 secure: secureMiddleware
13} 15}
14 16
diff --git a/server/middlewares/reqValidators/index.js b/server/middlewares/reqValidators/index.js
index b732a27b6..be68f6a29 100644
--- a/server/middlewares/reqValidators/index.js
+++ b/server/middlewares/reqValidators/index.js
@@ -3,12 +3,14 @@
3const paginationReqValidators = require('./pagination') 3const paginationReqValidators = require('./pagination')
4const podsReqValidators = require('./pods') 4const podsReqValidators = require('./pods')
5const remoteReqValidators = require('./remote') 5const remoteReqValidators = require('./remote')
6const sortReqValidators = require('./sort')
6const videosReqValidators = require('./videos') 7const videosReqValidators = require('./videos')
7 8
8const reqValidators = { 9const reqValidators = {
9 pagination: paginationReqValidators, 10 pagination: paginationReqValidators,
10 pods: podsReqValidators, 11 pods: podsReqValidators,
11 remote: remoteReqValidators, 12 remote: remoteReqValidators,
13 sort: sortReqValidators,
12 videos: videosReqValidators 14 videos: videosReqValidators
13} 15}
14 16
diff --git a/server/middlewares/reqValidators/pagination.js b/server/middlewares/reqValidators/pagination.js
index ca8375396..e598f269a 100644
--- a/server/middlewares/reqValidators/pagination.js
+++ b/server/middlewares/reqValidators/pagination.js
@@ -8,10 +8,10 @@ const reqValidatorsPagination = {
8} 8}
9 9
10function pagination (req, res, next) { 10function pagination (req, res, next) {
11 req.checkParams('start', 'Should have a number start').optional().isInt() 11 req.checkQuery('start', 'Should have a number start').optional().isInt()
12 req.checkParams('count', 'Should have a number count').optional().isInt() 12 req.checkQuery('count', 'Should have a number count').optional().isInt()
13 13
14 logger.debug('Checking pagination parameters', { parameters: req.params }) 14 logger.debug('Checking pagination parameters', { parameters: req.query })
15 15
16 checkErrors(req, res, next) 16 checkErrors(req, res, next)
17} 17}
diff --git a/server/middlewares/reqValidators/sort.js b/server/middlewares/reqValidators/sort.js
new file mode 100644
index 000000000..06e680ef4
--- /dev/null
+++ b/server/middlewares/reqValidators/sort.js
@@ -0,0 +1,23 @@
1'use strict'
2
3const checkErrors = require('./utils').checkErrors
4const constants = require('../../initializers/constants')
5const logger = require('../../helpers/logger')
6
7const reqValidatorsSort = {
8 videosSort: videosSort
9}
10
11function videosSort (req, res, next) {
12 const sortableColumns = constants.SORTABLE_COLUMNS.VIDEOS
13
14 req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns)
15
16 logger.debug('Checking sort parameters', { parameters: req.query })
17
18 checkErrors(req, res, next)
19}
20
21// ---------------------------------------------------------------------------
22
23module.exports = reqValidatorsSort
diff --git a/server/middlewares/sort.js b/server/middlewares/sort.js
new file mode 100644
index 000000000..9f52290a6
--- /dev/null
+++ b/server/middlewares/sort.js
@@ -0,0 +1,15 @@
1'use strict'
2
3const sortMiddleware = {
4 setVideosSort: setVideosSort
5}
6
7function setVideosSort (req, res, next) {
8 if (!req.query.sort) req.query.sort = '-createdDate'
9
10 return next()
11}
12
13// ---------------------------------------------------------------------------
14
15module.exports = sortMiddleware