aboutsummaryrefslogtreecommitdiffhomepage
path: root/middlewares/reqValidators/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'middlewares/reqValidators/videos.js')
-rw-r--r--middlewares/reqValidators/videos.js74
1 files changed, 0 insertions, 74 deletions
diff --git a/middlewares/reqValidators/videos.js b/middlewares/reqValidators/videos.js
deleted file mode 100644
index 4e5f4391f..000000000
--- a/middlewares/reqValidators/videos.js
+++ /dev/null
@@ -1,74 +0,0 @@
1'use strict'
2
3var checkErrors = require('./utils').checkErrors
4var logger = require('../../helpers/logger')
5var Videos = require('../../models/videos')
6
7var reqValidatorsVideos = {
8 videosAdd: videosAdd,
9 videosGet: videosGet,
10 videosRemove: videosRemove,
11 videosSearch: videosSearch
12}
13
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)
19
20 logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
21
22 checkErrors(req, res, next)
23}
24
25function videosGet (req, res, next) {
26 req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
27
28 logger.debug('Checking videosGet parameters', { parameters: req.params })
29
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 }
36
37 if (state.exist === false) return res.status(404).send('Video not found')
38
39 next()
40 })
41 })
42}
43
44function videosRemove (req, res, next) {
45 req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
46
47 logger.debug('Checking videosRemove parameters', { parameters: req.params })
48
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 }
55
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')
58
59 next()
60 })
61 })
62}
63
64function videosSearch (req, res, next) {
65 req.checkParams('name', 'Should have a name').notEmpty()
66
67 logger.debug('Checking videosSearch parameters', { parameters: req.params })
68
69 checkErrors(req, res, next)
70}
71
72// ---------------------------------------------------------------------------
73
74module.exports = reqValidatorsVideos