aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-25 16:23:44 +0200
committerChocobozzz <me@florianbigard.com>2019-07-25 16:23:44 +0200
commitc8861d5dc0436ef4342ce517241e3591fa256a13 (patch)
treeca47c09d1f7f1e2aa62c684d576faa938eb47af7 /server/middlewares/validators/videos
parentb4c19345c19b0891142c69308cd9447f2161188c (diff)
downloadPeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.tar.gz
PeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.tar.zst
PeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.zip
Fix express validator
Diffstat (limited to 'server/middlewares/validators/videos')
-rw-r--r--server/middlewares/validators/videos/video-abuses.ts3
-rw-r--r--server/middlewares/validators/videos/video-blacklist.ts6
-rw-r--r--server/middlewares/validators/videos/video-captions.ts2
-rw-r--r--server/middlewares/validators/videos/video-channels.ts2
-rw-r--r--server/middlewares/validators/videos/video-comments.ts2
-rw-r--r--server/middlewares/validators/videos/video-imports.ts6
-rw-r--r--server/middlewares/validators/videos/video-playlists.ts17
-rw-r--r--server/middlewares/validators/videos/video-rates.ts3
-rw-r--r--server/middlewares/validators/videos/video-shares.ts3
-rw-r--r--server/middlewares/validators/videos/video-watch.ts6
-rw-r--r--server/middlewares/validators/videos/videos.ts26
11 files changed, 40 insertions, 36 deletions
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { body, param } from 'express-validator'
3import { body, param } from 'express-validator/check'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
6import { areValidationErrors } from '../utils' 5import { 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query } from 'express-validator/check' 2import { body, param, query } from 'express-validator'
3import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' 3import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { areValidationErrors } from '../utils' 5import { areValidationErrors } from '../utils'
6import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' 6import { 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { areValidationErrors } from '../utils' 2import { areValidationErrors } from '../utils'
3import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
4import { body, param } from 'express-validator/check' 4import { body, param } from 'express-validator'
5import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 5import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
6import { UserRight } from '../../../../shared' 6import { UserRight } from '../../../../shared'
7import { logger } from '../../../helpers/logger' 7import { 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator'
3import { UserRight } from '../../../../shared' 3import { UserRight } from '../../../../shared'
4import { 4import {
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator'
3import { UserRight } from '../../../../shared' 3import { UserRight } from '../../../../shared'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' 5import { 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator/check' 2import { body } from 'express-validator'
3import { isIdValid } from '../../../helpers/custom-validators/misc' 3import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { areValidationErrors } from '../utils' 5import { areValidationErrors } from '../utils'
6import { getCommonVideoEditAttributes } from './videos' 6import { getCommonVideoEditAttributes } from './videos'
@@ -13,7 +13,7 @@ import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares'
13 13
14const videoImportAddValidator = getCommonVideoEditAttributes().concat([ 14const 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query, ValidationChain } from 'express-validator/check' 2import { body, param, query, ValidationChain } from 'express-validator'
3import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared' 3import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { UserModel } from '../../../models/account/user' 5import { UserModel } from '../../../models/account/user'
6import { areValidationErrors } from '../utils' 6import { areValidationErrors } from '../utils'
7import { isVideoImage } from '../../../helpers/custom-validators/videos' 7import { isVideoImage } from '../../../helpers/custom-validators/videos'
8import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 8import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
9import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' 9import {
10 isArrayOf,
11 isIdOrUUIDValid,
12 isIdValid,
13 isUUIDValid,
14 toIntArray,
15 toIntOrNull,
16 toValueOrNull
17} from '../../../helpers/custom-validators/misc'
10import { 18import {
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { body, param, query } from 'express-validator'
3import { body, param, query } from 'express-validator/check'
4import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
5import { isRatingValid } from '../../../helpers/custom-validators/video-rates' 4import { isRatingValid } from '../../../helpers/custom-validators/video-rates'
6import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' 5import { 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { param } from 'express-validator'
3import { param } from 'express-validator/check'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
6import { VideoShareModel } from '../../../models/video/video-share' 5import { 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 @@
1import { body, param } from 'express-validator/check' 1import { body, param } from 'express-validator'
2import * as express from 'express' 2import * as express from 'express'
3import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators/misc'
4import { areValidationErrors } from '../utils' 4import { areValidationErrors } from '../utils'
5import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
6import { doesVideoExist } from '../../../helpers/middlewares' 6import { doesVideoExist } from '../../../helpers/middlewares'
@@ -8,7 +8,7 @@ import { doesVideoExist } from '../../../helpers/middlewares'
8const videoWatchingValidator = [ 8const 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { body, param, query, ValidationChain } from 'express-validator'
3import { body, param, query, ValidationChain } from 'express-validator/check'
4import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' 3import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
5import { 4import {
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}