From c8861d5dc0436ef4342ce517241e3591fa256a13 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Jul 2019 16:23:44 +0200 Subject: Fix express validator --- server/helpers/custom-validators/accounts.ts | 1 - server/helpers/custom-validators/misc.ts | 18 ++++++++++++++++-- server/helpers/custom-validators/search.ts | 2 -- server/helpers/custom-validators/servers.ts | 4 +--- server/helpers/custom-validators/users.ts | 1 - server/helpers/custom-validators/video-channels.ts | 2 -- server/helpers/custom-validators/video-comments.ts | 1 - server/helpers/custom-validators/video-imports.ts | 1 - server/helpers/custom-validators/videos.ts | 7 +------ 9 files changed, 18 insertions(+), 19 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts index be196d2a4..f676669ea 100644 --- a/server/helpers/custom-validators/accounts.ts +++ b/server/helpers/custom-validators/accounts.ts @@ -1,4 +1,3 @@ -import 'express-validator' import { isUserDescriptionValid, isUserUsernameValid } from './users' import { exists } from './misc' diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 3ef38fce1..1b7e00431 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts @@ -1,6 +1,7 @@ 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 @@ -46,9 +47,21 @@ function isBooleanValid (value: any) { } function toIntOrNull (value: string) { - if (value === 'null') return null + const v = toValueOrNull(value) + + if (v === null || v === undefined) return v + if (typeof v === 'number') return v + + return validator.toInt(v) +} + +function toBooleanOrNull (value: any) { + const v = toValueOrNull(value) + + if (v === null || v === undefined) return v + if (typeof v === 'boolean') return v - return validator.toInt(value) + return toBoolean(v) } function toValueOrNull (value: string) { @@ -110,6 +123,7 @@ export { isIdOrUUIDValid, isDateValid, toValueOrNull, + toBooleanOrNull, isBooleanValid, toIntOrNull, toArray, diff --git a/server/helpers/custom-validators/search.ts b/server/helpers/custom-validators/search.ts index 15b389a58..ee732b15a 100644 --- a/server/helpers/custom-validators/search.ts +++ b/server/helpers/custom-validators/search.ts @@ -1,6 +1,4 @@ import * as validator from 'validator' -import 'express-validator' - import { isArray } from './misc' function isNumberArray (value: any) { diff --git a/server/helpers/custom-validators/servers.ts b/server/helpers/custom-validators/servers.ts index 5c8bf0d2d..7ced36fd3 100644 --- a/server/helpers/custom-validators/servers.ts +++ b/server/helpers/custom-validators/servers.ts @@ -1,7 +1,5 @@ import * as validator from 'validator' -import 'express-validator' - -import { isArray, exists } from './misc' +import { exists, isArray } from './misc' import { isTestInstance } from '../core-utils' import { CONSTRAINTS_FIELDS } from '../../initializers/constants' diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 738d5cbbf..c56ae14ef 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -1,4 +1,3 @@ -import 'express-validator' import * as validator from 'validator' import { UserRole } from '../../../shared' import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts index f55f0c8ef..6c52dc093 100644 --- a/server/helpers/custom-validators/video-channels.ts +++ b/server/helpers/custom-validators/video-channels.ts @@ -1,5 +1,3 @@ -import 'express-validator' -import 'multer' import * as validator from 'validator' import { CONSTRAINTS_FIELDS } from '../../initializers/constants' import { exists } from './misc' diff --git a/server/helpers/custom-validators/video-comments.ts b/server/helpers/custom-validators/video-comments.ts index 0707e2af2..8a7cd7105 100644 --- a/server/helpers/custom-validators/video-comments.ts +++ b/server/helpers/custom-validators/video-comments.ts @@ -1,4 +1,3 @@ -import 'express-validator' import 'multer' import * as validator from 'validator' import { CONSTRAINTS_FIELDS } from '../../initializers/constants' diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts index f4235e2fa..8820c4c0a 100644 --- a/server/helpers/custom-validators/video-imports.ts +++ b/server/helpers/custom-validators/video-imports.ts @@ -1,4 +1,3 @@ -import 'express-validator' import 'multer' import * as validator from 'validator' import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants' diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 157e1a8e3..9ab1ef234 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -1,9 +1,6 @@ -import { Response } from 'express' -import 'express-validator' import { values } from 'lodash' -import 'multer' import * as validator from 'validator' -import { UserRight, VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared' +import { VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared' import { CONSTRAINTS_FIELDS, MIMETYPES, @@ -13,9 +10,7 @@ import { VIDEO_RATE_TYPES, VIDEO_STATES } from '../../initializers/constants' -import { VideoModel } from '../../models/video/video' import { exists, isArray, isDateValid, isFileValid } from './misc' -import { UserModel } from '../../models/account/user' import * as magnetUtil from 'magnet-uri' const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS -- cgit v1.2.3