diff options
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/avatar.ts | 3 | ||||
-rw-r--r-- | server/middlewares/validators/video-captions.ts | 7 | ||||
-rw-r--r-- | server/middlewares/validators/video-channels.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/videos.ts | 22 |
4 files changed, 19 insertions, 17 deletions
diff --git a/server/middlewares/validators/avatar.ts b/server/middlewares/validators/avatar.ts index f346ea92f..5860735c6 100644 --- a/server/middlewares/validators/avatar.ts +++ b/server/middlewares/validators/avatar.ts | |||
@@ -4,6 +4,7 @@ import { isAvatarFile } from '../../helpers/custom-validators/users' | |||
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 5 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
6 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
7 | import { cleanUpReqFiles } from '../../helpers/utils' | ||
7 | 8 | ||
8 | const updateAvatarValidator = [ | 9 | const updateAvatarValidator = [ |
9 | body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage( | 10 | body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage( |
@@ -14,7 +15,7 @@ const updateAvatarValidator = [ | |||
14 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 15 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
15 | logger.debug('Checking updateAvatarValidator parameters', { files: req.files }) | 16 | logger.debug('Checking updateAvatarValidator parameters', { files: req.files }) |
16 | 17 | ||
17 | if (areValidationErrors(req, res)) return | 18 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) |
18 | 19 | ||
19 | return next() | 20 | return next() |
20 | } | 21 | } |
diff --git a/server/middlewares/validators/video-captions.ts b/server/middlewares/validators/video-captions.ts index b6d92d380..18d537bc4 100644 --- a/server/middlewares/validators/video-captions.ts +++ b/server/middlewares/validators/video-captions.ts | |||
@@ -7,6 +7,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers' | |||
7 | import { UserRight } from '../../../shared' | 7 | import { UserRight } from '../../../shared' |
8 | import { logger } from '../../helpers/logger' | 8 | import { logger } from '../../helpers/logger' |
9 | import { isVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions' | 9 | import { isVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions' |
10 | import { cleanUpReqFiles } from '../../helpers/utils' | ||
10 | 11 | ||
11 | const addVideoCaptionValidator = [ | 12 | const addVideoCaptionValidator = [ |
12 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), | 13 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), |
@@ -20,12 +21,12 @@ const addVideoCaptionValidator = [ | |||
20 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 21 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
21 | logger.debug('Checking addVideoCaption parameters', { parameters: req.body }) | 22 | logger.debug('Checking addVideoCaption parameters', { parameters: req.body }) |
22 | 23 | ||
23 | if (areValidationErrors(req, res)) return | 24 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) |
24 | if (!await isVideoExist(req.params.videoId, res)) return | 25 | if (!await isVideoExist(req.params.videoId, res)) return cleanUpReqFiles(req) |
25 | 26 | ||
26 | // Check if the user who did the request is able to update the video | 27 | // Check if the user who did the request is able to update the video |
27 | const user = res.locals.oauth.token.User | 28 | const user = res.locals.oauth.token.User |
28 | if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return | 29 | if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return cleanUpReqFiles(req) |
29 | 30 | ||
30 | return next() | 31 | return next() |
31 | } | 32 | } |
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 7f65f7290..143ce9582 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { UserRight } from '../../../shared' | 3 | import { UserRight } from '../../../shared' |
4 | import { isAccountIdExist, isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' | 4 | import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' |
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
6 | import { | 6 | import { |
7 | isVideoChannelDescriptionValid, | 7 | isVideoChannelDescriptionValid, |
@@ -13,8 +13,6 @@ import { logger } from '../../helpers/logger' | |||
13 | import { UserModel } from '../../models/account/user' | 13 | import { UserModel } from '../../models/account/user' |
14 | import { VideoChannelModel } from '../../models/video/video-channel' | 14 | import { VideoChannelModel } from '../../models/video/video-channel' |
15 | import { areValidationErrors } from './utils' | 15 | import { areValidationErrors } from './utils' |
16 | import { isAvatarFile } from '../../helpers/custom-validators/users' | ||
17 | import { CONSTRAINTS_FIELDS } from '../../initializers' | ||
18 | 16 | ||
19 | const listVideoAccountChannelsValidator = [ | 17 | const listVideoAccountChannelsValidator = [ |
20 | param('accountName').exists().withMessage('Should have a valid account name'), | 18 | param('accountName').exists().withMessage('Should have a valid account name'), |
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index d9af2aa0a..9357c1e39 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts | |||
@@ -35,6 +35,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers' | |||
35 | import { VideoShareModel } from '../../models/video/video-share' | 35 | import { VideoShareModel } from '../../models/video/video-share' |
36 | import { authenticate } from '../oauth' | 36 | import { authenticate } from '../oauth' |
37 | import { areValidationErrors } from './utils' | 37 | import { areValidationErrors } from './utils' |
38 | import { cleanUpReqFiles } from '../../helpers/utils' | ||
38 | 39 | ||
39 | const videosAddValidator = getCommonVideoAttributes().concat([ | 40 | const videosAddValidator = getCommonVideoAttributes().concat([ |
40 | body('videofile') | 41 | body('videofile') |
@@ -50,13 +51,13 @@ const videosAddValidator = getCommonVideoAttributes().concat([ | |||
50 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 51 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
51 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) | 52 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) |
52 | 53 | ||
53 | if (areValidationErrors(req, res)) return | 54 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) |
54 | if (areErrorsInScheduleUpdate(req, res)) return | 55 | if (areErrorsInScheduleUpdate(req, res)) return cleanUpReqFiles(req) |
55 | 56 | ||
56 | const videoFile: Express.Multer.File = req.files['videofile'][0] | 57 | const videoFile: Express.Multer.File = req.files['videofile'][0] |
57 | const user = res.locals.oauth.token.User | 58 | const user = res.locals.oauth.token.User |
58 | 59 | ||
59 | if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return | 60 | if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) |
60 | 61 | ||
61 | const isAble = await user.isAbleToUploadVideo(videoFile) | 62 | const isAble = await user.isAbleToUploadVideo(videoFile) |
62 | if (isAble === false) { | 63 | if (isAble === false) { |
@@ -64,7 +65,7 @@ const videosAddValidator = getCommonVideoAttributes().concat([ | |||
64 | .json({ error: 'The user video quota is exceeded with this video.' }) | 65 | .json({ error: 'The user video quota is exceeded with this video.' }) |
65 | .end() | 66 | .end() |
66 | 67 | ||
67 | return | 68 | return cleanUpReqFiles(req) |
68 | } | 69 | } |
69 | 70 | ||
70 | let duration: number | 71 | let duration: number |
@@ -77,7 +78,7 @@ const videosAddValidator = getCommonVideoAttributes().concat([ | |||
77 | .json({ error: 'Invalid input file.' }) | 78 | .json({ error: 'Invalid input file.' }) |
78 | .end() | 79 | .end() |
79 | 80 | ||
80 | return | 81 | return cleanUpReqFiles(req) |
81 | } | 82 | } |
82 | 83 | ||
83 | videoFile['duration'] = duration | 84 | videoFile['duration'] = duration |
@@ -99,23 +100,24 @@ const videosUpdateValidator = getCommonVideoAttributes().concat([ | |||
99 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 100 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
100 | logger.debug('Checking videosUpdate parameters', { parameters: req.body }) | 101 | logger.debug('Checking videosUpdate parameters', { parameters: req.body }) |
101 | 102 | ||
102 | if (areValidationErrors(req, res)) return | 103 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) |
103 | if (areErrorsInScheduleUpdate(req, res)) return | 104 | if (areErrorsInScheduleUpdate(req, res)) return cleanUpReqFiles(req) |
104 | if (!await isVideoExist(req.params.id, res)) return | 105 | if (!await isVideoExist(req.params.id, res)) return cleanUpReqFiles(req) |
105 | 106 | ||
106 | const video = res.locals.video | 107 | const video = res.locals.video |
107 | 108 | ||
108 | // Check if the user who did the request is able to update the video | 109 | // Check if the user who did the request is able to update the video |
109 | const user = res.locals.oauth.token.User | 110 | const user = res.locals.oauth.token.User |
110 | if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return | 111 | if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return cleanUpReqFiles(req) |
111 | 112 | ||
112 | if (video.privacy !== VideoPrivacy.PRIVATE && req.body.privacy === VideoPrivacy.PRIVATE) { | 113 | if (video.privacy !== VideoPrivacy.PRIVATE && req.body.privacy === VideoPrivacy.PRIVATE) { |
114 | cleanUpReqFiles(req) | ||
113 | return res.status(409) | 115 | return res.status(409) |
114 | .json({ error: 'Cannot set "private" a video that was not private.' }) | 116 | .json({ error: 'Cannot set "private" a video that was not private.' }) |
115 | .end() | 117 | .end() |
116 | } | 118 | } |
117 | 119 | ||
118 | if (req.body.channelId && !await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return | 120 | if (req.body.channelId && !await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) |
119 | 121 | ||
120 | return next() | 122 | return next() |
121 | } | 123 | } |