aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/remote/index.js13
-rw-r--r--server/middlewares/validators/remote/signature.js (renamed from server/middlewares/validators/remote.js)17
-rw-r--r--server/middlewares/validators/remote/videos.js20
-rw-r--r--server/middlewares/validators/sort.js23
-rw-r--r--server/middlewares/validators/videos.js15
5 files changed, 67 insertions, 21 deletions
diff --git a/server/middlewares/validators/remote/index.js b/server/middlewares/validators/remote/index.js
new file mode 100644
index 000000000..022a2fe50
--- /dev/null
+++ b/server/middlewares/validators/remote/index.js
@@ -0,0 +1,13 @@
1'use strict'
2
3const remoteSignatureValidators = require('./signature')
4const remoteVideosValidators = require('./videos')
5
6const validators = {
7 signature: remoteSignatureValidators,
8 videos: remoteVideosValidators
9}
10
11// ---------------------------------------------------------------------------
12
13module.exports = validators
diff --git a/server/middlewares/validators/remote.js b/server/middlewares/validators/remote/signature.js
index 858d193cc..5880a2c2c 100644
--- a/server/middlewares/validators/remote.js
+++ b/server/middlewares/validators/remote/signature.js
@@ -1,21 +1,12 @@
1'use strict' 1'use strict'
2 2
3const checkErrors = require('./utils').checkErrors 3const checkErrors = require('../utils').checkErrors
4const logger = require('../../helpers/logger') 4const logger = require('../../../helpers/logger')
5 5
6const validatorsRemote = { 6const validatorsRemoteSignature = {
7 remoteVideos,
8 signature 7 signature
9} 8}
10 9
11function remoteVideos (req, res, next) {
12 req.checkBody('data').isEachRemoteVideosValid()
13
14 logger.debug('Checking remoteVideos parameters', { parameters: req.body })
15
16 checkErrors(req, res, next)
17}
18
19function signature (req, res, next) { 10function signature (req, res, next) {
20 req.checkBody('signature.host', 'Should have a signature host').isURL() 11 req.checkBody('signature.host', 'Should have a signature host').isURL()
21 req.checkBody('signature.signature', 'Should have a signature').notEmpty() 12 req.checkBody('signature.signature', 'Should have a signature').notEmpty()
@@ -27,4 +18,4 @@ function signature (req, res, next) {
27 18
28// --------------------------------------------------------------------------- 19// ---------------------------------------------------------------------------
29 20
30module.exports = validatorsRemote 21module.exports = validatorsRemoteSignature
diff --git a/server/middlewares/validators/remote/videos.js b/server/middlewares/validators/remote/videos.js
new file mode 100644
index 000000000..cf9925b6c
--- /dev/null
+++ b/server/middlewares/validators/remote/videos.js
@@ -0,0 +1,20 @@
1'use strict'
2
3const checkErrors = require('../utils').checkErrors
4const logger = require('../../../helpers/logger')
5
6const validatorsRemoteVideos = {
7 remoteVideos
8}
9
10function remoteVideos (req, res, next) {
11 req.checkBody('data').isEachRemoteRequestVideosValid()
12
13 logger.debug('Checking remoteVideos parameters', { parameters: req.body })
14
15 checkErrors(req, res, next)
16}
17
18// ---------------------------------------------------------------------------
19
20module.exports = validatorsRemoteVideos
diff --git a/server/middlewares/validators/sort.js b/server/middlewares/validators/sort.js
index 431d3fffd..b7eec0316 100644
--- a/server/middlewares/validators/sort.js
+++ b/server/middlewares/validators/sort.js
@@ -6,29 +6,38 @@ const logger = require('../../helpers/logger')
6 6
7const validatorsSort = { 7const validatorsSort = {
8 usersSort, 8 usersSort,
9 videoAbusesSort,
9 videosSort 10 videosSort
10} 11}
11 12
12function usersSort (req, res, next) { 13function usersSort (req, res, next) {
13 const sortableColumns = constants.SORTABLE_COLUMNS.USERS 14 const sortableColumns = constants.SORTABLE_COLUMNS.USERS
14 15
15 req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns) 16 checkSort(req, res, next, sortableColumns)
17}
16 18
17 logger.debug('Checking sort parameters', { parameters: req.query }) 19function videoAbusesSort (req, res, next) {
20 const sortableColumns = constants.SORTABLE_COLUMNS.VIDEO_ABUSES
18 21
19 checkErrors(req, res, next) 22 checkSort(req, res, next, sortableColumns)
20} 23}
21 24
22function videosSort (req, res, next) { 25function videosSort (req, res, next) {
23 const sortableColumns = constants.SORTABLE_COLUMNS.VIDEOS 26 const sortableColumns = constants.SORTABLE_COLUMNS.VIDEOS
24 27
28 checkSort(req, res, next, sortableColumns)
29}
30
31// ---------------------------------------------------------------------------
32
33module.exports = validatorsSort
34
35// ---------------------------------------------------------------------------
36
37function checkSort (req, res, next, sortableColumns) {
25 req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns) 38 req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns)
26 39
27 logger.debug('Checking sort parameters', { parameters: req.query }) 40 logger.debug('Checking sort parameters', { parameters: req.query })
28 41
29 checkErrors(req, res, next) 42 checkErrors(req, res, next)
30} 43}
31
32// ---------------------------------------------------------------------------
33
34module.exports = validatorsSort
diff --git a/server/middlewares/validators/videos.js b/server/middlewares/validators/videos.js
index 295ed05fa..ff18a99c2 100644
--- a/server/middlewares/validators/videos.js
+++ b/server/middlewares/validators/videos.js
@@ -11,7 +11,9 @@ const validatorsVideos = {
11 videosUpdate, 11 videosUpdate,
12 videosGet, 12 videosGet,
13 videosRemove, 13 videosRemove,
14 videosSearch 14 videosSearch,
15
16 videoAbuseReport
15} 17}
16 18
17function videosAdd (req, res, next) { 19function videosAdd (req, res, next) {
@@ -97,6 +99,17 @@ function videosSearch (req, res, next) {
97 checkErrors(req, res, next) 99 checkErrors(req, res, next)
98} 100}
99 101
102function videoAbuseReport (req, res, next) {
103 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
104 req.checkBody('reason', 'Should have a valid reason').isVideoAbuseReasonValid()
105
106 logger.debug('Checking videoAbuseReport parameters', { parameters: req.body })
107
108 checkErrors(req, res, function () {
109 checkVideoExists(req.params.id, res, next)
110 })
111}
112
100// --------------------------------------------------------------------------- 113// ---------------------------------------------------------------------------
101 114
102module.exports = validatorsVideos 115module.exports = validatorsVideos