diff options
51 files changed, 93 insertions, 101 deletions
diff --git a/client/src/app/shared/video/infinite-scroller.directive.ts b/client/src/app/shared/video/infinite-scroller.directive.ts index 5f8a1dd6e..b1e88882c 100644 --- a/client/src/app/shared/video/infinite-scroller.directive.ts +++ b/client/src/app/shared/video/infinite-scroller.directive.ts | |||
@@ -39,7 +39,7 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy { | |||
39 | 39 | ||
40 | const scrollObservable = fromEvent(this.container || window, 'scroll') | 40 | const scrollObservable = fromEvent(this.container || window, 'scroll') |
41 | .pipe( | 41 | .pipe( |
42 | startWith(null), | 42 | startWith(null as string), // FIXME: typings |
43 | throttleTime(200, undefined, throttleOptions), | 43 | throttleTime(200, undefined, throttleOptions), |
44 | map(() => this.getScrollInfo()), | 44 | map(() => this.getScrollInfo()), |
45 | distinctUntilChanged((o1, o2) => o1.current === o2.current), | 45 | distinctUntilChanged((o1, o2) => o1.current === o2.current), |
diff --git a/client/src/app/shared/video/video-miniature.component.html b/client/src/app/shared/video/video-miniature.component.html index 7af0f1113..51ca1393d 100644 --- a/client/src/app/shared/video/video-miniature.component.html +++ b/client/src/app/shared/video/video-miniature.component.html | |||
@@ -31,7 +31,7 @@ | |||
31 | 31 | ||
32 | <div class="video-info-privacy"> | 32 | <div class="video-info-privacy"> |
33 | <ng-container *ngIf="displayOptions.privacyText">{{ video.privacy.label }}</ng-container> | 33 | <ng-container *ngIf="displayOptions.privacyText">{{ video.privacy.label }}</ng-container> |
34 | <ng-container *ngIf="displayOptions.privacyText && displayOptions.state"> - </ng-container> | 34 | <ng-container *ngIf="displayOptions.privacyText && getStateLabel(video)"> - </ng-container> |
35 | <ng-container *ngIf="displayOptions.state">{{ getStateLabel(video) }}</ng-container> | 35 | <ng-container *ngIf="displayOptions.state">{{ getStateLabel(video) }}</ng-container> |
36 | </div> | 36 | </div> |
37 | 37 | ||
diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.ts index 027c2b026..0d499d47f 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts | |||
@@ -255,10 +255,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
255 | ) | 255 | ) |
256 | 256 | ||
257 | // Video did change | 257 | // Video did change |
258 | forkJoin( | 258 | forkJoin([ |
259 | videoObs, | 259 | videoObs, |
260 | this.videoCaptionService.listCaptions(videoId) | 260 | this.videoCaptionService.listCaptions(videoId) |
261 | ) | 261 | ]) |
262 | .pipe( | 262 | .pipe( |
263 | // If 401, the video is private or blacklisted so redirect to 404 | 263 | // If 401, the video is private or blacklisted so redirect to 404 |
264 | catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ])) | 264 | catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ])) |
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 |
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts index 2b4e300e4..77fb305dd 100644 --- a/server/middlewares/oauth.ts +++ b/server/middlewares/oauth.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as OAuthServer from 'express-oauth-server' | 2 | import * as OAuthServer from 'express-oauth-server' |
3 | import 'express-validator' | ||
4 | import { OAUTH_LIFETIME } from '../initializers/constants' | 3 | import { OAUTH_LIFETIME } from '../initializers/constants' |
5 | import { logger } from '../helpers/logger' | 4 | import { logger } from '../helpers/logger' |
6 | import { Socket } from 'socket.io' | 5 | import { Socket } from 'socket.io' |
diff --git a/server/middlewares/pagination.ts b/server/middlewares/pagination.ts index 83304940f..043869303 100644 --- a/server/middlewares/pagination.ts +++ b/server/middlewares/pagination.ts | |||
@@ -1,6 +1,4 @@ | |||
1 | import 'express-validator' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | |||
4 | import { PAGINATION } from '../initializers/constants' | 2 | import { PAGINATION } from '../initializers/constants' |
5 | 3 | ||
6 | function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) { | 4 | function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) { |
diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts index c52f4685b..9c0af443a 100644 --- a/server/middlewares/servers.ts +++ b/server/middlewares/servers.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | ||
3 | import { getHostWithPort } from '../helpers/express-utils' | 2 | import { getHostWithPort } from '../helpers/express-utils' |
4 | 3 | ||
5 | function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { | 4 | function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { |
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts index 6507aa5b8..8c27e8237 100644 --- a/server/middlewares/sort.ts +++ b/server/middlewares/sort.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | ||
3 | import { SortType } from '../models/utils' | 2 | import { SortType } from '../models/utils' |
4 | 3 | ||
5 | function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) { | 4 | function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.ts index 498e3d677..4da7b9802 100644 --- a/server/middlewares/user-right.ts +++ b/server/middlewares/user-right.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | ||
3 | import { UserRight } from '../../shared' | 2 | import { UserRight } from '../../shared' |
4 | import { logger } from '../helpers/logger' | 3 | import { logger } from '../helpers/logger' |
5 | 4 | ||
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 67e4bf8cc..cbdcef2fd 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator' |
3 | import { isAccountNameValid } from '../../helpers/custom-validators/accounts' | 3 | import { isAccountNameValid } from '../../helpers/custom-validators/accounts' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.ts index be14e92ea..02b191480 100644 --- a/server/middlewares/validators/activitypub/signature.ts +++ b/server/middlewares/validators/activitypub/signature.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator/check' | 2 | import { body } from 'express-validator' |
3 | import { | 3 | import { |
4 | isSignatureCreatorValid, isSignatureTypeValid, | 4 | isSignatureCreatorValid, isSignatureTypeValid, |
5 | isSignatureValueValid | 5 | isSignatureValueValid |
diff --git a/server/middlewares/validators/avatar.ts b/server/middlewares/validators/avatar.ts index bab3ed118..8623d07e8 100644 --- a/server/middlewares/validators/avatar.ts +++ b/server/middlewares/validators/avatar.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator/check' | 2 | import { body } from 'express-validator' |
3 | import { isAvatarFile } from '../../helpers/custom-validators/users' | 3 | import { isAvatarFile } from '../../helpers/custom-validators/users' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 5 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts index 63d95e9e0..47a0b1a1c 100644 --- a/server/middlewares/validators/blocklist.ts +++ b/server/middlewares/validators/blocklist.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { body, param } from 'express-validator/check' | 1 | import { body, param } from 'express-validator' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 9c43da165..5059ed0f2 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator/check' | 2 | import { body } from 'express-validator' |
3 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' | 3 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | 5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts index fa130121f..1bef9891b 100644 --- a/server/middlewares/validators/feeds.ts +++ b/server/middlewares/validators/feeds.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param, query } from 'express-validator/check' | 2 | import { param, query } from 'express-validator' |
3 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index 2e5a02307..c3d772297 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator' |
3 | import { isTestInstance } from '../../helpers/core-utils' | 3 | import { isTestInstance } from '../../helpers/core-utils' |
4 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' | 4 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' |
5 | import { logger } from '../../helpers/logger' | 5 | import { logger } from '../../helpers/logger' |
diff --git a/server/middlewares/validators/jobs.ts b/server/middlewares/validators/jobs.ts index 2f8b1738c..41a8d6899 100644 --- a/server/middlewares/validators/jobs.ts +++ b/server/middlewares/validators/jobs.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator' |
3 | import { isValidJobState } from '../../helpers/custom-validators/jobs' | 3 | import { isValidJobState } from '../../helpers/custom-validators/jobs' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
diff --git a/server/middlewares/validators/logs.ts b/server/middlewares/validators/logs.ts index 7380c6edd..07f3f552f 100644 --- a/server/middlewares/validators/logs.ts +++ b/server/middlewares/validators/logs.ts | |||
@@ -2,7 +2,7 @@ import * as express from 'express' | |||
2 | import { logger } from '../../helpers/logger' | 2 | import { logger } from '../../helpers/logger' |
3 | import { areValidationErrors } from './utils' | 3 | import { areValidationErrors } from './utils' |
4 | import { isDateValid } from '../../helpers/custom-validators/misc' | 4 | import { isDateValid } from '../../helpers/custom-validators/misc' |
5 | import { query } from 'express-validator/check' | 5 | import { query } from 'express-validator' |
6 | import { isValidLogLevel } from '../../helpers/custom-validators/logs' | 6 | import { isValidLogLevel } from '../../helpers/custom-validators/logs' |
7 | 7 | ||
8 | const getLogsValidator = [ | 8 | const getLogsValidator = [ |
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index 505319980..24ba5569d 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator/check' | 2 | import { query } from 'express-validator' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { isTestInstance } from '../../helpers/core-utils' | 4 | import { isTestInstance } from '../../helpers/core-utils' |
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts index e1ed8cd65..80ae57c0b 100644 --- a/server/middlewares/validators/pagination.ts +++ b/server/middlewares/validators/pagination.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator/check' | 2 | import { query } from 'express-validator' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | 5 | ||
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts index dc3f1454a..910d03c29 100644 --- a/server/middlewares/validators/plugins.ts +++ b/server/middlewares/validators/plugins.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator/check' | 2 | import { body, param, query } from 'express-validator' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | import { isNpmPluginNameValid, isPluginNameValid, isPluginTypeValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' | 5 | import { isNpmPluginNameValid, isPluginNameValid, isPluginTypeValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' |
6 | import { PluginManager } from '../../lib/plugins/plugin-manager' | 6 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
7 | import { isBooleanValid, isSafePath } from '../../helpers/custom-validators/misc' | 7 | import { isBooleanValid, isSafePath, toBooleanOrNull } from '../../helpers/custom-validators/misc' |
8 | import { PluginModel } from '../../models/server/plugin' | 8 | import { PluginModel } from '../../models/server/plugin' |
9 | import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model' | 9 | import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model' |
10 | import { PluginType } from '../../../shared/models/plugins/plugin.type' | 10 | import { PluginType } from '../../../shared/models/plugins/plugin.type' |
@@ -39,7 +39,7 @@ const listPluginsValidator = [ | |||
39 | .custom(isPluginTypeValid).withMessage('Should have a valid plugin type'), | 39 | .custom(isPluginTypeValid).withMessage('Should have a valid plugin type'), |
40 | query('uninstalled') | 40 | query('uninstalled') |
41 | .optional() | 41 | .optional() |
42 | .toBoolean() | 42 | .customSanitizer(toBooleanOrNull) |
43 | .custom(isBooleanValid).withMessage('Should have a valid uninstalled attribute'), | 43 | .custom(isBooleanValid).withMessage('Should have a valid uninstalled attribute'), |
44 | 44 | ||
45 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 45 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.ts index edc53a6b2..1fdac0e4e 100644 --- a/server/middlewares/validators/redundancy.ts +++ b/server/middlewares/validators/redundancy.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { body, param } from 'express-validator' |
3 | import { body, param } from 'express-validator/check' | 3 | import { exists, isBooleanValid, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' |
4 | import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc' | ||
5 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
6 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
7 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' | 6 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' |
@@ -68,7 +67,7 @@ const videoPlaylistRedundancyGetValidator = [ | |||
68 | const updateServerRedundancyValidator = [ | 67 | const updateServerRedundancyValidator = [ |
69 | param('host').custom(isHostValid).withMessage('Should have a valid host'), | 68 | param('host').custom(isHostValid).withMessage('Should have a valid host'), |
70 | body('redundancyAllowed') | 69 | body('redundancyAllowed') |
71 | .toBoolean() | 70 | .customSanitizer(toBooleanOrNull) |
72 | .custom(isBooleanValid).withMessage('Should have a valid redundancyAllowed attribute'), | 71 | .custom(isBooleanValid).withMessage('Should have a valid redundancyAllowed attribute'), |
73 | 72 | ||
74 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 73 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts index 7816d229c..5a3c83f2c 100644 --- a/server/middlewares/validators/search.ts +++ b/server/middlewares/validators/search.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { areValidationErrors } from './utils' | 2 | import { areValidationErrors } from './utils' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { query } from 'express-validator/check' | 4 | import { query } from 'express-validator' |
5 | import { isDateValid } from '../../helpers/custom-validators/misc' | 5 | import { isDateValid } from '../../helpers/custom-validators/misc' |
6 | 6 | ||
7 | const videosSearchValidator = [ | 7 | const videosSearchValidator = [ |
diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts index 6eff8e9ee..f6812647b 100644 --- a/server/middlewares/validators/server.ts +++ b/server/middlewares/validators/server.ts | |||
@@ -3,7 +3,7 @@ import { logger } from '../../helpers/logger' | |||
3 | import { areValidationErrors } from './utils' | 3 | import { areValidationErrors } from './utils' |
4 | import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers' | 4 | import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers' |
5 | import { ServerModel } from '../../models/server/server' | 5 | import { ServerModel } from '../../models/server/server' |
6 | import { body } from 'express-validator/check' | 6 | import { body } from 'express-validator' |
7 | import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' | 7 | import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' |
8 | import { Emailer } from '../../lib/emailer' | 8 | import { Emailer } from '../../lib/emailer' |
9 | import { Redis } from '../../lib/redis' | 9 | import { Redis } from '../../lib/redis' |
diff --git a/server/middlewares/validators/themes.ts b/server/middlewares/validators/themes.ts index 642f2df78..24a9673f7 100644 --- a/server/middlewares/validators/themes.ts +++ b/server/middlewares/validators/themes.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' | 5 | import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' |
diff --git a/server/middlewares/validators/user-history.ts b/server/middlewares/validators/user-history.ts index 418313d09..2f1d3cc41 100644 --- a/server/middlewares/validators/user-history.ts +++ b/server/middlewares/validators/user-history.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { body } from 'express-validator/check' | ||
4 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
6 | import { isDateValid } from '../../helpers/custom-validators/misc' | 5 | import { isDateValid } from '../../helpers/custom-validators/misc' |
diff --git a/server/middlewares/validators/user-notifications.ts b/server/middlewares/validators/user-notifications.ts index 3ded8d8cf..308b32655 100644 --- a/server/middlewares/validators/user-notifications.ts +++ b/server/middlewares/validators/user-notifications.ts | |||
@@ -1,15 +1,14 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { body, query } from 'express-validator' |
3 | import { body, query } from 'express-validator/check' | ||
4 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
6 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' | 5 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' |
7 | import { isNotEmptyIntArray } from '../../helpers/custom-validators/misc' | 6 | import { isNotEmptyIntArray, toBooleanOrNull } from '../../helpers/custom-validators/misc' |
8 | 7 | ||
9 | const listUserNotificationsValidator = [ | 8 | const listUserNotificationsValidator = [ |
10 | query('unread') | 9 | query('unread') |
11 | .optional() | 10 | .optional() |
12 | .toBoolean() | 11 | .customSanitizer(toBooleanOrNull) |
13 | .isBoolean().withMessage('Should have a valid unread boolean'), | 12 | .isBoolean().withMessage('Should have a valid unread boolean'), |
14 | 13 | ||
15 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 14 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts index 2356745d7..9bc8c87e7 100644 --- a/server/middlewares/validators/user-subscriptions.ts +++ b/server/middlewares/validators/user-subscriptions.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { body, param, query } from 'express-validator/check' | ||
4 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
6 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 5 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 7002de20d..db03dc231 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -1,9 +1,8 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import 'express-validator' | 3 | import { body, param } from 'express-validator' |
4 | import { body, param } from 'express-validator/check' | ||
5 | import { omit } from 'lodash' | 4 | import { omit } from 'lodash' |
6 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc' |
7 | import { | 6 | import { |
8 | isUserAdminFlagsValid, | 7 | isUserAdminFlagsValid, |
9 | isUserAutoPlayVideoValid, | 8 | isUserAutoPlayVideoValid, |
@@ -358,7 +357,7 @@ const usersVerifyEmailValidator = [ | |||
358 | .not().isEmpty().withMessage('Should have a valid verification string'), | 357 | .not().isEmpty().withMessage('Should have a valid verification string'), |
359 | body('isPendingEmail') | 358 | body('isPendingEmail') |
360 | .optional() | 359 | .optional() |
361 | .toBoolean(), | 360 | .customSanitizer(toIntOrNull), |
362 | 361 | ||
363 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 362 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
364 | logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params }) | 363 | logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params }) |
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts index 8f77c9fbd..43e5652fa 100644 --- a/server/middlewares/validators/utils.ts +++ b/server/middlewares/validators/utils.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query, validationResult } from 'express-validator/check' | 2 | import { query, validationResult } from 'express-validator' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | 4 | ||
5 | function areValidationErrors (req: express.Request, res: express.Response) { | 5 | function areValidationErrors (req: express.Request, res: express.Response) { |
diff --git a/server/middlewares/validators/videos/video-abuses.ts b/server/middlewares/validators/videos/video-abuses.ts index e176e01af..e27d91bb1 100644 --- a/server/middlewares/validators/videos/video-abuses.ts +++ b/server/middlewares/validators/videos/video-abuses.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { body, param } from 'express-validator' |
3 | import { body, param } from 'express-validator/check' | ||
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
6 | import { areValidationErrors } from '../utils' | 5 | import { areValidationErrors } from '../utils' |
diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index db59427c7..3e8c5b30c 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator/check' | 2 | import { body, param, query } from 'express-validator' |
3 | import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' |
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { areValidationErrors } from '../utils' | 5 | import { areValidationErrors } from '../utils' |
6 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' | 6 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' |
@@ -24,7 +24,7 @@ const videosBlacklistAddValidator = [ | |||
24 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | 24 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), |
25 | body('unfederate') | 25 | body('unfederate') |
26 | .optional() | 26 | .optional() |
27 | .toBoolean() | 27 | .customSanitizer(toBooleanOrNull) |
28 | .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'), | 28 | .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'), |
29 | body('reason') | 29 | body('reason') |
30 | .optional() | 30 | .optional() |
diff --git a/server/middlewares/validators/videos/video-captions.ts b/server/middlewares/validators/videos/video-captions.ts index f8739e27f..f5610222a 100644 --- a/server/middlewares/validators/videos/video-captions.ts +++ b/server/middlewares/validators/videos/video-captions.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { areValidationErrors } from '../utils' | 2 | import { areValidationErrors } from '../utils' |
3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
4 | import { body, param } from 'express-validator/check' | 4 | import { body, param } from 'express-validator' |
5 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 5 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
6 | import { UserRight } from '../../../../shared' | 6 | import { UserRight } from '../../../../shared' |
7 | import { logger } from '../../../helpers/logger' | 7 | import { logger } from '../../../helpers/logger' |
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index c1065b898..3ee5064fc 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator' |
3 | import { UserRight } from '../../../../shared' | 3 | import { UserRight } from '../../../../shared' |
4 | import { | 4 | import { |
5 | isVideoChannelDescriptionValid, | 5 | isVideoChannelDescriptionValid, |
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index 1e3e42833..83a0c24b0 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator' |
3 | import { UserRight } from '../../../../shared' | 3 | import { UserRight } from '../../../../shared' |
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' | 5 | import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' |
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index 8b0dd8960..318dad100 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator/check' | 2 | import { body } from 'express-validator' |
3 | import { isIdValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' |
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { areValidationErrors } from '../utils' | 5 | import { areValidationErrors } from '../utils' |
6 | import { getCommonVideoEditAttributes } from './videos' | 6 | import { getCommonVideoEditAttributes } from './videos' |
@@ -13,7 +13,7 @@ import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares' | |||
13 | 13 | ||
14 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | 14 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ |
15 | body('channelId') | 15 | body('channelId') |
16 | .toInt() | 16 | .customSanitizer(toIntOrNull) |
17 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 17 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
18 | body('targetUrl') | 18 | body('targetUrl') |
19 | .optional() | 19 | .optional() |
diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts index 638122a2e..2e9c8aa33 100644 --- a/server/middlewares/validators/videos/video-playlists.ts +++ b/server/middlewares/validators/videos/video-playlists.ts | |||
@@ -1,12 +1,20 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query, ValidationChain } from 'express-validator/check' | 2 | import { body, param, query, ValidationChain } from 'express-validator' |
3 | import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared' | 3 | import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared' |
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { UserModel } from '../../../models/account/user' | 5 | import { UserModel } from '../../../models/account/user' |
6 | import { areValidationErrors } from '../utils' | 6 | import { areValidationErrors } from '../utils' |
7 | import { isVideoImage } from '../../../helpers/custom-validators/videos' | 7 | import { isVideoImage } from '../../../helpers/custom-validators/videos' |
8 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 8 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
9 | import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' | 9 | import { |
10 | isArrayOf, | ||
11 | isIdOrUUIDValid, | ||
12 | isIdValid, | ||
13 | isUUIDValid, | ||
14 | toIntArray, | ||
15 | toIntOrNull, | ||
16 | toValueOrNull | ||
17 | } from '../../../helpers/custom-validators/misc' | ||
10 | import { | 18 | import { |
11 | isVideoPlaylistDescriptionValid, | 19 | isVideoPlaylistDescriptionValid, |
12 | isVideoPlaylistNameValid, | 20 | isVideoPlaylistNameValid, |
@@ -374,12 +382,11 @@ function getCommonPlaylistEditAttributes () { | |||
374 | .custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'), | 382 | .custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'), |
375 | body('privacy') | 383 | body('privacy') |
376 | .optional() | 384 | .optional() |
377 | .toInt() | 385 | .customSanitizer(toIntOrNull) |
378 | .custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'), | 386 | .custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'), |
379 | body('videoChannelId') | 387 | body('videoChannelId') |
380 | .optional() | 388 | .optional() |
381 | .customSanitizer(toValueOrNull) | 389 | .customSanitizer(toIntOrNull) |
382 | .toInt() | ||
383 | ] as (ValidationChain | express.Handler)[] | 390 | ] as (ValidationChain | express.Handler)[] |
384 | } | 391 | } |
385 | 392 | ||
diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index 5bb3f4a51..4021cfecc 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { body, param, query } from 'express-validator/check' | ||
4 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
5 | import { isRatingValid } from '../../../helpers/custom-validators/video-rates' | 4 | import { isRatingValid } from '../../../helpers/custom-validators/video-rates' |
6 | import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' | 5 | import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' |
diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts index 6f4a1f3e0..ace62be5c 100644 --- a/server/middlewares/validators/videos/video-shares.ts +++ b/server/middlewares/validators/videos/video-shares.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { param } from 'express-validator' |
3 | import { param } from 'express-validator/check' | ||
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
6 | import { VideoShareModel } from '../../../models/video/video-share' | 5 | import { VideoShareModel } from '../../../models/video/video-share' |
diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts index a0b530c75..d6ca1d341 100644 --- a/server/middlewares/validators/videos/video-watch.ts +++ b/server/middlewares/validators/videos/video-watch.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { body, param } from 'express-validator/check' | 1 | import { body, param } from 'express-validator' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators/misc' |
4 | import { areValidationErrors } from '../utils' | 4 | import { areValidationErrors } from '../utils' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
6 | import { doesVideoExist } from '../../../helpers/middlewares' | 6 | import { doesVideoExist } from '../../../helpers/middlewares' |
@@ -8,7 +8,7 @@ import { doesVideoExist } from '../../../helpers/middlewares' | |||
8 | const videoWatchingValidator = [ | 8 | const videoWatchingValidator = [ |
9 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 9 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
10 | body('currentTime') | 10 | body('currentTime') |
11 | .toInt() | 11 | .customSanitizer(toIntOrNull) |
12 | .isInt().withMessage('Should have correct current time'), | 12 | .isInt().withMessage('Should have correct current time'), |
13 | 13 | ||
14 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 14 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 8f5e5c95c..27dfe91ca 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import { body, param, query, ValidationChain } from 'express-validator' |
3 | import { body, param, query, ValidationChain } from 'express-validator/check' | ||
4 | import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' | 3 | import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' |
5 | import { | 4 | import { |
6 | isBooleanValid, | 5 | isBooleanValid, |
@@ -9,6 +8,7 @@ import { | |||
9 | isIdValid, | 8 | isIdValid, |
10 | isUUIDValid, | 9 | isUUIDValid, |
11 | toArray, | 10 | toArray, |
11 | toBooleanOrNull, | ||
12 | toIntOrNull, | 12 | toIntOrNull, |
13 | toValueOrNull | 13 | toValueOrNull |
14 | } from '../../../helpers/custom-validators/misc' | 14 | } from '../../../helpers/custom-validators/misc' |
@@ -53,7 +53,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([ | |||
53 | ), | 53 | ), |
54 | body('name').custom(isVideoNameValid).withMessage('Should have a valid name'), | 54 | body('name').custom(isVideoNameValid).withMessage('Should have a valid name'), |
55 | body('channelId') | 55 | body('channelId') |
56 | .toInt() | 56 | .customSanitizer(toIntOrNull) |
57 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 57 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
58 | 58 | ||
59 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 59 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
@@ -101,7 +101,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ | |||
101 | .custom(isVideoNameValid).withMessage('Should have a valid name'), | 101 | .custom(isVideoNameValid).withMessage('Should have a valid name'), |
102 | body('channelId') | 102 | body('channelId') |
103 | .optional() | 103 | .optional() |
104 | .toInt() | 104 | .customSanitizer(toIntOrNull) |
105 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 105 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
106 | 106 | ||
107 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 107 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
@@ -307,15 +307,15 @@ function getCommonVideoEditAttributes () { | |||
307 | .custom(isVideoLanguageValid).withMessage('Should have a valid language'), | 307 | .custom(isVideoLanguageValid).withMessage('Should have a valid language'), |
308 | body('nsfw') | 308 | body('nsfw') |
309 | .optional() | 309 | .optional() |
310 | .toBoolean() | 310 | .customSanitizer(toBooleanOrNull) |
311 | .custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), | 311 | .custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), |
312 | body('waitTranscoding') | 312 | body('waitTranscoding') |
313 | .optional() | 313 | .optional() |
314 | .toBoolean() | 314 | .customSanitizer(toBooleanOrNull) |
315 | .custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'), | 315 | .custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'), |
316 | body('privacy') | 316 | body('privacy') |
317 | .optional() | 317 | .optional() |
318 | .toInt() | 318 | .customSanitizer(toValueOrNull) |
319 | .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), | 319 | .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), |
320 | body('description') | 320 | body('description') |
321 | .optional() | 321 | .optional() |
@@ -331,16 +331,16 @@ function getCommonVideoEditAttributes () { | |||
331 | .custom(isVideoTagsValid).withMessage('Should have correct tags'), | 331 | .custom(isVideoTagsValid).withMessage('Should have correct tags'), |
332 | body('commentsEnabled') | 332 | body('commentsEnabled') |
333 | .optional() | 333 | .optional() |
334 | .toBoolean() | 334 | .customSanitizer(toBooleanOrNull) |
335 | .custom(isBooleanValid).withMessage('Should have comments enabled boolean'), | 335 | .custom(isBooleanValid).withMessage('Should have comments enabled boolean'), |
336 | body('downloadEnabled') | 336 | body('downloadEnabled') |
337 | .optional() | 337 | .optional() |
338 | .toBoolean() | 338 | .customSanitizer(toBooleanOrNull) |
339 | .custom(isBooleanValid).withMessage('Should have downloading enabled boolean'), | 339 | .custom(isBooleanValid).withMessage('Should have downloading enabled boolean'), |
340 | body('originallyPublishedAt') | 340 | body('originallyPublishedAt') |
341 | .optional() | 341 | .optional() |
342 | .customSanitizer(toValueOrNull) | 342 | .customSanitizer(toValueOrNull) |
343 | .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'), | 343 | .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'), |
344 | body('scheduleUpdate') | 344 | body('scheduleUpdate') |
345 | .optional() | 345 | .optional() |
346 | .customSanitizer(toValueOrNull), | 346 | .customSanitizer(toValueOrNull), |
@@ -349,7 +349,7 @@ function getCommonVideoEditAttributes () { | |||
349 | .custom(isDateValid).withMessage('Should have a valid schedule update date'), | 349 | .custom(isDateValid).withMessage('Should have a valid schedule update date'), |
350 | body('scheduleUpdate.privacy') | 350 | body('scheduleUpdate.privacy') |
351 | .optional() | 351 | .optional() |
352 | .toInt() | 352 | .customSanitizer(toValueOrNull) |
353 | .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy') | 353 | .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy') |
354 | ] as (ValidationChain | express.Handler)[] | 354 | ] as (ValidationChain | express.Handler)[] |
355 | } | 355 | } |
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts index 63a1678ec..d7cfe17f0 100644 --- a/server/middlewares/validators/webfinger.ts +++ b/server/middlewares/validators/webfinger.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator/check' | 2 | import { query } from 'express-validator' |
3 | import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger' | 3 | import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { ActorModel } from '../../models/activitypub/actor' | 5 | import { ActorModel } from '../../models/activitypub/actor' |
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 8ff115e7b..231d5cc85 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts | |||
@@ -91,7 +91,7 @@ describe('Test video imports API validator', function () { | |||
91 | support: 'my super support text', | 91 | support: 'my super support text', |
92 | tags: [ 'tag1', 'tag2' ], | 92 | tags: [ 'tag1', 'tag2' ], |
93 | privacy: VideoPrivacy.PUBLIC, | 93 | privacy: VideoPrivacy.PUBLIC, |
94 | channelId: channelId | 94 | channelId |
95 | } | 95 | } |
96 | }) | 96 | }) |
97 | 97 | ||