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/users.ts | 2 ++ server/middlewares/validators/videos.ts | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 71e529872..eeb0e3557 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -12,6 +12,7 @@ function usersAddValidator (req: express.Request, res: express.Response, next: e req.checkBody('username', 'Should have a valid username').isUserUsernameValid() req.checkBody('password', 'Should have a valid password').isUserPasswordValid() req.checkBody('email', 'Should have a valid email').isEmail() + req.checkBody('videoQuota', 'Should have a valid user quota').isUserVideoQuotaValid() logger.debug('Checking usersAdd parameters', { parameters: req.body }) @@ -55,6 +56,7 @@ function usersUpdateValidator (req: express.Request, res: express.Response, next // Add old password verification req.checkBody('password', 'Should have a valid password').optional().isUserPasswordValid() req.checkBody('displayNSFW', 'Should have a valid display Not Safe For Work attribute').optional().isUserDisplayNSFWValid() + req.checkBody('videoQuota', 'Should have a valid user quota').optional().isUserVideoQuotaValid() logger.debug('Checking usersUpdate parameters', { parameters: req.body }) 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