diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/helpers/custom-validators/misc.ts | 5 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 8 | ||||
-rw-r--r-- | server/middlewares/validators/users.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 2 |
4 files changed, 7 insertions, 12 deletions
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 1b7e00431..0c3df1cd0 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import 'multer' | 1 | import 'multer' |
2 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
3 | import { sep } from 'path' | 3 | import { sep } from 'path' |
4 | import toBoolean = require('validator/lib/toBoolean') | ||
5 | 4 | ||
6 | function exists (value: any) { | 5 | function exists (value: any) { |
7 | return value !== undefined && value !== null | 6 | return value !== undefined && value !== null |
@@ -52,7 +51,7 @@ function toIntOrNull (value: string) { | |||
52 | if (v === null || v === undefined) return v | 51 | if (v === null || v === undefined) return v |
53 | if (typeof v === 'number') return v | 52 | if (typeof v === 'number') return v |
54 | 53 | ||
55 | return validator.toInt(v) | 54 | return validator.toInt('' + v) |
56 | } | 55 | } |
57 | 56 | ||
58 | function toBooleanOrNull (value: any) { | 57 | function toBooleanOrNull (value: any) { |
@@ -61,7 +60,7 @@ function toBooleanOrNull (value: any) { | |||
61 | if (v === null || v === undefined) return v | 60 | if (v === null || v === undefined) return v |
62 | if (typeof v === 'boolean') return v | 61 | if (typeof v === 'boolean') return v |
63 | 62 | ||
64 | return toBoolean(v) | 63 | return validator.toBoolean('' + v) |
65 | } | 64 | } |
66 | 65 | ||
67 | function toValueOrNull (value: string) { | 66 | function toValueOrNull (value: string) { |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 9ab1ef234..e92ef9b92 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -98,15 +98,11 @@ function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } | | |||
98 | } | 98 | } |
99 | 99 | ||
100 | function isVideoPrivacyValid (value: number) { | 100 | function isVideoPrivacyValid (value: number) { |
101 | return validator.isInt(value + '') && VIDEO_PRIVACIES[ value ] !== undefined | 101 | return VIDEO_PRIVACIES[ value ] !== undefined |
102 | } | 102 | } |
103 | 103 | ||
104 | function isScheduleVideoUpdatePrivacyValid (value: number) { | 104 | function isScheduleVideoUpdatePrivacyValid (value: number) { |
105 | return validator.isInt(value + '') && | 105 | return value === VideoPrivacy.UNLISTED || value === VideoPrivacy.PUBLIC |
106 | ( | ||
107 | value === VideoPrivacy.UNLISTED || | ||
108 | value === VideoPrivacy.PUBLIC | ||
109 | ) | ||
110 | } | 106 | } |
111 | 107 | ||
112 | function isVideoOriginallyPublishedAtValid (value: string | null) { | 108 | function isVideoOriginallyPublishedAtValid (value: string | null) { |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index db03dc231..da92c715d 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -2,7 +2,7 @@ import * as Bluebird from 'bluebird' | |||
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { body, param } from 'express-validator' | 3 | import { body, param } from 'express-validator' |
4 | import { omit } from 'lodash' | 4 | import { omit } from 'lodash' |
5 | import { isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' |
6 | import { | 6 | import { |
7 | isUserAdminFlagsValid, | 7 | isUserAdminFlagsValid, |
8 | isUserAutoPlayVideoValid, | 8 | isUserAutoPlayVideoValid, |
@@ -357,7 +357,7 @@ const usersVerifyEmailValidator = [ | |||
357 | .not().isEmpty().withMessage('Should have a valid verification string'), | 357 | .not().isEmpty().withMessage('Should have a valid verification string'), |
358 | body('isPendingEmail') | 358 | body('isPendingEmail') |
359 | .optional() | 359 | .optional() |
360 | .customSanitizer(toIntOrNull), | 360 | .customSanitizer(toBooleanOrNull), |
361 | 361 | ||
362 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 362 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
363 | logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params }) | 363 | logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params }) |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 27dfe91ca..af06f3c62 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -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 | .customSanitizer(toValueOrNull) | 352 | .customSanitizer(toIntOrNull) |
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 | } |