From b0f9f39ed70299a208d1b388c72de8b7f3510cb7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 4 Sep 2017 20:07:54 +0200 Subject: Begin user quota --- server/middlewares/validators/videos.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'server/middlewares/validators/videos.ts') diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index 29c1ee0ef..1d19ebfd9 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts @@ -24,10 +24,23 @@ function videosAddValidator (req: express.Request, res: express.Response, next: logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) checkErrors(req, res, () => { - const videoFile = req.files['videofile'][0] + const videoFile: Express.Multer.File = req.files['videofile'][0] + const user = res.locals.oauth.token.User - db.Video.getDurationFromFile(videoFile.path) + user.isAbleToUploadVideo(videoFile) + .then(isAble => { + if (isAble === false) { + res.status(403).send('The user video quota is exceeded with this video.') + + return undefined + } + + return db.Video.getDurationFromFile(videoFile.path) + }) .then(duration => { + // Previous test failed, abort + if (duration === undefined) return + if (!isVideoDurationValid('' + duration)) { return res.status(400).send('Duration of the video file is too big (max: ' + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).') } -- cgit v1.2.3