]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/reqValidators/videos.js
3 var checkErrors
= require('./utils').checkErrors
4 var logger
= require('../../helpers/logger')
5 var Videos
= require('../../models/videos')
7 var reqValidatorsVideos
= {
10 videosRemove: videosRemove
,
11 videosSearch: videosSearch
14 function videosAdd (req
, res
, next
) {
15 req
.checkFiles('input_video[0].originalname', 'Should have an input video').notEmpty()
16 req
.checkFiles('input_video[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i)
17 req
.checkBody('name', 'Should have a name').isLength(1, 50)
18 req
.checkBody('description', 'Should have a description').isLength(1, 250)
20 logger
.debug('Checking videosAdd parameters', { parameters: req
.body
, files: req
.files
})
22 checkErrors(req
, res
, next
)
25 function videosGet (req
, res
, next
) {
26 req
.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
28 logger
.debug('Checking videosGet parameters', { parameters: req
.params
})
30 checkErrors(req
, res
, function () {
31 Videos
.getVideoState(req
.params
.id
, function (err
, state
) {
33 logger
.error('Error in videosGet request validator.', { error: err
})
37 if (state
.exist
=== false) return res
.status(404).send('Video not found')
44 function videosRemove (req
, res
, next
) {
45 req
.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
47 logger
.debug('Checking videosRemove parameters', { parameters: req
.params
})
49 checkErrors(req
, res
, function () {
50 Videos
.getVideoState(req
.params
.id
, function (err
, state
) {
52 logger
.error('Error in videosRemove request validator.', { error: err
})
56 if (state
.exist
=== false) return res
.status(404).send('Video not found')
57 else if (state
.owned
=== false) return res
.status(403).send('Cannot remove video of another pod')
64 function videosSearch (req
, res
, next
) {
65 req
.checkParams('name', 'Should have a name').notEmpty()
67 logger
.debug('Checking videosSearch parameters', { parameters: req
.params
})
69 checkErrors(req
, res
, next
)
72 // ---------------------------------------------------------------------------
74 module
.exports
= reqValidatorsVideos