aboutsummaryrefslogtreecommitdiffhomepage
path: root/middlewares/reqValidators/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'middlewares/reqValidators/videos.js')
-rw-r--r--middlewares/reqValidators/videos.js106
1 files changed, 52 insertions, 54 deletions
diff --git a/middlewares/reqValidators/videos.js b/middlewares/reqValidators/videos.js
index f7bd24658..4e5f4391f 100644
--- a/middlewares/reqValidators/videos.js
+++ b/middlewares/reqValidators/videos.js
@@ -1,76 +1,74 @@
1;(function () { 1'use strict'
2 'use strict'
3 2
4 var checkErrors = require('./utils').checkErrors 3var checkErrors = require('./utils').checkErrors
5 var logger = require('../../helpers/logger') 4var logger = require('../../helpers/logger')
6 var Videos = require('../../models/videos') 5var Videos = require('../../models/videos')
7 6
8 var reqValidatorsVideos = { 7var reqValidatorsVideos = {
9 videosAdd: videosAdd, 8 videosAdd: videosAdd,
10 videosGet: videosGet, 9 videosGet: videosGet,
11 videosRemove: videosRemove, 10 videosRemove: videosRemove,
12 videosSearch: videosSearch 11 videosSearch: videosSearch
13 } 12}
14 13
15 function videosAdd (req, res, next) { 14function videosAdd (req, res, next) {
16 req.checkFiles('input_video[0].originalname', 'Should have an input video').notEmpty() 15 req.checkFiles('input_video[0].originalname', 'Should have an input video').notEmpty()
17 req.checkFiles('input_video[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) 16 req.checkFiles('input_video[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i)
18 req.checkBody('name', 'Should have a name').isLength(1, 50) 17 req.checkBody('name', 'Should have a name').isLength(1, 50)
19 req.checkBody('description', 'Should have a description').isLength(1, 250) 18 req.checkBody('description', 'Should have a description').isLength(1, 250)
20 19
21 logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) 20 logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
22 21
23 checkErrors(req, res, next) 22 checkErrors(req, res, next)
24 } 23}
25 24
26 function videosGet (req, res, next) { 25function videosGet (req, res, next) {
27 req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId() 26 req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
28 27
29 logger.debug('Checking videosGet parameters', { parameters: req.params }) 28 logger.debug('Checking videosGet parameters', { parameters: req.params })
30 29
31 checkErrors(req, res, function () { 30 checkErrors(req, res, function () {
32 Videos.getVideoState(req.params.id, function (err, state) { 31 Videos.getVideoState(req.params.id, function (err, state) {
33 if (err) { 32 if (err) {
34 logger.error('Error in videosGet request validator.', { error: err }) 33 logger.error('Error in videosGet request validator.', { error: err })
35 res.sendStatus(500) 34 res.sendStatus(500)
36 } 35 }
37 36
38 if (state.exist === false) return res.status(404).send('Video not found') 37 if (state.exist === false) return res.status(404).send('Video not found')
39 38
40 next() 39 next()
41 })
42 }) 40 })
43 } 41 })
42}
44 43
45 function videosRemove (req, res, next) { 44function videosRemove (req, res, next) {
46 req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId() 45 req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
47 46
48 logger.debug('Checking videosRemove parameters', { parameters: req.params }) 47 logger.debug('Checking videosRemove parameters', { parameters: req.params })
49 48
50 checkErrors(req, res, function () { 49 checkErrors(req, res, function () {
51 Videos.getVideoState(req.params.id, function (err, state) { 50 Videos.getVideoState(req.params.id, function (err, state) {
52 if (err) { 51 if (err) {
53 logger.error('Error in videosRemove request validator.', { error: err }) 52 logger.error('Error in videosRemove request validator.', { error: err })
54 res.sendStatus(500) 53 res.sendStatus(500)
55 } 54 }
56 55
57 if (state.exist === false) return res.status(404).send('Video not found') 56 if (state.exist === false) return res.status(404).send('Video not found')
58 else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod') 57 else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod')
59 58
60 next() 59 next()
61 })
62 }) 60 })
63 } 61 })
62}
64 63
65 function videosSearch (req, res, next) { 64function videosSearch (req, res, next) {
66 req.checkParams('name', 'Should have a name').notEmpty() 65 req.checkParams('name', 'Should have a name').notEmpty()
67 66
68 logger.debug('Checking videosSearch parameters', { parameters: req.params }) 67 logger.debug('Checking videosSearch parameters', { parameters: req.params })
69 68
70 checkErrors(req, res, next) 69 checkErrors(req, res, next)
71 } 70}
72 71
73 // --------------------------------------------------------------------------- 72// ---------------------------------------------------------------------------
74 73
75 module.exports = reqValidatorsVideos 74module.exports = reqValidatorsVideos
76})()