Fix express validator
This commit is contained in:
parent
b4c19345c1
commit
c8861d5dc0
|
@ -39,7 +39,7 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy {
|
||||||
|
|
||||||
const scrollObservable = fromEvent(this.container || window, 'scroll')
|
const scrollObservable = fromEvent(this.container || window, 'scroll')
|
||||||
.pipe(
|
.pipe(
|
||||||
startWith(null),
|
startWith(null as string), // FIXME: typings
|
||||||
throttleTime(200, undefined, throttleOptions),
|
throttleTime(200, undefined, throttleOptions),
|
||||||
map(() => this.getScrollInfo()),
|
map(() => this.getScrollInfo()),
|
||||||
distinctUntilChanged((o1, o2) => o1.current === o2.current),
|
distinctUntilChanged((o1, o2) => o1.current === o2.current),
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
<div class="video-info-privacy">
|
<div class="video-info-privacy">
|
||||||
<ng-container *ngIf="displayOptions.privacyText">{{ video.privacy.label }}</ng-container>
|
<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>
|
<ng-container *ngIf="displayOptions.state">{{ getStateLabel(video) }}</ng-container>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -255,10 +255,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
)
|
)
|
||||||
|
|
||||||
// Video did change
|
// Video did change
|
||||||
forkJoin(
|
forkJoin([
|
||||||
videoObs,
|
videoObs,
|
||||||
this.videoCaptionService.listCaptions(videoId)
|
this.videoCaptionService.listCaptions(videoId)
|
||||||
)
|
])
|
||||||
.pipe(
|
.pipe(
|
||||||
// If 401, the video is private or blacklisted so redirect to 404
|
// If 401, the video is private or blacklisted so redirect to 404
|
||||||
catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ]))
|
catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ]))
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import 'express-validator'
|
|
||||||
import { isUserDescriptionValid, isUserUsernameValid } from './users'
|
import { isUserDescriptionValid, isUserUsernameValid } from './users'
|
||||||
import { exists } from './misc'
|
import { exists } from './misc'
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'multer'
|
import 'multer'
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import { sep } from 'path'
|
import { sep } from 'path'
|
||||||
|
import toBoolean = require('validator/lib/toBoolean')
|
||||||
|
|
||||||
function exists (value: any) {
|
function exists (value: any) {
|
||||||
return value !== undefined && value !== null
|
return value !== undefined && value !== null
|
||||||
|
@ -46,9 +47,21 @@ function isBooleanValid (value: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function toIntOrNull (value: string) {
|
function toIntOrNull (value: string) {
|
||||||
if (value === 'null') return null
|
const v = toValueOrNull(value)
|
||||||
|
|
||||||
return validator.toInt(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 toBoolean(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
function toValueOrNull (value: string) {
|
function toValueOrNull (value: string) {
|
||||||
|
@ -110,6 +123,7 @@ export {
|
||||||
isIdOrUUIDValid,
|
isIdOrUUIDValid,
|
||||||
isDateValid,
|
isDateValid,
|
||||||
toValueOrNull,
|
toValueOrNull,
|
||||||
|
toBooleanOrNull,
|
||||||
isBooleanValid,
|
isBooleanValid,
|
||||||
toIntOrNull,
|
toIntOrNull,
|
||||||
toArray,
|
toArray,
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import 'express-validator'
|
|
||||||
|
|
||||||
import { isArray } from './misc'
|
import { isArray } from './misc'
|
||||||
|
|
||||||
function isNumberArray (value: any) {
|
function isNumberArray (value: any) {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import 'express-validator'
|
import { exists, isArray } from './misc'
|
||||||
|
|
||||||
import { isArray, exists } from './misc'
|
|
||||||
import { isTestInstance } from '../core-utils'
|
import { isTestInstance } from '../core-utils'
|
||||||
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import 'express-validator'
|
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import { UserRole } from '../../../shared'
|
import { UserRole } from '../../../shared'
|
||||||
import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants'
|
import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants'
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import 'express-validator'
|
|
||||||
import 'multer'
|
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
||||||
import { exists } from './misc'
|
import { exists } from './misc'
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import 'express-validator'
|
|
||||||
import 'multer'
|
import 'multer'
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import 'express-validator'
|
|
||||||
import 'multer'
|
import 'multer'
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants'
|
import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants'
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
import { Response } from 'express'
|
|
||||||
import 'express-validator'
|
|
||||||
import { values } from 'lodash'
|
import { values } from 'lodash'
|
||||||
import 'multer'
|
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import { UserRight, VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared'
|
import { VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared'
|
||||||
import {
|
import {
|
||||||
CONSTRAINTS_FIELDS,
|
CONSTRAINTS_FIELDS,
|
||||||
MIMETYPES,
|
MIMETYPES,
|
||||||
|
@ -13,9 +10,7 @@ import {
|
||||||
VIDEO_RATE_TYPES,
|
VIDEO_RATE_TYPES,
|
||||||
VIDEO_STATES
|
VIDEO_STATES
|
||||||
} from '../../initializers/constants'
|
} from '../../initializers/constants'
|
||||||
import { VideoModel } from '../../models/video/video'
|
|
||||||
import { exists, isArray, isDateValid, isFileValid } from './misc'
|
import { exists, isArray, isDateValid, isFileValid } from './misc'
|
||||||
import { UserModel } from '../../models/account/user'
|
|
||||||
import * as magnetUtil from 'magnet-uri'
|
import * as magnetUtil from 'magnet-uri'
|
||||||
|
|
||||||
const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
|
const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import * as OAuthServer from 'express-oauth-server'
|
import * as OAuthServer from 'express-oauth-server'
|
||||||
import 'express-validator'
|
|
||||||
import { OAUTH_LIFETIME } from '../initializers/constants'
|
import { OAUTH_LIFETIME } from '../initializers/constants'
|
||||||
import { logger } from '../helpers/logger'
|
import { logger } from '../helpers/logger'
|
||||||
import { Socket } from 'socket.io'
|
import { Socket } from 'socket.io'
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import 'express-validator'
|
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
|
|
||||||
import { PAGINATION } from '../initializers/constants'
|
import { PAGINATION } from '../initializers/constants'
|
||||||
|
|
||||||
function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) {
|
function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
|
||||||
import { getHostWithPort } from '../helpers/express-utils'
|
import { getHostWithPort } from '../helpers/express-utils'
|
||||||
|
|
||||||
function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
|
function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
|
||||||
import { SortType } from '../models/utils'
|
import { SortType } from '../models/utils'
|
||||||
|
|
||||||
function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) {
|
function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
|
||||||
import { UserRight } from '../../shared'
|
import { UserRight } from '../../shared'
|
||||||
import { logger } from '../helpers/logger'
|
import { logger } from '../helpers/logger'
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { param } from 'express-validator/check'
|
import { param } from 'express-validator'
|
||||||
import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
|
import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { body } from 'express-validator/check'
|
import { body } from 'express-validator'
|
||||||
import {
|
import {
|
||||||
isSignatureCreatorValid, isSignatureTypeValid,
|
isSignatureCreatorValid, isSignatureTypeValid,
|
||||||
isSignatureValueValid
|
isSignatureValueValid
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { body } from 'express-validator/check'
|
import { body } from 'express-validator'
|
||||||
import { isAvatarFile } from '../../helpers/custom-validators/users'
|
import { isAvatarFile } from '../../helpers/custom-validators/users'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { body, param } from 'express-validator/check'
|
import { body, param } from 'express-validator'
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
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 { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { CustomConfig } from '../../../shared/models/server/custom-config.model'
|
import { CustomConfig } from '../../../shared/models/server/custom-config.model'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
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 { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
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 { isTestInstance } from '../../helpers/core-utils'
|
||||||
import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers'
|
import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { param } from 'express-validator/check'
|
import { param } from 'express-validator'
|
||||||
import { isValidJobState } from '../../helpers/custom-validators/jobs'
|
import { isValidJobState } from '../../helpers/custom-validators/jobs'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as express from 'express'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { isDateValid } from '../../helpers/custom-validators/misc'
|
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'
|
import { isValidLogLevel } from '../../helpers/custom-validators/logs'
|
||||||
|
|
||||||
const getLogsValidator = [
|
const getLogsValidator = [
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { query } from 'express-validator/check'
|
import { query } from 'express-validator'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { isTestInstance } from '../../helpers/core-utils'
|
import { isTestInstance } from '../../helpers/core-utils'
|
||||||
import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
|
import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { query } from 'express-validator/check'
|
import { query } from 'express-validator'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import * as express from 'express'
|
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 { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { isNpmPluginNameValid, isPluginNameValid, isPluginTypeValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
|
import { isNpmPluginNameValid, isPluginNameValid, isPluginTypeValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
|
||||||
import { PluginManager } from '../../lib/plugins/plugin-manager'
|
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 { PluginModel } from '../../models/server/plugin'
|
||||||
import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model'
|
import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model'
|
||||||
import { PluginType } from '../../../shared/models/plugins/plugin.type'
|
import { PluginType } from '../../../shared/models/plugins/plugin.type'
|
||||||
|
@ -39,7 +39,7 @@ const listPluginsValidator = [
|
||||||
.custom(isPluginTypeValid).withMessage('Should have a valid plugin type'),
|
.custom(isPluginTypeValid).withMessage('Should have a valid plugin type'),
|
||||||
query('uninstalled')
|
query('uninstalled')
|
||||||
.optional()
|
.optional()
|
||||||
.toBoolean()
|
.customSanitizer(toBooleanOrNull)
|
||||||
.custom(isBooleanValid).withMessage('Should have a valid uninstalled attribute'),
|
.custom(isBooleanValid).withMessage('Should have a valid uninstalled attribute'),
|
||||||
|
|
||||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
import { body, param } from 'express-validator'
|
||||||
import { body, param } from 'express-validator/check'
|
import { exists, isBooleanValid, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
|
||||||
import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc'
|
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
|
import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
|
||||||
|
@ -68,7 +67,7 @@ const videoPlaylistRedundancyGetValidator = [
|
||||||
const updateServerRedundancyValidator = [
|
const updateServerRedundancyValidator = [
|
||||||
param('host').custom(isHostValid).withMessage('Should have a valid host'),
|
param('host').custom(isHostValid).withMessage('Should have a valid host'),
|
||||||
body('redundancyAllowed')
|
body('redundancyAllowed')
|
||||||
.toBoolean()
|
.customSanitizer(toBooleanOrNull)
|
||||||
.custom(isBooleanValid).withMessage('Should have a valid redundancyAllowed attribute'),
|
.custom(isBooleanValid).withMessage('Should have a valid redundancyAllowed attribute'),
|
||||||
|
|
||||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { query } from 'express-validator/check'
|
import { query } from 'express-validator'
|
||||||
import { isDateValid } from '../../helpers/custom-validators/misc'
|
import { isDateValid } from '../../helpers/custom-validators/misc'
|
||||||
|
|
||||||
const videosSearchValidator = [
|
const videosSearchValidator = [
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers'
|
import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers'
|
||||||
import { ServerModel } from '../../models/server/server'
|
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 { isUserDisplayNameValid } from '../../helpers/custom-validators/users'
|
||||||
import { Emailer } from '../../lib/emailer'
|
import { Emailer } from '../../lib/emailer'
|
||||||
import { Redis } from '../../lib/redis'
|
import { Redis } from '../../lib/redis'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { param } from 'express-validator/check'
|
import { param } from 'express-validator'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
|
import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
import { body } from 'express-validator'
|
||||||
import { body } from 'express-validator/check'
|
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { isDateValid } from '../../helpers/custom-validators/misc'
|
import { isDateValid } from '../../helpers/custom-validators/misc'
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
import { body, query } from 'express-validator'
|
||||||
import { body, query } from 'express-validator/check'
|
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
|
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 = [
|
const listUserNotificationsValidator = [
|
||||||
query('unread')
|
query('unread')
|
||||||
.optional()
|
.optional()
|
||||||
.toBoolean()
|
.customSanitizer(toBooleanOrNull)
|
||||||
.isBoolean().withMessage('Should have a valid unread boolean'),
|
.isBoolean().withMessage('Should have a valid unread boolean'),
|
||||||
|
|
||||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
import { body, param, query } from 'express-validator'
|
||||||
import { body, param, query } from 'express-validator/check'
|
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { ActorFollowModel } from '../../models/activitypub/actor-follow'
|
import { ActorFollowModel } from '../../models/activitypub/actor-follow'
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import * as Bluebird from 'bluebird'
|
import * as Bluebird from 'bluebird'
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
import { body, param } from 'express-validator'
|
||||||
import { body, param } from 'express-validator/check'
|
|
||||||
import { omit } from 'lodash'
|
import { omit } from 'lodash'
|
||||||
import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
|
import { isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc'
|
||||||
import {
|
import {
|
||||||
isUserAdminFlagsValid,
|
isUserAdminFlagsValid,
|
||||||
isUserAutoPlayVideoValid,
|
isUserAutoPlayVideoValid,
|
||||||
|
@ -358,7 +357,7 @@ const usersVerifyEmailValidator = [
|
||||||
.not().isEmpty().withMessage('Should have a valid verification string'),
|
.not().isEmpty().withMessage('Should have a valid verification string'),
|
||||||
body('isPendingEmail')
|
body('isPendingEmail')
|
||||||
.optional()
|
.optional()
|
||||||
.toBoolean(),
|
.customSanitizer(toIntOrNull),
|
||||||
|
|
||||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params })
|
logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params })
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { query, validationResult } from 'express-validator/check'
|
import { query, validationResult } from 'express-validator'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
|
|
||||||
function areValidationErrors (req: express.Request, res: express.Response) {
|
function areValidationErrors (req: express.Request, res: express.Response) {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
import { body, param } from 'express-validator'
|
||||||
import { body, param } from 'express-validator/check'
|
|
||||||
import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
|
import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
import { areValidationErrors } from '../utils'
|
import { areValidationErrors } from '../utils'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { body, param, query } from 'express-validator/check'
|
import { body, param, query } from 'express-validator'
|
||||||
import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
|
import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
import { areValidationErrors } from '../utils'
|
import { areValidationErrors } from '../utils'
|
||||||
import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist'
|
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'),
|
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
||||||
body('unfederate')
|
body('unfederate')
|
||||||
.optional()
|
.optional()
|
||||||
.toBoolean()
|
.customSanitizer(toBooleanOrNull)
|
||||||
.custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),
|
.custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),
|
||||||
body('reason')
|
body('reason')
|
||||||
.optional()
|
.optional()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { areValidationErrors } from '../utils'
|
import { areValidationErrors } from '../utils'
|
||||||
import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
|
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 { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
|
||||||
import { UserRight } from '../../../../shared'
|
import { UserRight } from '../../../../shared'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { body, param } from 'express-validator/check'
|
import { body, param } from 'express-validator'
|
||||||
import { UserRight } from '../../../../shared'
|
import { UserRight } from '../../../../shared'
|
||||||
import {
|
import {
|
||||||
isVideoChannelDescriptionValid,
|
isVideoChannelDescriptionValid,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { body, param } from 'express-validator/check'
|
import { body, param } from 'express-validator'
|
||||||
import { UserRight } from '../../../../shared'
|
import { UserRight } from '../../../../shared'
|
||||||
import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
|
import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
|
||||||
import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments'
|
import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { body } from 'express-validator/check'
|
import { body } from 'express-validator'
|
||||||
import { isIdValid } from '../../../helpers/custom-validators/misc'
|
import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
import { areValidationErrors } from '../utils'
|
import { areValidationErrors } from '../utils'
|
||||||
import { getCommonVideoEditAttributes } from './videos'
|
import { getCommonVideoEditAttributes } from './videos'
|
||||||
|
@ -13,7 +13,7 @@ import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares'
|
||||||
|
|
||||||
const videoImportAddValidator = getCommonVideoEditAttributes().concat([
|
const videoImportAddValidator = getCommonVideoEditAttributes().concat([
|
||||||
body('channelId')
|
body('channelId')
|
||||||
.toInt()
|
.customSanitizer(toIntOrNull)
|
||||||
.custom(isIdValid).withMessage('Should have correct video channel id'),
|
.custom(isIdValid).withMessage('Should have correct video channel id'),
|
||||||
body('targetUrl')
|
body('targetUrl')
|
||||||
.optional()
|
.optional()
|
||||||
|
|
|
@ -1,12 +1,20 @@
|
||||||
import * as express from 'express'
|
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 { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
import { UserModel } from '../../../models/account/user'
|
import { UserModel } from '../../../models/account/user'
|
||||||
import { areValidationErrors } from '../utils'
|
import { areValidationErrors } from '../utils'
|
||||||
import { isVideoImage } from '../../../helpers/custom-validators/videos'
|
import { isVideoImage } from '../../../helpers/custom-validators/videos'
|
||||||
import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
|
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 {
|
import {
|
||||||
isVideoPlaylistDescriptionValid,
|
isVideoPlaylistDescriptionValid,
|
||||||
isVideoPlaylistNameValid,
|
isVideoPlaylistNameValid,
|
||||||
|
@ -374,12 +382,11 @@ function getCommonPlaylistEditAttributes () {
|
||||||
.custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'),
|
.custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'),
|
||||||
body('privacy')
|
body('privacy')
|
||||||
.optional()
|
.optional()
|
||||||
.toInt()
|
.customSanitizer(toIntOrNull)
|
||||||
.custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'),
|
.custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'),
|
||||||
body('videoChannelId')
|
body('videoChannelId')
|
||||||
.optional()
|
.optional()
|
||||||
.customSanitizer(toValueOrNull)
|
.customSanitizer(toIntOrNull)
|
||||||
.toInt()
|
|
||||||
] as (ValidationChain | express.Handler)[]
|
] as (ValidationChain | express.Handler)[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
import { body, param, query } from 'express-validator'
|
||||||
import { body, param, query } from 'express-validator/check'
|
|
||||||
import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
|
import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
|
||||||
import { isRatingValid } from '../../../helpers/custom-validators/video-rates'
|
import { isRatingValid } from '../../../helpers/custom-validators/video-rates'
|
||||||
import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos'
|
import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos'
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
import { param } from 'express-validator'
|
||||||
import { param } from 'express-validator/check'
|
|
||||||
import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
|
import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
import { VideoShareModel } from '../../../models/video/video-share'
|
import { VideoShareModel } from '../../../models/video/video-share'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { body, param } from 'express-validator/check'
|
import { body, param } from 'express-validator'
|
||||||
import * as express from 'express'
|
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 { areValidationErrors } from '../utils'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
import { doesVideoExist } from '../../../helpers/middlewares'
|
import { doesVideoExist } from '../../../helpers/middlewares'
|
||||||
|
@ -8,7 +8,7 @@ import { doesVideoExist } from '../../../helpers/middlewares'
|
||||||
const videoWatchingValidator = [
|
const videoWatchingValidator = [
|
||||||
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
||||||
body('currentTime')
|
body('currentTime')
|
||||||
.toInt()
|
.customSanitizer(toIntOrNull)
|
||||||
.isInt().withMessage('Should have correct current time'),
|
.isInt().withMessage('Should have correct current time'),
|
||||||
|
|
||||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
import { body, param, query, ValidationChain } from 'express-validator'
|
||||||
import { body, param, query, ValidationChain } from 'express-validator/check'
|
|
||||||
import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
|
import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
|
||||||
import {
|
import {
|
||||||
isBooleanValid,
|
isBooleanValid,
|
||||||
|
@ -9,6 +8,7 @@ import {
|
||||||
isIdValid,
|
isIdValid,
|
||||||
isUUIDValid,
|
isUUIDValid,
|
||||||
toArray,
|
toArray,
|
||||||
|
toBooleanOrNull,
|
||||||
toIntOrNull,
|
toIntOrNull,
|
||||||
toValueOrNull
|
toValueOrNull
|
||||||
} from '../../../helpers/custom-validators/misc'
|
} from '../../../helpers/custom-validators/misc'
|
||||||
|
@ -53,7 +53,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([
|
||||||
),
|
),
|
||||||
body('name').custom(isVideoNameValid).withMessage('Should have a valid name'),
|
body('name').custom(isVideoNameValid).withMessage('Should have a valid name'),
|
||||||
body('channelId')
|
body('channelId')
|
||||||
.toInt()
|
.customSanitizer(toIntOrNull)
|
||||||
.custom(isIdValid).withMessage('Should have correct video channel id'),
|
.custom(isIdValid).withMessage('Should have correct video channel id'),
|
||||||
|
|
||||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
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'),
|
.custom(isVideoNameValid).withMessage('Should have a valid name'),
|
||||||
body('channelId')
|
body('channelId')
|
||||||
.optional()
|
.optional()
|
||||||
.toInt()
|
.customSanitizer(toIntOrNull)
|
||||||
.custom(isIdValid).withMessage('Should have correct video channel id'),
|
.custom(isIdValid).withMessage('Should have correct video channel id'),
|
||||||
|
|
||||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
@ -307,15 +307,15 @@ function getCommonVideoEditAttributes () {
|
||||||
.custom(isVideoLanguageValid).withMessage('Should have a valid language'),
|
.custom(isVideoLanguageValid).withMessage('Should have a valid language'),
|
||||||
body('nsfw')
|
body('nsfw')
|
||||||
.optional()
|
.optional()
|
||||||
.toBoolean()
|
.customSanitizer(toBooleanOrNull)
|
||||||
.custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),
|
.custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),
|
||||||
body('waitTranscoding')
|
body('waitTranscoding')
|
||||||
.optional()
|
.optional()
|
||||||
.toBoolean()
|
.customSanitizer(toBooleanOrNull)
|
||||||
.custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'),
|
.custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'),
|
||||||
body('privacy')
|
body('privacy')
|
||||||
.optional()
|
.optional()
|
||||||
.toInt()
|
.customSanitizer(toValueOrNull)
|
||||||
.custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
|
.custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
|
||||||
body('description')
|
body('description')
|
||||||
.optional()
|
.optional()
|
||||||
|
@ -331,11 +331,11 @@ function getCommonVideoEditAttributes () {
|
||||||
.custom(isVideoTagsValid).withMessage('Should have correct tags'),
|
.custom(isVideoTagsValid).withMessage('Should have correct tags'),
|
||||||
body('commentsEnabled')
|
body('commentsEnabled')
|
||||||
.optional()
|
.optional()
|
||||||
.toBoolean()
|
.customSanitizer(toBooleanOrNull)
|
||||||
.custom(isBooleanValid).withMessage('Should have comments enabled boolean'),
|
.custom(isBooleanValid).withMessage('Should have comments enabled boolean'),
|
||||||
body('downloadEnabled')
|
body('downloadEnabled')
|
||||||
.optional()
|
.optional()
|
||||||
.toBoolean()
|
.customSanitizer(toBooleanOrNull)
|
||||||
.custom(isBooleanValid).withMessage('Should have downloading enabled boolean'),
|
.custom(isBooleanValid).withMessage('Should have downloading enabled boolean'),
|
||||||
body('originallyPublishedAt')
|
body('originallyPublishedAt')
|
||||||
.optional()
|
.optional()
|
||||||
|
@ -349,7 +349,7 @@ function getCommonVideoEditAttributes () {
|
||||||
.custom(isDateValid).withMessage('Should have a valid schedule update date'),
|
.custom(isDateValid).withMessage('Should have a valid schedule update date'),
|
||||||
body('scheduleUpdate.privacy')
|
body('scheduleUpdate.privacy')
|
||||||
.optional()
|
.optional()
|
||||||
.toInt()
|
.customSanitizer(toValueOrNull)
|
||||||
.custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy')
|
.custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy')
|
||||||
] as (ValidationChain | express.Handler)[]
|
] as (ValidationChain | express.Handler)[]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { query } from 'express-validator/check'
|
import { query } from 'express-validator'
|
||||||
import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger'
|
import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { ActorModel } from '../../models/activitypub/actor'
|
import { ActorModel } from '../../models/activitypub/actor'
|
||||||
|
|
|
@ -91,7 +91,7 @@ describe('Test video imports API validator', function () {
|
||||||
support: 'my super support text',
|
support: 'my super support text',
|
||||||
tags: [ 'tag1', 'tag2' ],
|
tags: [ 'tag1', 'tag2' ],
|
||||||
privacy: VideoPrivacy.PUBLIC,
|
privacy: VideoPrivacy.PUBLIC,
|
||||||
channelId: channelId
|
channelId
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue