diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-25 16:23:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-07-25 16:23:44 +0200 |
commit | c8861d5dc0436ef4342ce517241e3591fa256a13 (patch) | |
tree | ca47c09d1f7f1e2aa62c684d576faa938eb47af7 /server/helpers/custom-validators/misc.ts | |
parent | b4c19345c19b0891142c69308cd9447f2161188c (diff) | |
download | PeerTube-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.ts | 18 |
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 @@ | |||
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') | ||
4 | 5 | ||
5 | function exists (value: any) { | 6 | function 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 | ||
48 | function toIntOrNull (value: string) { | 49 | function 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 | |||
58 | function 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 | ||
54 | function toValueOrNull (value: string) { | 67 | function 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, |