]>
Commit | Line | Data |
---|---|---|
34ca3b52 C |
1 | ;(function () { |
2 | 'use strict' | |
3 | ||
4 | var checkErrors = require('./utils').checkErrors | |
cda02107 | 5 | var logger = require('../../helpers/logger') |
c173e565 | 6 | var Videos = require('../../models/videos') |
34ca3b52 | 7 | |
c45f7f84 C |
8 | var reqValidatorsVideos = { |
9 | videosAdd: videosAdd, | |
10 | videosGet: videosGet, | |
11 | videosRemove: videosRemove, | |
12 | videosSearch: videosSearch | |
34ca3b52 C |
13 | } |
14 | ||
c45f7f84 | 15 | function videosAdd (req, res, next) { |
207fbab4 C |
16 | req.checkFiles('input_video[0].originalname', 'Should have an input video').notEmpty() |
17 | req.checkFiles('input_video[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) | |
34ca3b52 C |
18 | req.checkBody('name', 'Should have a name').isLength(1, 50) |
19 | req.checkBody('description', 'Should have a description').isLength(1, 250) | |
20 | ||
21 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) | |
22 | ||
23 | checkErrors(req, res, next) | |
24 | } | |
25 | ||
c45f7f84 | 26 | function videosGet (req, res, next) { |
34ca3b52 C |
27 | req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId() |
28 | ||
29 | logger.debug('Checking videosGet parameters', { parameters: req.params }) | |
30 | ||
31 | checkErrors(req, res, function () { | |
c173e565 C |
32 | Videos.getVideoState(req.params.id, function (err, state) { |
33 | if (err) { | |
34 | logger.error('Error in videosGet request validator.', { error: err }) | |
35 | res.sendStatus(500) | |
36 | } | |
37 | ||
38 | if (state.exist === false) return res.status(404).send('Video not found') | |
34ca3b52 C |
39 | |
40 | next() | |
41 | }) | |
42 | }) | |
43 | } | |
44 | ||
c45f7f84 | 45 | function videosRemove (req, res, next) { |
34ca3b52 C |
46 | req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId() |
47 | ||
48 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) | |
49 | ||
50 | checkErrors(req, res, function () { | |
c173e565 C |
51 | Videos.getVideoState(req.params.id, function (err, state) { |
52 | if (err) { | |
53 | logger.error('Error in videosRemove request validator.', { error: err }) | |
54 | res.sendStatus(500) | |
55 | } | |
56 | ||
57 | if (state.exist === false) return res.status(404).send('Video not found') | |
58 | else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod') | |
34ca3b52 C |
59 | |
60 | next() | |
61 | }) | |
62 | }) | |
63 | } | |
64 | ||
c45f7f84 C |
65 | function videosSearch (req, res, next) { |
66 | req.checkParams('name', 'Should have a name').notEmpty() | |
67 | ||
68 | logger.debug('Checking videosSearch parameters', { parameters: req.params }) | |
69 | ||
70 | checkErrors(req, res, next) | |
71 | } | |
72 | ||
73 | // --------------------------------------------------------------------------- | |
74 | ||
75 | module.exports = reqValidatorsVideos | |
34ca3b52 | 76 | })() |