aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-09-04 20:07:54 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-09-04 20:07:54 +0200
commitb0f9f39ed70299a208d1b388c72de8b7f3510cb7 (patch)
tree4b7d388125265533ac2f6d4bf457d018617e1db6 /server/middlewares
parente7dbeae8d915cdf4470ceb51c2724b04148b30b5 (diff)
downloadPeerTube-b0f9f39ed70299a208d1b388c72de8b7f3510cb7.tar.gz
PeerTube-b0f9f39ed70299a208d1b388c72de8b7f3510cb7.tar.zst
PeerTube-b0f9f39ed70299a208d1b388c72de8b7f3510cb7.zip
Begin user quota
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/validators/users.ts2
-rw-r--r--server/middlewares/validators/videos.ts17
2 files changed, 17 insertions, 2 deletions
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
12 req.checkBody('username', 'Should have a valid username').isUserUsernameValid() 12 req.checkBody('username', 'Should have a valid username').isUserUsernameValid()
13 req.checkBody('password', 'Should have a valid password').isUserPasswordValid() 13 req.checkBody('password', 'Should have a valid password').isUserPasswordValid()
14 req.checkBody('email', 'Should have a valid email').isEmail() 14 req.checkBody('email', 'Should have a valid email').isEmail()
15 req.checkBody('videoQuota', 'Should have a valid user quota').isUserVideoQuotaValid()
15 16
16 logger.debug('Checking usersAdd parameters', { parameters: req.body }) 17 logger.debug('Checking usersAdd parameters', { parameters: req.body })
17 18
@@ -55,6 +56,7 @@ function usersUpdateValidator (req: express.Request, res: express.Response, next
55 // Add old password verification 56 // Add old password verification
56 req.checkBody('password', 'Should have a valid password').optional().isUserPasswordValid() 57 req.checkBody('password', 'Should have a valid password').optional().isUserPasswordValid()
57 req.checkBody('displayNSFW', 'Should have a valid display Not Safe For Work attribute').optional().isUserDisplayNSFWValid() 58 req.checkBody('displayNSFW', 'Should have a valid display Not Safe For Work attribute').optional().isUserDisplayNSFWValid()
59 req.checkBody('videoQuota', 'Should have a valid user quota').optional().isUserVideoQuotaValid()
58 60
59 logger.debug('Checking usersUpdate parameters', { parameters: req.body }) 61 logger.debug('Checking usersUpdate parameters', { parameters: req.body })
60 62
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:
24 logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) 24 logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
25 25
26 checkErrors(req, res, () => { 26 checkErrors(req, res, () => {
27 const videoFile = req.files['videofile'][0] 27 const videoFile: Express.Multer.File = req.files['videofile'][0]
28 const user = res.locals.oauth.token.User
28 29
29 db.Video.getDurationFromFile(videoFile.path) 30 user.isAbleToUploadVideo(videoFile)
31 .then(isAble => {
32 if (isAble === false) {
33 res.status(403).send('The user video quota is exceeded with this video.')
34
35 return undefined
36 }
37
38 return db.Video.getDurationFromFile(videoFile.path)
39 })
30 .then(duration => { 40 .then(duration => {
41 // Previous test failed, abort
42 if (duration === undefined) return
43
31 if (!isVideoDurationValid('' + duration)) { 44 if (!isVideoDurationValid('' + duration)) {
32 return res.status(400).send('Duration of the video file is too big (max: ' + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).') 45 return res.status(400).send('Duration of the video file is too big (max: ' + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).')
33 } 46 }