diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/accounts.ts | 1 | ||||
-rw-r--r-- | server/helpers/custom-validators/misc.ts | 18 | ||||
-rw-r--r-- | server/helpers/custom-validators/search.ts | 2 | ||||
-rw-r--r-- | server/helpers/custom-validators/servers.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/users.ts | 1 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-channels.ts | 2 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-comments.ts | 1 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-imports.ts | 1 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 7 |
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 @@ | |||
1 | import 'express-validator' | ||
2 | import { isUserDescriptionValid, isUserUsernameValid } from './users' | 1 | import { isUserDescriptionValid, isUserUsernameValid } from './users' |
3 | import { exists } from './misc' | 2 | import { 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 @@ | |||
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, |
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 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import 'express-validator' | ||
3 | |||
4 | import { isArray } from './misc' | 2 | import { isArray } from './misc' |
5 | 3 | ||
6 | function isNumberArray (value: any) { | 4 | 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 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import 'express-validator' | 2 | import { exists, isArray } from './misc' |
3 | |||
4 | import { isArray, exists } from './misc' | ||
5 | import { isTestInstance } from '../core-utils' | 3 | import { isTestInstance } from '../core-utils' |
6 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 4 | import { 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 @@ | |||
1 | import 'express-validator' | ||
2 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
3 | import { UserRole } from '../../../shared' | 2 | import { UserRole } from '../../../shared' |
4 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' | 3 | 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 @@ | |||
1 | import 'express-validator' | ||
2 | import 'multer' | ||
3 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 2 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
5 | import { exists } from './misc' | 3 | 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 @@ | |||
1 | import 'express-validator' | ||
2 | import 'multer' | 1 | import 'multer' |
3 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 3 | 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 @@ | |||
1 | import 'express-validator' | ||
2 | import 'multer' | 1 | import 'multer' |
3 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
4 | import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants' | 3 | 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 @@ | |||
1 | import { Response } from 'express' | ||
2 | import 'express-validator' | ||
3 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
4 | import 'multer' | ||
5 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
6 | import { UserRight, VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared' | 3 | import { VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared' |
7 | import { | 4 | import { |
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' |
16 | import { VideoModel } from '../../models/video/video' | ||
17 | import { exists, isArray, isDateValid, isFileValid } from './misc' | 13 | import { exists, isArray, isDateValid, isFileValid } from './misc' |
18 | import { UserModel } from '../../models/account/user' | ||
19 | import * as magnetUtil from 'magnet-uri' | 14 | import * as magnetUtil from 'magnet-uri' |
20 | 15 | ||
21 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS | 16 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS |