diff options
Diffstat (limited to 'server/middlewares/validators/videos.ts')
-rw-r--r-- | server/middlewares/validators/videos.ts | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index 3f881e1b5..8a9b383b8 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts | |||
@@ -15,11 +15,12 @@ import { | |||
15 | isVideoLanguageValid, | 15 | isVideoLanguageValid, |
16 | isVideoTagsValid, | 16 | isVideoTagsValid, |
17 | isVideoNSFWValid, | 17 | isVideoNSFWValid, |
18 | isVideoIdOrUUIDValid, | 18 | isIdOrUUIDValid, |
19 | isVideoAbuseReasonValid, | 19 | isVideoAbuseReasonValid, |
20 | isVideoRatingTypeValid, | 20 | isVideoRatingTypeValid, |
21 | getDurationFromVideoFile, | 21 | getDurationFromVideoFile, |
22 | checkVideoExists | 22 | checkVideoExists, |
23 | isIdValid | ||
23 | } from '../../helpers' | 24 | } from '../../helpers' |
24 | 25 | ||
25 | const videosAddValidator = [ | 26 | const videosAddValidator = [ |
@@ -33,6 +34,7 @@ const videosAddValidator = [ | |||
33 | body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'), | 34 | body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'), |
34 | body('nsfw').custom(isVideoNSFWValid).withMessage('Should have a valid NSFW attribute'), | 35 | body('nsfw').custom(isVideoNSFWValid).withMessage('Should have a valid NSFW attribute'), |
35 | body('description').custom(isVideoDescriptionValid).withMessage('Should have a valid description'), | 36 | body('description').custom(isVideoDescriptionValid).withMessage('Should have a valid description'), |
37 | body('channelId').custom(isIdValid).withMessage('Should have correct video channel id'), | ||
36 | body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'), | 38 | body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'), |
37 | 39 | ||
38 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 40 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
@@ -42,7 +44,20 @@ const videosAddValidator = [ | |||
42 | const videoFile: Express.Multer.File = req.files['videofile'][0] | 44 | const videoFile: Express.Multer.File = req.files['videofile'][0] |
43 | const user = res.locals.oauth.token.User | 45 | const user = res.locals.oauth.token.User |
44 | 46 | ||
45 | user.isAbleToUploadVideo(videoFile) | 47 | return db.VideoChannel.loadByIdAndAuthor(req.body.channelId, user.Author.id) |
48 | .then(videoChannel => { | ||
49 | if (!videoChannel) { | ||
50 | res.status(400) | ||
51 | .json({ error: 'Unknown video video channel for this author.' }) | ||
52 | .end() | ||
53 | |||
54 | return undefined | ||
55 | } | ||
56 | |||
57 | res.locals.videoChannel = videoChannel | ||
58 | |||
59 | return user.isAbleToUploadVideo(videoFile) | ||
60 | }) | ||
46 | .then(isAble => { | 61 | .then(isAble => { |
47 | if (isAble === false) { | 62 | if (isAble === false) { |
48 | res.status(403) | 63 | res.status(403) |
@@ -88,7 +103,7 @@ const videosAddValidator = [ | |||
88 | ] | 103 | ] |
89 | 104 | ||
90 | const videosUpdateValidator = [ | 105 | const videosUpdateValidator = [ |
91 | param('id').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 106 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
92 | body('name').optional().custom(isVideoNameValid).withMessage('Should have a valid name'), | 107 | body('name').optional().custom(isVideoNameValid).withMessage('Should have a valid name'), |
93 | body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'), | 108 | body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'), |
94 | body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'), | 109 | body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'), |
@@ -109,7 +124,7 @@ const videosUpdateValidator = [ | |||
109 | .end() | 124 | .end() |
110 | } | 125 | } |
111 | 126 | ||
112 | if (res.locals.video.Author.userId !== res.locals.oauth.token.User.id) { | 127 | if (res.locals.video.VideoChannel.Author.userId !== res.locals.oauth.token.User.id) { |
113 | return res.status(403) | 128 | return res.status(403) |
114 | .json({ error: 'Cannot update video of another user' }) | 129 | .json({ error: 'Cannot update video of another user' }) |
115 | .end() | 130 | .end() |
@@ -122,7 +137,7 @@ const videosUpdateValidator = [ | |||
122 | ] | 137 | ] |
123 | 138 | ||
124 | const videosGetValidator = [ | 139 | const videosGetValidator = [ |
125 | param('id').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 140 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
126 | 141 | ||
127 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 142 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
128 | logger.debug('Checking videosGet parameters', { parameters: req.params }) | 143 | logger.debug('Checking videosGet parameters', { parameters: req.params }) |
@@ -134,7 +149,7 @@ const videosGetValidator = [ | |||
134 | ] | 149 | ] |
135 | 150 | ||
136 | const videosRemoveValidator = [ | 151 | const videosRemoveValidator = [ |
137 | param('id').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 152 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
138 | 153 | ||
139 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 154 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
140 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) | 155 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) |
@@ -162,7 +177,7 @@ const videosSearchValidator = [ | |||
162 | ] | 177 | ] |
163 | 178 | ||
164 | const videoAbuseReportValidator = [ | 179 | const videoAbuseReportValidator = [ |
165 | param('id').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 180 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
166 | body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'), | 181 | body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'), |
167 | 182 | ||
168 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 183 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
@@ -175,7 +190,7 @@ const videoAbuseReportValidator = [ | |||
175 | ] | 190 | ] |
176 | 191 | ||
177 | const videoRateValidator = [ | 192 | const videoRateValidator = [ |
178 | param('id').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 193 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
179 | body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'), | 194 | body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'), |
180 | 195 | ||
181 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 196 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |