]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/reqValidators/videos.js
3 const checkErrors
= require('./utils').checkErrors
4 const constants
= require('../../initializers/constants')
5 const logger
= require('../../helpers/logger')
6 const videos
= require('../../lib/videos')
7 const Videos
= require('../../models/videos')
9 const reqValidatorsVideos
= {
12 videosRemove: videosRemove
,
13 videosSearch: videosSearch
16 function videosAdd (req
, res
, next
) {
17 req
.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty()
18 req
.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i)
19 req
.checkBody('name', 'Should have a name').isLength(1, 50)
20 req
.checkBody('description', 'Should have a description').isLength(1, 250)
22 logger
.debug('Checking videosAdd parameters', { parameters: req
.body
, files: req
.files
})
24 checkErrors(req
, res
, function () {
25 const videoFile
= req
.files
.videofile
[0]
27 videos
.getVideoDuration(videoFile
.path
, function (err
, duration
) {
29 return res
.status(400).send('Cannot retrieve metadata of the file.')
32 if (duration
> constants
.MAXIMUM_VIDEO_DURATION
) {
33 return res
.status(400).send('Duration of the video file is too big.')
36 videoFile
.duration
= duration
42 function videosGet (req
, res
, next
) {
43 req
.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
45 logger
.debug('Checking videosGet parameters', { parameters: req
.params
})
47 checkErrors(req
, res
, function () {
48 Videos
.get(req
.params
.id
, function (err
, video
) {
50 logger
.error('Error in videosGet request validator.', { error: err
})
54 const state
= videos
.getVideoState(video
)
55 if (state
.exist
=== false) return res
.status(404).send('Video not found')
62 function videosRemove (req
, res
, next
) {
63 req
.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
65 logger
.debug('Checking videosRemove parameters', { parameters: req
.params
})
67 checkErrors(req
, res
, function () {
68 Videos
.get(req
.params
.id
, function (err
, video
) {
70 logger
.error('Error in videosRemove request validator.', { error: err
})
74 const state
= videos
.getVideoState(video
)
75 if (state
.exist
=== false) return res
.status(404).send('Video not found')
76 else if (state
.owned
=== false) return res
.status(403).send('Cannot remove video of another pod')
83 function videosSearch (req
, res
, next
) {
84 req
.checkParams('name', 'Should have a name').notEmpty()
86 logger
.debug('Checking videosSearch parameters', { parameters: req
.params
})
88 checkErrors(req
, res
, next
)
91 // ---------------------------------------------------------------------------
93 module
.exports
= reqValidatorsVideos