aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-25 16:23:44 +0200
committerChocobozzz <me@florianbigard.com>2019-07-25 16:23:44 +0200
commitc8861d5dc0436ef4342ce517241e3591fa256a13 (patch)
treeca47c09d1f7f1e2aa62c684d576faa938eb47af7 /server/helpers
parentb4c19345c19b0891142c69308cd9447f2161188c (diff)
downloadPeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.tar.gz
PeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.tar.zst
PeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.zip
Fix express validator
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/accounts.ts1
-rw-r--r--server/helpers/custom-validators/misc.ts18
-rw-r--r--server/helpers/custom-validators/search.ts2
-rw-r--r--server/helpers/custom-validators/servers.ts4
-rw-r--r--server/helpers/custom-validators/users.ts1
-rw-r--r--server/helpers/custom-validators/video-channels.ts2
-rw-r--r--server/helpers/custom-validators/video-comments.ts1
-rw-r--r--server/helpers/custom-validators/video-imports.ts1
-rw-r--r--server/helpers/custom-validators/videos.ts7
9 files changed, 18 insertions, 19 deletions
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 @@
1import 'express-validator'
2import { isUserDescriptionValid, isUserUsernameValid } from './users' 1import { isUserDescriptionValid, isUserUsernameValid } from './users'
3import { exists } from './misc' 2import { exists } from './misc'
4 3
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 @@
1import 'multer' 1import 'multer'
2import * as validator from 'validator' 2import * as validator from 'validator'
3import { sep } from 'path' 3import { sep } from 'path'
4import toBoolean = require('validator/lib/toBoolean')
4 5
5function exists (value: any) { 6function exists (value: any) {
6 return value !== undefined && value !== null 7 return value !== undefined && value !== null
@@ -46,9 +47,21 @@ function isBooleanValid (value: any) {
46} 47}
47 48
48function toIntOrNull (value: string) { 49function toIntOrNull (value: string) {
49 if (value === 'null') return null 50 const v = toValueOrNull(value)
51
52 if (v === null || v === undefined) return v
53 if (typeof v === 'number') return v
54
55 return validator.toInt(v)
56}
57
58function toBooleanOrNull (value: any) {
59 const v = toValueOrNull(value)
60
61 if (v === null || v === undefined) return v
62 if (typeof v === 'boolean') return v
50 63
51 return validator.toInt(value) 64 return toBoolean(v)
52} 65}
53 66
54function toValueOrNull (value: string) { 67function toValueOrNull (value: string) {
@@ -110,6 +123,7 @@ export {
110 isIdOrUUIDValid, 123 isIdOrUUIDValid,
111 isDateValid, 124 isDateValid,
112 toValueOrNull, 125 toValueOrNull,
126 toBooleanOrNull,
113 isBooleanValid, 127 isBooleanValid,
114 toIntOrNull, 128 toIntOrNull,
115 toArray, 129 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 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2import 'express-validator'
3
4import { isArray } from './misc' 2import { isArray } from './misc'
5 3
6function isNumberArray (value: any) { 4function 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 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2import 'express-validator' 2import { exists, isArray } from './misc'
3
4import { isArray, exists } from './misc'
5import { isTestInstance } from '../core-utils' 3import { isTestInstance } from '../core-utils'
6import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 4import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
7 5
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 @@
1import 'express-validator'
2import * as validator from 'validator' 1import * as validator from 'validator'
3import { UserRole } from '../../../shared' 2import { UserRole } from '../../../shared'
4import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' 3import { 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 @@
1import 'express-validator'
2import 'multer'
3import * as validator from 'validator' 1import * as validator from 'validator'
4import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 2import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
5import { exists } from './misc' 3import { 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 @@
1import 'express-validator'
2import 'multer' 1import 'multer'
3import * as validator from 'validator' 2import * as validator from 'validator'
4import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 3import { 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 @@
1import 'express-validator'
2import 'multer' 1import 'multer'
3import * as validator from 'validator' 2import * as validator from 'validator'
4import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants' 3import { 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 @@
1import { Response } from 'express'
2import 'express-validator'
3import { values } from 'lodash' 1import { values } from 'lodash'
4import 'multer'
5import * as validator from 'validator' 2import * as validator from 'validator'
6import { UserRight, VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared' 3import { VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared'
7import { 4import {
8 CONSTRAINTS_FIELDS, 5 CONSTRAINTS_FIELDS,
9 MIMETYPES, 6 MIMETYPES,
@@ -13,9 +10,7 @@ import {
13 VIDEO_RATE_TYPES, 10 VIDEO_RATE_TYPES,
14 VIDEO_STATES 11 VIDEO_STATES
15} from '../../initializers/constants' 12} from '../../initializers/constants'
16import { VideoModel } from '../../models/video/video'
17import { exists, isArray, isDateValid, isFileValid } from './misc' 13import { exists, isArray, isDateValid, isFileValid } from './misc'
18import { UserModel } from '../../models/account/user'
19import * as magnetUtil from 'magnet-uri' 14import * as magnetUtil from 'magnet-uri'
20 15
21const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS 16const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS