]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - middlewares/reqValidators/videos.js
3763a657ceb9f9f1e2e71d16af829311382707f9
4 var checkErrors
= require('./utils').checkErrors
5 var VideosDB
= require('../../src/database').VideosDB
6 var logger
= require('../../src/logger')
10 function findVideoById (id
, callback
) {
11 VideosDB
.findById(id
, { _id: 1, namePath: 1 }).limit(1).exec(function (err
, video
) {
18 videos
.videosSearch = function (req
, res
, next
) {
19 req
.checkParams('name', 'Should have a name').notEmpty()
21 logger
.debug('Checking videosSearch parameters', { parameters: req
.params
})
23 checkErrors(req
, res
, next
)
26 videos
.videosAdd = function (req
, res
, next
) {
27 req
.checkFiles('input_video.originalname', 'Should have an input video').notEmpty()
28 req
.checkFiles('input_video.mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i)
29 req
.checkBody('name', 'Should have a name').isLength(1, 50)
30 req
.checkBody('description', 'Should have a description').isLength(1, 250)
32 logger
.debug('Checking videosAdd parameters', { parameters: req
.body
, files: req
.files
})
34 checkErrors(req
, res
, next
)
37 videos
.videosGet = function (req
, res
, next
) {
38 req
.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
40 logger
.debug('Checking videosGet parameters', { parameters: req
.params
})
42 checkErrors(req
, res
, function () {
43 findVideoById(req
.params
.id
, function (video
) {
44 if (!video
) return res
.status(404).send('Video not found')
51 videos
.videosRemove = function (req
, res
, next
) {
52 req
.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
54 logger
.debug('Checking videosRemove parameters', { parameters: req
.params
})
56 checkErrors(req
, res
, function () {
57 findVideoById(req
.params
.id
, function (video
) {
58 if (!video
) return res
.status(404).send('Video not found')
59 else if (video
.namePath
=== null) return res
.status(403).send('Cannot remove video of another pod')
66 module
.exports
= videos