ActivityPub-federated video streaming platform using P2P directly in your web browser
Fix express validator
Chocobozzzc8861d5dc043
diff --git a/client/src/app/shared/video/infinite-scroller.directive.ts b/client/src/app/shared/video/infinite-scroller.directive.tsindex 5f8a1dd6e4..b1e88882c5 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 {const scrollObservable = fromEvent(this.container || window, 'scroll').pipe(- startWith(null),+ startWith(null as string), // FIXME: typingsthrottleTime(200, undefined, throttleOptions),map(() => this.getScrollInfo()),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.htmlindex 7af0f11138..51ca1393df 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 @@<div class="video-info-privacy"><ng-container *ngIf="displayOptions.privacyText">{{ video.privacy.label }}</ng-container>- <ng-container *ngIf="displayOptions.privacyText && displayOptions.state"> - </ng-container>+ <ng-container *ngIf="displayOptions.privacyText && getStateLabel(video)"> - </ng-container><ng-container *ngIf="displayOptions.state">{{ getStateLabel(video) }}</ng-container></div>diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.tsindex 027c2b026c..0d499d47f7 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 {)// Video did change- forkJoin(+ forkJoin([videoObs,this.videoCaptionService.listCaptions(videoId)- )+ ]).pipe(// If 401, the video is private or blacklisted so redirect to 404catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ]))diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.tsindex be196d2a46..f676669ea6 100644--- a/server/helpers/custom-validators/accounts.ts+++ b/server/helpers/custom-validators/accounts.ts@@ -1,4 +1,3 @@-import 'express-validator'import { isUserDescriptionValid, isUserUsernameValid } from './users'import { exists } from './misc'diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.tsindex 3ef38fce1d..1b7e004310 100644--- a/server/helpers/custom-validators/misc.ts+++ b/server/helpers/custom-validators/misc.ts@@ -1,6 +1,7 @@import 'multer'import * as validator from 'validator'import { sep } from 'path'+import toBoolean = require('validator/lib/toBoolean')function exists (value: any) {return value !== undefined && value !== null@@ -46,9 +47,21 @@ function isBooleanValid (value: any) {}function toIntOrNull (value: string) {- if (value === 'null') return null+ const v = toValueOrNull(value)++ if (v === null || v === undefined) return v+ if (typeof v === 'number') return v++ return validator.toInt(v)+}++function toBooleanOrNull (value: any) {+ const v = toValueOrNull(value)++ if (v === null || v === undefined) return v+ if (typeof v === 'boolean') return v- return validator.toInt(value)+ return toBoolean(v)}function toValueOrNull (value: string) {@@ -110,6 +123,7 @@ export {isIdOrUUIDValid,isDateValid,toValueOrNull,+ toBooleanOrNull,isBooleanValid,toIntOrNull,toArray,diff --git a/server/helpers/custom-validators/search.ts b/server/helpers/custom-validators/search.tsindex 15b389a58e..ee732b15aa 100644--- a/server/helpers/custom-validators/search.ts+++ b/server/helpers/custom-validators/search.ts@@ -1,6 +1,4 @@import * as validator from 'validator'-import 'express-validator'-import { isArray } from './misc'function isNumberArray (value: any) {diff --git a/server/helpers/custom-validators/servers.ts b/server/helpers/custom-validators/servers.tsindex 5c8bf0d2d5..7ced36fd33 100644--- a/server/helpers/custom-validators/servers.ts+++ b/server/helpers/custom-validators/servers.ts@@ -1,7 +1,5 @@import * as validator from 'validator'-import 'express-validator'--import { isArray, exists } from './misc'+import { exists, isArray } from './misc'import { isTestInstance } from '../core-utils'import { CONSTRAINTS_FIELDS } from '../../initializers/constants'diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.tsindex 738d5cbbf9..c56ae14ef8 100644--- a/server/helpers/custom-validators/users.ts+++ b/server/helpers/custom-validators/users.ts@@ -1,4 +1,3 @@-import 'express-validator'import * as validator from 'validator'import { UserRole } from '../../../shared'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.tsindex f55f0c8ef1..6c52dc093e 100644--- a/server/helpers/custom-validators/video-channels.ts+++ b/server/helpers/custom-validators/video-channels.ts@@ -1,5 +1,3 @@-import 'express-validator'-import 'multer'import * as validator from 'validator'import { CONSTRAINTS_FIELDS } from '../../initializers/constants'import { exists } from './misc'diff --git a/server/helpers/custom-validators/video-comments.ts b/server/helpers/custom-validators/video-comments.tsindex 0707e2af26..8a7cd7105d 100644--- a/server/helpers/custom-validators/video-comments.ts+++ b/server/helpers/custom-validators/video-comments.ts@@ -1,4 +1,3 @@-import 'express-validator'import 'multer'import * as validator from 'validator'import { CONSTRAINTS_FIELDS } from '../../initializers/constants'diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.tsindex f4235e2fa7..8820c4c0aa 100644--- a/server/helpers/custom-validators/video-imports.ts+++ b/server/helpers/custom-validators/video-imports.ts@@ -1,4 +1,3 @@-import 'express-validator'import 'multer'import * as validator from 'validator'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.tsindex 157e1a8e3e..9ab1ef2343 100644--- a/server/helpers/custom-validators/videos.ts+++ b/server/helpers/custom-validators/videos.ts@@ -1,9 +1,6 @@-import { Response } from 'express'-import 'express-validator'import { values } from 'lodash'-import 'multer'import * as validator from 'validator'-import { UserRight, VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared'+import { VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared'import {CONSTRAINTS_FIELDS,MIMETYPES,@@ -13,9 +10,7 @@ import {VIDEO_RATE_TYPES,VIDEO_STATES} from '../../initializers/constants'-import { VideoModel } from '../../models/video/video'import { exists, isArray, isDateValid, isFileValid } from './misc'-import { UserModel } from '../../models/account/user'import * as magnetUtil from 'magnet-uri'const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOSdiff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.tsindex 2b4e300e44..77fb305dd5 100644--- a/server/middlewares/oauth.ts+++ b/server/middlewares/oauth.ts@@ -1,6 +1,5 @@import * as express from 'express'import * as OAuthServer from 'express-oauth-server'-import 'express-validator'import { OAUTH_LIFETIME } from '../initializers/constants'import { logger } from '../helpers/logger'import { Socket } from 'socket.io'diff --git a/server/middlewares/pagination.ts b/server/middlewares/pagination.tsindex 83304940f3..043869303f 100644--- a/server/middlewares/pagination.ts+++ b/server/middlewares/pagination.ts@@ -1,6 +1,4 @@-import 'express-validator'import * as express from 'express'-import { PAGINATION } from '../initializers/constants'function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) {diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.tsindex c52f4685b9..9c0af443a5 100644--- a/server/middlewares/servers.ts+++ b/server/middlewares/servers.ts@@ -1,5 +1,4 @@import * as express from 'express'-import 'express-validator'import { getHostWithPort } from '../helpers/express-utils'function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.tsindex 6507aa5b8b..8c27e82379 100644--- a/server/middlewares/sort.ts+++ b/server/middlewares/sort.ts@@ -1,5 +1,4 @@import * as express from 'express'-import 'express-validator'import { SortType } from '../models/utils'function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) {diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.tsindex 498e3d6777..4da7b98025 100644--- a/server/middlewares/user-right.ts+++ b/server/middlewares/user-right.ts@@ -1,5 +1,4 @@import * as express from 'express'-import 'express-validator'import { UserRight } from '../../shared'import { logger } from '../helpers/logger'diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.tsindex 67e4bf8cca..cbdcef2fd4 100644--- a/server/middlewares/validators/account.ts+++ b/server/middlewares/validators/account.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { param } from 'express-validator/check'+import { param } from 'express-validator'import { isAccountNameValid } from '../../helpers/custom-validators/accounts'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.tsindex be14e92eac..02b191480b 100644--- a/server/middlewares/validators/activitypub/signature.ts+++ b/server/middlewares/validators/activitypub/signature.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { body } from 'express-validator/check'+import { body } from 'express-validator'import {isSignatureCreatorValid, isSignatureTypeValid,isSignatureValueValiddiff --git a/server/middlewares/validators/avatar.ts b/server/middlewares/validators/avatar.tsindex bab3ed118c..8623d07e80 100644--- a/server/middlewares/validators/avatar.ts+++ b/server/middlewares/validators/avatar.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { body } from 'express-validator/check'+import { body } from 'express-validator'import { isAvatarFile } from '../../helpers/custom-validators/users'import { areValidationErrors } from './utils'import { CONSTRAINTS_FIELDS } from '../../initializers/constants'diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.tsindex 63d95e9e04..47a0b1a1c1 100644--- a/server/middlewares/validators/blocklist.ts+++ b/server/middlewares/validators/blocklist.ts@@ -1,4 +1,4 @@-import { body, param } from 'express-validator/check'+import { body, param } from 'express-validator'import * as express from 'express'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.tsindex 9c43da1654..5059ed0f29 100644--- a/server/middlewares/validators/config.ts+++ b/server/middlewares/validators/config.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { body } from 'express-validator/check'+import { body } from 'express-validator'import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users'import { logger } from '../../helpers/logger'import { CustomConfig } from '../../../shared/models/server/custom-config.model'diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.tsindex fa130121fd..1bef9891b3 100644--- a/server/middlewares/validators/feeds.ts+++ b/server/middlewares/validators/feeds.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { param, query } from 'express-validator/check'+import { param, query } from 'express-validator'import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.tsindex 2e5a023077..c3d772297e 100644--- a/server/middlewares/validators/follows.ts+++ b/server/middlewares/validators/follows.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { body, param } from 'express-validator/check'+import { body, param } from 'express-validator'import { isTestInstance } from '../../helpers/core-utils'import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers'import { logger } from '../../helpers/logger'diff --git a/server/middlewares/validators/jobs.ts b/server/middlewares/validators/jobs.tsindex 2f8b1738c5..41a8d68996 100644--- a/server/middlewares/validators/jobs.ts+++ b/server/middlewares/validators/jobs.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { param } from 'express-validator/check'+import { param } from 'express-validator'import { isValidJobState } from '../../helpers/custom-validators/jobs'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'diff --git a/server/middlewares/validators/logs.ts b/server/middlewares/validators/logs.tsindex 7380c6edde..07f3f552f4 100644--- a/server/middlewares/validators/logs.ts+++ b/server/middlewares/validators/logs.ts@@ -2,7 +2,7 @@ import * as express from 'express'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'import { isDateValid } from '../../helpers/custom-validators/misc'-import { query } from 'express-validator/check'+import { query } from 'express-validator'import { isValidLogLevel } from '../../helpers/custom-validators/logs'const getLogsValidator = [diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.tsindex 5053199803..24ba5569dc 100644--- a/server/middlewares/validators/oembed.ts+++ b/server/middlewares/validators/oembed.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { query } from 'express-validator/check'+import { query } from 'express-validator'import { join } from 'path'import { isTestInstance } from '../../helpers/core-utils'import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.tsindex e1ed8cd65c..80ae57c0bb 100644--- a/server/middlewares/validators/pagination.ts+++ b/server/middlewares/validators/pagination.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { query } from 'express-validator/check'+import { query } from 'express-validator'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.tsindex dc3f1454ae..910d03c293 100644--- a/server/middlewares/validators/plugins.ts+++ b/server/middlewares/validators/plugins.ts@@ -1,10 +1,10 @@import * as express from 'express'-import { body, param, query } from 'express-validator/check'+import { body, param, query } from 'express-validator'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'import { isNpmPluginNameValid, isPluginNameValid, isPluginTypeValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'import { PluginManager } from '../../lib/plugins/plugin-manager'-import { isBooleanValid, isSafePath } from '../../helpers/custom-validators/misc'+import { isBooleanValid, isSafePath, toBooleanOrNull } from '../../helpers/custom-validators/misc'import { PluginModel } from '../../models/server/plugin'import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model'import { PluginType } from '../../../shared/models/plugins/plugin.type'@@ -39,7 +39,7 @@ const listPluginsValidator = [.custom(isPluginTypeValid).withMessage('Should have a valid plugin type'),query('uninstalled').optional()- .toBoolean()+ .customSanitizer(toBooleanOrNull).custom(isBooleanValid).withMessage('Should have a valid uninstalled attribute'),(req: express.Request, res: express.Response, next: express.NextFunction) => {diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.tsindex edc53a6b26..1fdac0e4e2 100644--- a/server/middlewares/validators/redundancy.ts+++ b/server/middlewares/validators/redundancy.ts@@ -1,7 +1,6 @@import * as express from 'express'-import 'express-validator'-import { body, param } from 'express-validator/check'-import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc'+import { body, param } from 'express-validator'+import { exists, isBooleanValid, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'@@ -68,7 +67,7 @@ const videoPlaylistRedundancyGetValidator = [const updateServerRedundancyValidator = [param('host').custom(isHostValid).withMessage('Should have a valid host'),body('redundancyAllowed')- .toBoolean()+ .customSanitizer(toBooleanOrNull).custom(isBooleanValid).withMessage('Should have a valid redundancyAllowed attribute'),async (req: express.Request, res: express.Response, next: express.NextFunction) => {diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.tsindex 7816d229c6..5a3c83f2ca 100644--- a/server/middlewares/validators/search.ts+++ b/server/middlewares/validators/search.ts@@ -1,7 +1,7 @@import * as express from 'express'import { areValidationErrors } from './utils'import { logger } from '../../helpers/logger'-import { query } from 'express-validator/check'+import { query } from 'express-validator'import { isDateValid } from '../../helpers/custom-validators/misc'const videosSearchValidator = [diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.tsindex 6eff8e9ee9..f6812647bf 100644--- a/server/middlewares/validators/server.ts+++ b/server/middlewares/validators/server.ts@@ -3,7 +3,7 @@ import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers'import { ServerModel } from '../../models/server/server'-import { body } from 'express-validator/check'+import { body } from 'express-validator'import { isUserDisplayNameValid } from '../../helpers/custom-validators/users'import { Emailer } from '../../lib/emailer'import { Redis } from '../../lib/redis'diff --git a/server/middlewares/validators/themes.ts b/server/middlewares/validators/themes.tsindex 642f2df78f..24a9673f78 100644--- a/server/middlewares/validators/themes.ts+++ b/server/middlewares/validators/themes.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { param } from 'express-validator/check'+import { param } from 'express-validator'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'diff --git a/server/middlewares/validators/user-history.ts b/server/middlewares/validators/user-history.tsindex 418313d098..2f1d3cc413 100644--- a/server/middlewares/validators/user-history.ts+++ b/server/middlewares/validators/user-history.ts@@ -1,6 +1,5 @@import * as express from 'express'-import 'express-validator'-import { body } from 'express-validator/check'+import { body } from 'express-validator'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'import { isDateValid } from '../../helpers/custom-validators/misc'diff --git a/server/middlewares/validators/user-notifications.ts b/server/middlewares/validators/user-notifications.tsindex 3ded8d8cf9..308b326552 100644--- a/server/middlewares/validators/user-notifications.ts+++ b/server/middlewares/validators/user-notifications.ts@@ -1,15 +1,14 @@import * as express from 'express'-import 'express-validator'-import { body, query } from 'express-validator/check'+import { body, query } from 'express-validator'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'-import { isNotEmptyIntArray } from '../../helpers/custom-validators/misc'+import { isNotEmptyIntArray, toBooleanOrNull } from '../../helpers/custom-validators/misc'const listUserNotificationsValidator = [query('unread').optional()- .toBoolean()+ .customSanitizer(toBooleanOrNull).isBoolean().withMessage('Should have a valid unread boolean'),(req: express.Request, res: express.Response, next: express.NextFunction) => {diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.tsindex 2356745d7e..9bc8c87e74 100644--- a/server/middlewares/validators/user-subscriptions.ts+++ b/server/middlewares/validators/user-subscriptions.ts@@ -1,6 +1,5 @@import * as express from 'express'-import 'express-validator'-import { body, param, query } from 'express-validator/check'+import { body, param, query } from 'express-validator'import { logger } from '../../helpers/logger'import { areValidationErrors } from './utils'import { ActorFollowModel } from '../../models/activitypub/actor-follow'diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.tsindex 7002de20d6..db03dc2316 100644--- a/server/middlewares/validators/users.ts+++ b/server/middlewares/validators/users.ts@@ -1,9 +1,8 @@import * as Bluebird from 'bluebird'import * as express from 'express'-import 'express-validator'-import { body, param } from 'express-validator/check'+import { body, param } from 'express-validator'import { omit } from 'lodash'-import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'+import { isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc'import {isUserAdminFlagsValid,isUserAutoPlayVideoValid,@@ -358,7 +357,7 @@ const usersVerifyEmailValidator = [.not().isEmpty().withMessage('Should have a valid verification string'),body('isPendingEmail').optional()- .toBoolean(),+ .customSanitizer(toIntOrNull),async (req: express.Request, res: express.Response, next: express.NextFunction) => {logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params })diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.tsindex 8f77c9fbd8..43e5652fa2 100644--- a/server/middlewares/validators/utils.ts+++ b/server/middlewares/validators/utils.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { query, validationResult } from 'express-validator/check'+import { query, validationResult } from 'express-validator'import { logger } from '../../helpers/logger'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.tsindex e176e01af6..e27d91bb12 100644--- a/server/middlewares/validators/videos/video-abuses.ts+++ b/server/middlewares/validators/videos/video-abuses.ts@@ -1,6 +1,5 @@import * as express from 'express'-import 'express-validator'-import { body, param } from 'express-validator/check'+import { body, param } from 'express-validator'import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'import { logger } from '../../../helpers/logger'import { areValidationErrors } from '../utils'diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.tsindex db59427c74..3e8c5b30c9 100644--- a/server/middlewares/validators/videos/video-blacklist.ts+++ b/server/middlewares/validators/videos/video-blacklist.ts@@ -1,6 +1,6 @@import * as express from 'express'-import { body, param, query } from 'express-validator/check'-import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'+import { body, param, query } from 'express-validator'+import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc'import { logger } from '../../../helpers/logger'import { areValidationErrors } from '../utils'import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist'@@ -24,7 +24,7 @@ const videosBlacklistAddValidator = [param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),body('unfederate').optional()- .toBoolean()+ .customSanitizer(toBooleanOrNull).custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),body('reason').optional()diff --git a/server/middlewares/validators/videos/video-captions.ts b/server/middlewares/validators/videos/video-captions.tsindex f8739e27f8..f5610222ac 100644--- a/server/middlewares/validators/videos/video-captions.ts+++ b/server/middlewares/validators/videos/video-captions.ts@@ -1,7 +1,7 @@import * as express from 'express'import { areValidationErrors } from '../utils'import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'-import { body, param } from 'express-validator/check'+import { body, param } from 'express-validator'import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'import { UserRight } from '../../../../shared'import { logger } from '../../../helpers/logger'diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.tsindex c1065b898b..3ee5064fc6 100644--- a/server/middlewares/validators/videos/video-channels.ts+++ b/server/middlewares/validators/videos/video-channels.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { body, param } from 'express-validator/check'+import { body, param } from 'express-validator'import { UserRight } from '../../../../shared'import {isVideoChannelDescriptionValid,diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.tsindex 1e3e42833c..83a0c24b03 100644--- a/server/middlewares/validators/videos/video-comments.ts+++ b/server/middlewares/validators/videos/video-comments.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { body, param } from 'express-validator/check'+import { body, param } from 'express-validator'import { UserRight } from '../../../../shared'import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'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.tsindex 8b0dd8960d..318dad1008 100644--- a/server/middlewares/validators/videos/video-imports.ts+++ b/server/middlewares/validators/videos/video-imports.ts@@ -1,6 +1,6 @@import * as express from 'express'-import { body } from 'express-validator/check'-import { isIdValid } from '../../../helpers/custom-validators/misc'+import { body } from 'express-validator'+import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc'import { logger } from '../../../helpers/logger'import { areValidationErrors } from '../utils'import { getCommonVideoEditAttributes } from './videos'@@ -13,7 +13,7 @@ import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares'const videoImportAddValidator = getCommonVideoEditAttributes().concat([body('channelId')- .toInt()+ .customSanitizer(toIntOrNull).custom(isIdValid).withMessage('Should have correct video channel id'),body('targetUrl').optional()diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.tsindex 638122a2e8..2e9c8aa334 100644--- a/server/middlewares/validators/videos/video-playlists.ts+++ b/server/middlewares/validators/videos/video-playlists.ts@@ -1,12 +1,20 @@import * as express from 'express'-import { body, param, query, ValidationChain } from 'express-validator/check'+import { body, param, query, ValidationChain } from 'express-validator'import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared'import { logger } from '../../../helpers/logger'import { UserModel } from '../../../models/account/user'import { areValidationErrors } from '../utils'import { isVideoImage } from '../../../helpers/custom-validators/videos'import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'-import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc'+import {+ isArrayOf,+ isIdOrUUIDValid,+ isIdValid,+ isUUIDValid,+ toIntArray,+ toIntOrNull,+ toValueOrNull+} from '../../../helpers/custom-validators/misc'import {isVideoPlaylistDescriptionValid,isVideoPlaylistNameValid,@@ -374,12 +382,11 @@ function getCommonPlaylistEditAttributes () {.custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'),body('privacy').optional()- .toInt()+ .customSanitizer(toIntOrNull).custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'),body('videoChannelId').optional()- .customSanitizer(toValueOrNull)- .toInt()+ .customSanitizer(toIntOrNull)] as (ValidationChain | express.Handler)[]}diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.tsindex 5bb3f4a517..4021cfecc8 100644--- a/server/middlewares/validators/videos/video-rates.ts+++ b/server/middlewares/validators/videos/video-rates.ts@@ -1,6 +1,5 @@import * as express from 'express'-import 'express-validator'-import { body, param, query } from 'express-validator/check'+import { body, param, query } from 'express-validator'import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'import { isRatingValid } from '../../../helpers/custom-validators/video-rates'import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos'diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.tsindex 6f4a1f3e06..ace62be5ca 100644--- a/server/middlewares/validators/videos/video-shares.ts+++ b/server/middlewares/validators/videos/video-shares.ts@@ -1,6 +1,5 @@import * as express from 'express'-import 'express-validator'-import { param } from 'express-validator/check'+import { param } from 'express-validator'import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'import { logger } from '../../../helpers/logger'import { VideoShareModel } from '../../../models/video/video-share'diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.tsindex a0b530c755..d6ca1d3412 100644--- a/server/middlewares/validators/videos/video-watch.ts+++ b/server/middlewares/validators/videos/video-watch.ts@@ -1,6 +1,6 @@-import { body, param } from 'express-validator/check'+import { body, param } from 'express-validator'import * as express from 'express'-import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'+import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators/misc'import { areValidationErrors } from '../utils'import { logger } from '../../../helpers/logger'import { doesVideoExist } from '../../../helpers/middlewares'@@ -8,7 +8,7 @@ import { doesVideoExist } from '../../../helpers/middlewares'const videoWatchingValidator = [param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),body('currentTime')- .toInt()+ .customSanitizer(toIntOrNull).isInt().withMessage('Should have correct current time'),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.tsindex 8f5e5c95c2..27dfe91ca9 100644--- a/server/middlewares/validators/videos/videos.ts+++ b/server/middlewares/validators/videos/videos.ts@@ -1,6 +1,5 @@import * as express from 'express'-import 'express-validator'-import { body, param, query, ValidationChain } from 'express-validator/check'+import { body, param, query, ValidationChain } from 'express-validator'import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'import {isBooleanValid,@@ -9,6 +8,7 @@ import {isIdValid,isUUIDValid,toArray,+ toBooleanOrNull,toIntOrNull,toValueOrNull} from '../../../helpers/custom-validators/misc'@@ -53,7 +53,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([),body('name').custom(isVideoNameValid).withMessage('Should have a valid name'),body('channelId')- .toInt()+ .customSanitizer(toIntOrNull).custom(isIdValid).withMessage('Should have correct video channel id'),async (req: express.Request, res: express.Response, next: express.NextFunction) => {@@ -101,7 +101,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([.custom(isVideoNameValid).withMessage('Should have a valid name'),body('channelId').optional()- .toInt()+ .customSanitizer(toIntOrNull).custom(isIdValid).withMessage('Should have correct video channel id'),async (req: express.Request, res: express.Response, next: express.NextFunction) => {@@ -307,15 +307,15 @@ function getCommonVideoEditAttributes () {.custom(isVideoLanguageValid).withMessage('Should have a valid language'),body('nsfw').optional()- .toBoolean()+ .customSanitizer(toBooleanOrNull).custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),body('waitTranscoding').optional()- .toBoolean()+ .customSanitizer(toBooleanOrNull).custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'),body('privacy').optional()- .toInt()+ .customSanitizer(toValueOrNull).custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),body('description').optional()@@ -331,16 +331,16 @@ function getCommonVideoEditAttributes () {.custom(isVideoTagsValid).withMessage('Should have correct tags'),body('commentsEnabled').optional()- .toBoolean()+ .customSanitizer(toBooleanOrNull).custom(isBooleanValid).withMessage('Should have comments enabled boolean'),body('downloadEnabled').optional()- .toBoolean()+ .customSanitizer(toBooleanOrNull).custom(isBooleanValid).withMessage('Should have downloading enabled boolean'),body('originallyPublishedAt')- .optional()- .customSanitizer(toValueOrNull)- .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'),+ .optional()+ .customSanitizer(toValueOrNull)+ .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'),body('scheduleUpdate').optional().customSanitizer(toValueOrNull),@@ -349,7 +349,7 @@ function getCommonVideoEditAttributes () {.custom(isDateValid).withMessage('Should have a valid schedule update date'),body('scheduleUpdate.privacy').optional()- .toInt()+ .customSanitizer(toValueOrNull).custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy')] as (ValidationChain | express.Handler)[]}diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.tsindex 63a1678ec9..d7cfe17f00 100644--- a/server/middlewares/validators/webfinger.ts+++ b/server/middlewares/validators/webfinger.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { query } from 'express-validator/check'+import { query } from 'express-validator'import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger'import { logger } from '../../helpers/logger'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.tsindex 8ff115e7bb..231d5cc856 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 () {support: 'my super support text',tags: [ 'tag1', 'tag2' ],privacy: VideoPrivacy.PUBLIC,- channelId: channelId+ channelId}})