diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-10-02 15:39:09 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-10-02 15:39:09 +0200 |
commit | a6375e69668ea42e19531c6bc68dcd37f3f7cbd7 (patch) | |
tree | 03204a408d56311692c3528bedcf95d2455e94f2 /server/middlewares/validators/videos.js | |
parent | 052937db8a8d282eccdbdf38d487ed8d85d3c0a7 (diff) | |
parent | c4403b29ad4db097af528a7f04eea07e0ed320d0 (diff) | |
download | PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.gz PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.zst PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.zip |
Merge branch 'master' into webseed-merged
Diffstat (limited to 'server/middlewares/validators/videos.js')
-rw-r--r-- | server/middlewares/validators/videos.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/server/middlewares/validators/videos.js b/server/middlewares/validators/videos.js index 3e2af06fb..76e943e77 100644 --- a/server/middlewares/validators/videos.js +++ b/server/middlewares/validators/videos.js | |||
@@ -4,20 +4,21 @@ const mongoose = require('mongoose') | |||
4 | 4 | ||
5 | const checkErrors = require('./utils').checkErrors | 5 | const checkErrors = require('./utils').checkErrors |
6 | const constants = require('../../initializers/constants') | 6 | const constants = require('../../initializers/constants') |
7 | const customValidators = require('../../helpers/custom-validators') | 7 | const customVideosValidators = require('../../helpers/custom-validators').videos |
8 | const logger = require('../../helpers/logger') | 8 | const logger = require('../../helpers/logger') |
9 | 9 | ||
10 | const Video = mongoose.model('Video') | 10 | const Video = mongoose.model('Video') |
11 | 11 | ||
12 | const validatorsVideos = { | 12 | const validatorsVideos = { |
13 | videosAdd: videosAdd, | 13 | videosAdd, |
14 | videosGet: videosGet, | 14 | videosGet, |
15 | videosRemove: videosRemove, | 15 | videosRemove, |
16 | videosSearch: videosSearch | 16 | videosSearch |
17 | } | 17 | } |
18 | 18 | ||
19 | function videosAdd (req, res, next) { | 19 | function videosAdd (req, res, next) { |
20 | req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty() | 20 | req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty() |
21 | // TODO: move to constants and function | ||
21 | req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) | 22 | req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) |
22 | req.checkBody('name', 'Should have a valid name').isVideoNameValid() | 23 | req.checkBody('name', 'Should have a valid name').isVideoNameValid() |
23 | req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid() | 24 | req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid() |
@@ -33,8 +34,8 @@ function videosAdd (req, res, next) { | |||
33 | return res.status(400).send('Cannot retrieve metadata of the file.') | 34 | return res.status(400).send('Cannot retrieve metadata of the file.') |
34 | } | 35 | } |
35 | 36 | ||
36 | if (!customValidators.isVideoDurationValid(duration)) { | 37 | if (!customVideosValidators.isVideoDurationValid(duration)) { |
37 | return res.status(400).send('Duration of the video file is too big (max: ' + constants.VIDEOS_CONSTRAINTS_FIELDS.DURATION.max + 's).') | 38 | return res.status(400).send('Duration of the video file is too big (max: ' + constants.CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).') |
38 | } | 39 | } |
39 | 40 | ||
40 | videoFile.duration = duration | 41 | videoFile.duration = duration |
@@ -76,6 +77,7 @@ function videosRemove (req, res, next) { | |||
76 | 77 | ||
77 | if (!video) return res.status(404).send('Video not found') | 78 | if (!video) return res.status(404).send('Video not found') |
78 | else if (video.isOwned() === false) return res.status(403).send('Cannot remove video of another pod') | 79 | else if (video.isOwned() === false) return res.status(403).send('Cannot remove video of another pod') |
80 | else if (video.author !== res.locals.oauth.token.user.username) return res.status(403).send('Cannot remove video of another user') | ||
79 | 81 | ||
80 | next() | 82 | next() |
81 | }) | 83 | }) |