From 67100f1f971dd10a466a321899b56c0813e08d31 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 16 May 2016 19:49:10 +0200 Subject: Add a check for the duration of videos --- server/middlewares/reqValidators/videos.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'server/middlewares') 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 @@ 'use strict' const checkErrors = require('./utils').checkErrors +const constants = require('../../initializers/constants') const logger = require('../../helpers/logger') const videos = require('../../lib/videos') const Videos = require('../../models/videos') @@ -20,7 +21,22 @@ function videosAdd (req, res, next) { logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) - checkErrors(req, res, next) + checkErrors(req, res, function () { + const videoFile = req.files.videofile[0] + + videos.getVideoDuration(videoFile.path, function (err, duration) { + if (err) { + return res.status(400).send('Cannot retrieve metadata of the file.') + } + + if (duration > constants.MAXIMUM_VIDEO_DURATION) { + return res.status(400).send('Duration of the video file is too big.') + } + + videoFile.duration = duration + next() + }) + }) } function videosGet (req, res, next) { -- cgit v1.2.3