diff options
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/videos.js | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/server/middlewares/validators/videos.js b/server/middlewares/validators/videos.js index 7e90ca047..09a188c76 100644 --- a/server/middlewares/validators/videos.js +++ b/server/middlewares/validators/videos.js | |||
@@ -8,6 +8,7 @@ const logger = require('../../helpers/logger') | |||
8 | 8 | ||
9 | const validatorsVideos = { | 9 | const validatorsVideos = { |
10 | videosAdd, | 10 | videosAdd, |
11 | videosUpdate, | ||
11 | videosGet, | 12 | videosGet, |
12 | videosRemove, | 13 | videosRemove, |
13 | videosSearch | 14 | videosSearch |
@@ -41,22 +42,26 @@ function videosAdd (req, res, next) { | |||
41 | }) | 42 | }) |
42 | } | 43 | } |
43 | 44 | ||
44 | function videosGet (req, res, next) { | 45 | function videosUpdate (req, res, next) { |
45 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 46 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) |
47 | req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid() | ||
48 | req.checkBody('description', 'Should have a valid description').optional().isVideoDescriptionValid() | ||
49 | req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid() | ||
46 | 50 | ||
47 | logger.debug('Checking videosGet parameters', { parameters: req.params }) | 51 | logger.debug('Checking videosUpdate parameters', { parameters: req.body }) |
48 | 52 | ||
49 | checkErrors(req, res, function () { | 53 | checkErrors(req, res, function () { |
50 | db.Video.load(req.params.id, function (err, video) { | 54 | checkVideoExists(req.params.id, res, next) |
51 | if (err) { | 55 | }) |
52 | logger.error('Error in videosGet request validator.', { error: err }) | 56 | } |
53 | return res.sendStatus(500) | ||
54 | } | ||
55 | 57 | ||
56 | if (!video) return res.status(404).send('Video not found') | 58 | function videosGet (req, res, next) { |
59 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | ||
57 | 60 | ||
58 | next() | 61 | logger.debug('Checking videosGet parameters', { parameters: req.params }) |
59 | }) | 62 | |
63 | checkErrors(req, res, function () { | ||
64 | checkVideoExists(req.params.id, res, next) | ||
60 | }) | 65 | }) |
61 | } | 66 | } |
62 | 67 | ||
@@ -94,3 +99,19 @@ function videosSearch (req, res, next) { | |||
94 | // --------------------------------------------------------------------------- | 99 | // --------------------------------------------------------------------------- |
95 | 100 | ||
96 | module.exports = validatorsVideos | 101 | module.exports = validatorsVideos |
102 | |||
103 | // --------------------------------------------------------------------------- | ||
104 | |||
105 | function checkVideoExists (id, res, callback) { | ||
106 | db.Video.loadAndPopulateAuthorAndPodAndTags(id, function (err, video) { | ||
107 | if (err) { | ||
108 | logger.error('Error in video request validator.', { error: err }) | ||
109 | return res.sendStatus(500) | ||
110 | } | ||
111 | |||
112 | if (!video) return res.status(404).send('Video not found') | ||
113 | |||
114 | res.locals.video = video | ||
115 | callback() | ||
116 | }) | ||
117 | } | ||