diff options
Diffstat (limited to 'server/middlewares/validators/videos/videos.ts')
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 26 |
1 files changed, 13 insertions, 13 deletions
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 | } |