import 'multer'
import * as validator from 'validator'
import { sep } from 'path'
-import toBoolean = require('validator/lib/toBoolean')
function exists (value: any) {
return value !== undefined && value !== null
if (v === null || v === undefined) return v
if (typeof v === 'number') return v
- return validator.toInt(v)
+ return validator.toInt('' + v)
}
function toBooleanOrNull (value: any) {
if (v === null || v === undefined) return v
if (typeof v === 'boolean') return v
- return toBoolean(v)
+ return validator.toBoolean('' + v)
}
function toValueOrNull (value: string) {
}
function isVideoPrivacyValid (value: number) {
- return validator.isInt(value + '') && VIDEO_PRIVACIES[ value ] !== undefined
+ return VIDEO_PRIVACIES[ value ] !== undefined
}
function isScheduleVideoUpdatePrivacyValid (value: number) {
- return validator.isInt(value + '') &&
- (
- value === VideoPrivacy.UNLISTED ||
- value === VideoPrivacy.PUBLIC
- )
+ return value === VideoPrivacy.UNLISTED || value === VideoPrivacy.PUBLIC
}
function isVideoOriginallyPublishedAtValid (value: string | null) {
import * as express from 'express'
import { body, param } from 'express-validator'
import { omit } from 'lodash'
-import { isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc'
+import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
import {
isUserAdminFlagsValid,
isUserAutoPlayVideoValid,
.not().isEmpty().withMessage('Should have a valid verification string'),
body('isPendingEmail')
.optional()
- .customSanitizer(toIntOrNull),
+ .customSanitizer(toBooleanOrNull),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params })
.custom(isDateValid).withMessage('Should have a valid schedule update date'),
body('scheduleUpdate.privacy')
.optional()
- .customSanitizer(toValueOrNull)
+ .customSanitizer(toIntOrNull)
.custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy')
] as (ValidationChain | express.Handler)[]
}