aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/misc.ts
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/custom-validators/misc.ts
parentb4c19345c19b0891142c69308cd9447f2161188c (diff)
downloadPeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.tar.gz
PeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.tar.zst
PeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.zip
Fix express validator
Diffstat (limited to 'server/helpers/custom-validators/misc.ts')
-rw-r--r--server/helpers/custom-validators/misc.ts18
1 files changed, 16 insertions, 2 deletions
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,