diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-25 16:23:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-07-25 16:23:44 +0200 |
commit | c8861d5dc0436ef4342ce517241e3591fa256a13 (patch) | |
tree | ca47c09d1f7f1e2aa62c684d576faa938eb47af7 /server/middlewares/validators/videos | |
parent | b4c19345c19b0891142c69308cd9447f2161188c (diff) | |
download | PeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.tar.gz PeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.tar.zst PeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.zip |
Fix express validator
Diffstat (limited to 'server/middlewares/validators/videos')
11 files changed, 40 insertions, 36 deletions
diff --git a/server/middlewares/validators/videos/video-abuses.ts b/server/middlewares/validators/videos/video-abuses.ts index e176e01af..e27d91bb1 100644 --- a/server/middlewares/validators/videos/video-abuses.ts +++ b/server/middlewares/validators/videos/video-abuses.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { body, param } from 'express-validator' |
3 | import { body, param } from 'express-validator/check' | ||
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
6 | import { areValidationErrors } from '../utils' | 5 | import { areValidationErrors } from '../utils' |
diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index db59427c7..3e8c5b30c 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator/check' | 2 | import { body, param, query } from 'express-validator' |
3 | import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' |
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { areValidationErrors } from '../utils' | 5 | import { areValidationErrors } from '../utils' |
6 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' | 6 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' |
@@ -24,7 +24,7 @@ const videosBlacklistAddValidator = [ | |||
24 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | 24 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), |
25 | body('unfederate') | 25 | body('unfederate') |
26 | .optional() | 26 | .optional() |
27 | .toBoolean() | 27 | .customSanitizer(toBooleanOrNull) |
28 | .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'), | 28 | .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'), |
29 | body('reason') | 29 | body('reason') |
30 | .optional() | 30 | .optional() |
diff --git a/server/middlewares/validators/videos/video-captions.ts b/server/middlewares/validators/videos/video-captions.ts index f8739e27f..f5610222a 100644 --- a/server/middlewares/validators/videos/video-captions.ts +++ b/server/middlewares/validators/videos/video-captions.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { areValidationErrors } from '../utils' | 2 | import { areValidationErrors } from '../utils' |
3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
4 | import { body, param } from 'express-validator/check' | 4 | import { body, param } from 'express-validator' |
5 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 5 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
6 | import { UserRight } from '../../../../shared' | 6 | import { UserRight } from '../../../../shared' |
7 | import { logger } from '../../../helpers/logger' | 7 | import { logger } from '../../../helpers/logger' |
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index c1065b898..3ee5064fc 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts | |||
@@ -1,5 +1,5 @@ | |||
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' |
3 | import { UserRight } from '../../../../shared' | 3 | import { UserRight } from '../../../../shared' |
4 | import { | 4 | import { |
5 | isVideoChannelDescriptionValid, | 5 | isVideoChannelDescriptionValid, |
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index 1e3e42833..83a0c24b0 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts | |||
@@ -1,5 +1,5 @@ | |||
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' |
3 | import { UserRight } from '../../../../shared' | 3 | import { UserRight } from '../../../../shared' |
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' | 5 | import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' |
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index 8b0dd8960..318dad100 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator/check' | 2 | import { body } from 'express-validator' |
3 | import { isIdValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' |
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { areValidationErrors } from '../utils' | 5 | import { areValidationErrors } from '../utils' |
6 | import { getCommonVideoEditAttributes } from './videos' | 6 | import { getCommonVideoEditAttributes } from './videos' |
@@ -13,7 +13,7 @@ import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares' | |||
13 | 13 | ||
14 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | 14 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ |
15 | body('channelId') | 15 | body('channelId') |
16 | .toInt() | 16 | .customSanitizer(toIntOrNull) |
17 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 17 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
18 | body('targetUrl') | 18 | body('targetUrl') |
19 | .optional() | 19 | .optional() |
diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts index 638122a2e..2e9c8aa33 100644 --- a/server/middlewares/validators/videos/video-playlists.ts +++ b/server/middlewares/validators/videos/video-playlists.ts | |||
@@ -1,12 +1,20 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query, ValidationChain } from 'express-validator/check' | 2 | import { body, param, query, ValidationChain } from 'express-validator' |
3 | import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared' | 3 | import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared' |
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { UserModel } from '../../../models/account/user' | 5 | import { UserModel } from '../../../models/account/user' |
6 | import { areValidationErrors } from '../utils' | 6 | import { areValidationErrors } from '../utils' |
7 | import { isVideoImage } from '../../../helpers/custom-validators/videos' | 7 | import { isVideoImage } from '../../../helpers/custom-validators/videos' |
8 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 8 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
9 | import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' | 9 | import { |
10 | isArrayOf, | ||
11 | isIdOrUUIDValid, | ||
12 | isIdValid, | ||
13 | isUUIDValid, | ||
14 | toIntArray, | ||
15 | toIntOrNull, | ||
16 | toValueOrNull | ||
17 | } from '../../../helpers/custom-validators/misc' | ||
10 | import { | 18 | import { |
11 | isVideoPlaylistDescriptionValid, | 19 | isVideoPlaylistDescriptionValid, |
12 | isVideoPlaylistNameValid, | 20 | isVideoPlaylistNameValid, |
@@ -374,12 +382,11 @@ function getCommonPlaylistEditAttributes () { | |||
374 | .custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'), | 382 | .custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'), |
375 | body('privacy') | 383 | body('privacy') |
376 | .optional() | 384 | .optional() |
377 | .toInt() | 385 | .customSanitizer(toIntOrNull) |
378 | .custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'), | 386 | .custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'), |
379 | body('videoChannelId') | 387 | body('videoChannelId') |
380 | .optional() | 388 | .optional() |
381 | .customSanitizer(toValueOrNull) | 389 | .customSanitizer(toIntOrNull) |
382 | .toInt() | ||
383 | ] as (ValidationChain | express.Handler)[] | 390 | ] as (ValidationChain | express.Handler)[] |
384 | } | 391 | } |
385 | 392 | ||
diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index 5bb3f4a51..4021cfecc 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { body, param, query } from 'express-validator/check' | ||
4 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
5 | import { isRatingValid } from '../../../helpers/custom-validators/video-rates' | 4 | import { isRatingValid } from '../../../helpers/custom-validators/video-rates' |
6 | import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' | 5 | import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' |
diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts index 6f4a1f3e0..ace62be5c 100644 --- a/server/middlewares/validators/videos/video-shares.ts +++ b/server/middlewares/validators/videos/video-shares.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { param } from 'express-validator' |
3 | import { param } from 'express-validator/check' | ||
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
6 | import { VideoShareModel } from '../../../models/video/video-share' | 5 | import { VideoShareModel } from '../../../models/video/video-share' |
diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts index a0b530c75..d6ca1d341 100644 --- a/server/middlewares/validators/videos/video-watch.ts +++ b/server/middlewares/validators/videos/video-watch.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { body, param } from 'express-validator/check' | 1 | import { body, param } from 'express-validator' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators/misc' |
4 | import { areValidationErrors } from '../utils' | 4 | import { areValidationErrors } from '../utils' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
6 | import { doesVideoExist } from '../../../helpers/middlewares' | 6 | import { doesVideoExist } from '../../../helpers/middlewares' |
@@ -8,7 +8,7 @@ import { doesVideoExist } from '../../../helpers/middlewares' | |||
8 | const videoWatchingValidator = [ | 8 | const videoWatchingValidator = [ |
9 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 9 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
10 | body('currentTime') | 10 | body('currentTime') |
11 | .toInt() | 11 | .customSanitizer(toIntOrNull) |
12 | .isInt().withMessage('Should have correct current time'), | 12 | .isInt().withMessage('Should have correct current time'), |
13 | 13 | ||
14 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 14 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 8f5e5c95c..27dfe91ca 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { body, param, query, ValidationChain } from 'express-validator' |
3 | import { body, param, query, ValidationChain } from 'express-validator/check' | ||
4 | import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' | 3 | import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' |
5 | import { | 4 | import { |
6 | isBooleanValid, | 5 | isBooleanValid, |
@@ -9,6 +8,7 @@ import { | |||
9 | isIdValid, | 8 | isIdValid, |
10 | isUUIDValid, | 9 | isUUIDValid, |
11 | toArray, | 10 | toArray, |
11 | toBooleanOrNull, | ||
12 | toIntOrNull, | 12 | toIntOrNull, |
13 | toValueOrNull | 13 | toValueOrNull |
14 | } from '../../../helpers/custom-validators/misc' | 14 | } from '../../../helpers/custom-validators/misc' |
@@ -53,7 +53,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([ | |||
53 | ), | 53 | ), |
54 | body('name').custom(isVideoNameValid).withMessage('Should have a valid name'), | 54 | body('name').custom(isVideoNameValid).withMessage('Should have a valid name'), |
55 | body('channelId') | 55 | body('channelId') |
56 | .toInt() | 56 | .customSanitizer(toIntOrNull) |
57 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 57 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
58 | 58 | ||
59 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 59 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
@@ -101,7 +101,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ | |||
101 | .custom(isVideoNameValid).withMessage('Should have a valid name'), | 101 | .custom(isVideoNameValid).withMessage('Should have a valid name'), |
102 | body('channelId') | 102 | body('channelId') |
103 | .optional() | 103 | .optional() |
104 | .toInt() | 104 | .customSanitizer(toIntOrNull) |
105 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 105 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
106 | 106 | ||
107 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 107 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
@@ -307,15 +307,15 @@ function getCommonVideoEditAttributes () { | |||
307 | .custom(isVideoLanguageValid).withMessage('Should have a valid language'), | 307 | .custom(isVideoLanguageValid).withMessage('Should have a valid language'), |
308 | body('nsfw') | 308 | body('nsfw') |
309 | .optional() | 309 | .optional() |
310 | .toBoolean() | 310 | .customSanitizer(toBooleanOrNull) |
311 | .custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), | 311 | .custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), |
312 | body('waitTranscoding') | 312 | body('waitTranscoding') |
313 | .optional() | 313 | .optional() |
314 | .toBoolean() | 314 | .customSanitizer(toBooleanOrNull) |
315 | .custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'), | 315 | .custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'), |
316 | body('privacy') | 316 | body('privacy') |
317 | .optional() | 317 | .optional() |
318 | .toInt() | 318 | .customSanitizer(toValueOrNull) |
319 | .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), | 319 | .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), |
320 | body('description') | 320 | body('description') |
321 | .optional() | 321 | .optional() |
@@ -331,16 +331,16 @@ function getCommonVideoEditAttributes () { | |||
331 | .custom(isVideoTagsValid).withMessage('Should have correct tags'), | 331 | .custom(isVideoTagsValid).withMessage('Should have correct tags'), |
332 | body('commentsEnabled') | 332 | body('commentsEnabled') |
333 | .optional() | 333 | .optional() |
334 | .toBoolean() | 334 | .customSanitizer(toBooleanOrNull) |
335 | .custom(isBooleanValid).withMessage('Should have comments enabled boolean'), | 335 | .custom(isBooleanValid).withMessage('Should have comments enabled boolean'), |
336 | body('downloadEnabled') | 336 | body('downloadEnabled') |
337 | .optional() | 337 | .optional() |
338 | .toBoolean() | 338 | .customSanitizer(toBooleanOrNull) |
339 | .custom(isBooleanValid).withMessage('Should have downloading enabled boolean'), | 339 | .custom(isBooleanValid).withMessage('Should have downloading enabled boolean'), |
340 | body('originallyPublishedAt') | 340 | body('originallyPublishedAt') |
341 | .optional() | 341 | .optional() |
342 | .customSanitizer(toValueOrNull) | 342 | .customSanitizer(toValueOrNull) |
343 | .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'), | 343 | .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'), |
344 | body('scheduleUpdate') | 344 | body('scheduleUpdate') |
345 | .optional() | 345 | .optional() |
346 | .customSanitizer(toValueOrNull), | 346 | .customSanitizer(toValueOrNull), |
@@ -349,7 +349,7 @@ function getCommonVideoEditAttributes () { | |||
349 | .custom(isDateValid).withMessage('Should have a valid schedule update date'), | 349 | .custom(isDateValid).withMessage('Should have a valid schedule update date'), |
350 | body('scheduleUpdate.privacy') | 350 | body('scheduleUpdate.privacy') |
351 | .optional() | 351 | .optional() |
352 | .toInt() | 352 | .customSanitizer(toValueOrNull) |
353 | .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy') | 353 | .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy') |
354 | ] as (ValidationChain | express.Handler)[] | 354 | ] as (ValidationChain | express.Handler)[] |
355 | } | 355 | } |