diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-05-16 19:49:10 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-05-16 19:49:10 +0200 |
commit | 67100f1f971dd10a466a321899b56c0813e08d31 (patch) | |
tree | 3253db23a9dca2273fd2c9702fb3b6f1801c0f1c /server/middlewares/reqValidators/videos.js | |
parent | dcc7b3fe470fe5f1546c0f3e7c28c07fc54633c5 (diff) | |
download | PeerTube-67100f1f971dd10a466a321899b56c0813e08d31.tar.gz PeerTube-67100f1f971dd10a466a321899b56c0813e08d31.tar.zst PeerTube-67100f1f971dd10a466a321899b56c0813e08d31.zip |
Add a check for the duration of videos
Diffstat (limited to 'server/middlewares/reqValidators/videos.js')
-rw-r--r-- | server/middlewares/reqValidators/videos.js | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/server/middlewares/reqValidators/videos.js b/server/middlewares/reqValidators/videos.js index c20660452..6e6e75fb3 100644 --- a/server/middlewares/reqValidators/videos.js +++ b/server/middlewares/reqValidators/videos.js | |||
@@ -1,6 +1,7 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const checkErrors = require('./utils').checkErrors | 3 | const checkErrors = require('./utils').checkErrors |
4 | const constants = require('../../initializers/constants') | ||
4 | const logger = require('../../helpers/logger') | 5 | const logger = require('../../helpers/logger') |
5 | const videos = require('../../lib/videos') | 6 | const videos = require('../../lib/videos') |
6 | const Videos = require('../../models/videos') | 7 | const Videos = require('../../models/videos') |
@@ -20,7 +21,22 @@ function videosAdd (req, res, next) { | |||
20 | 21 | ||
21 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) | 22 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) |
22 | 23 | ||
23 | checkErrors(req, res, next) | 24 | checkErrors(req, res, function () { |
25 | const videoFile = req.files.videofile[0] | ||
26 | |||
27 | videos.getVideoDuration(videoFile.path, function (err, duration) { | ||
28 | if (err) { | ||
29 | return res.status(400).send('Cannot retrieve metadata of the file.') | ||
30 | } | ||
31 | |||
32 | if (duration > constants.MAXIMUM_VIDEO_DURATION) { | ||
33 | return res.status(400).send('Duration of the video file is too big.') | ||
34 | } | ||
35 | |||
36 | videoFile.duration = duration | ||
37 | next() | ||
38 | }) | ||
39 | }) | ||
24 | } | 40 | } |
25 | 41 | ||
26 | function videosGet (req, res, next) { | 42 | function videosGet (req, res, next) { |