]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/reqValidators/videos.js
3 const checkErrors
= require('./utils').checkErrors
4 const logger
= require('../../helpers/logger')
5 const videos
= require('../../lib/videos')
6 const Videos
= require('../../models/videos')
8 const reqValidatorsVideos
= {
11 videosRemove: videosRemove
,
12 videosSearch: videosSearch
15 function videosAdd (req
, res
, next
) {
16 req
.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty()
17 req
.checkFiles('videofile[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)
19 req
.checkBody('description', 'Should have a description').isLength(1, 250)
21 logger
.debug('Checking videosAdd parameters', { parameters: req
.body
, files: req
.files
})
23 checkErrors(req
, res
, next
)
26 function videosGet (req
, res
, next
) {
27 req
.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
29 logger
.debug('Checking videosGet parameters', { parameters: req
.params
})
31 checkErrors(req
, res
, function () {
32 Videos
.get(req
.params
.id
, function (err
, video
) {
34 logger
.error('Error in videosGet request validator.', { error: err
})
38 const state
= videos
.getVideoState(video
)
39 if (state
.exist
=== false) return res
.status(404).send('Video not found')
46 function videosRemove (req
, res
, next
) {
47 req
.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
49 logger
.debug('Checking videosRemove parameters', { parameters: req
.params
})
51 checkErrors(req
, res
, function () {
52 Videos
.get(req
.params
.id
, function (err
, video
) {
54 logger
.error('Error in videosRemove request validator.', { error: err
})
58 const state
= videos
.getVideoState(video
)
59 if (state
.exist
=== false) return res
.status(404).send('Video not found')
60 else if (state
.owned
=== false) return res
.status(403).send('Cannot remove video of another pod')
67 function videosSearch (req
, res
, next
) {
68 req
.checkParams('name', 'Should have a name').notEmpty()
70 logger
.debug('Checking videosSearch parameters', { parameters: req
.params
})
72 checkErrors(req
, res
, next
)
75 // ---------------------------------------------------------------------------
77 module
.exports
= reqValidatorsVideos