]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - middlewares/reqValidators/videos.js
Remove useless anonymous functions of files
[github/Chocobozzz/PeerTube.git] / middlewares / reqValidators / videos.js
CommitLineData
9f10b292 1'use strict'
34ca3b52 2
9f10b292
C
3var checkErrors = require('./utils').checkErrors
4var logger = require('../../helpers/logger')
5var Videos = require('../../models/videos')
34ca3b52 6
9f10b292
C
7var reqValidatorsVideos = {
8 videosAdd: videosAdd,
9 videosGet: videosGet,
10 videosRemove: videosRemove,
11 videosSearch: videosSearch
12}
34ca3b52 13
9f10b292
C
14function 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)
34ca3b52 19
9f10b292 20 logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
34ca3b52 21
9f10b292
C
22 checkErrors(req, res, next)
23}
34ca3b52 24
9f10b292
C
25function videosGet (req, res, next) {
26 req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
34ca3b52 27
9f10b292 28 logger.debug('Checking videosGet parameters', { parameters: req.params })
34ca3b52 29
9f10b292
C
30 checkErrors(req, res, function () {
31 Videos.getVideoState(req.params.id, function (err, state) {
32 if (err) {
33 logger.error('Error in videosGet request validator.', { error: err })
34 res.sendStatus(500)
35 }
c173e565 36
9f10b292 37 if (state.exist === false) return res.status(404).send('Video not found')
34ca3b52 38
9f10b292 39 next()
34ca3b52 40 })
9f10b292
C
41 })
42}
34ca3b52 43
9f10b292
C
44function videosRemove (req, res, next) {
45 req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
34ca3b52 46
9f10b292 47 logger.debug('Checking videosRemove parameters', { parameters: req.params })
34ca3b52 48
9f10b292
C
49 checkErrors(req, res, function () {
50 Videos.getVideoState(req.params.id, function (err, state) {
51 if (err) {
52 logger.error('Error in videosRemove request validator.', { error: err })
53 res.sendStatus(500)
54 }
c173e565 55
9f10b292
C
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')
34ca3b52 58
9f10b292 59 next()
34ca3b52 60 })
9f10b292
C
61 })
62}
34ca3b52 63
9f10b292
C
64function videosSearch (req, res, next) {
65 req.checkParams('name', 'Should have a name').notEmpty()
c45f7f84 66
9f10b292 67 logger.debug('Checking videosSearch parameters', { parameters: req.params })
c45f7f84 68
9f10b292
C
69 checkErrors(req, res, next)
70}
c45f7f84 71
9f10b292 72// ---------------------------------------------------------------------------
c45f7f84 73
9f10b292 74module.exports = reqValidatorsVideos