aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/video-channels.ts')
-rw-r--r--server/middlewares/validators/video-channels.ts23
1 files changed, 12 insertions, 11 deletions
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts
index d354c7e05..79587b028 100644
--- a/server/middlewares/validators/video-channels.ts
+++ b/server/middlewares/validators/video-channels.ts
@@ -2,18 +2,18 @@ import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { UserRight } from '../../../shared' 3import { UserRight } from '../../../shared'
4import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' 4import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { 5import {
7 isLocalVideoChannelNameExist, 6 isLocalVideoChannelNameExist,
8 isVideoChannelDescriptionValid, 7 isVideoChannelDescriptionValid,
9 isVideoChannelExist,
10 isVideoChannelNameValid, 8 isVideoChannelNameValid,
9 isVideoChannelNameWithHostExist,
11 isVideoChannelSupportValid 10 isVideoChannelSupportValid
12} from '../../helpers/custom-validators/video-channels' 11} from '../../helpers/custom-validators/video-channels'
13import { logger } from '../../helpers/logger' 12import { logger } from '../../helpers/logger'
14import { UserModel } from '../../models/account/user' 13import { UserModel } from '../../models/account/user'
15import { VideoChannelModel } from '../../models/video/video-channel' 14import { VideoChannelModel } from '../../models/video/video-channel'
16import { areValidationErrors } from './utils' 15import { areValidationErrors } from './utils'
16import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor'
17 17
18const listVideoAccountChannelsValidator = [ 18const listVideoAccountChannelsValidator = [
19 param('accountName').exists().withMessage('Should have a valid account name'), 19 param('accountName').exists().withMessage('Should have a valid account name'),
@@ -29,6 +29,7 @@ const listVideoAccountChannelsValidator = [
29] 29]
30 30
31const videoChannelsAddValidator = [ 31const videoChannelsAddValidator = [
32 body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'),
32 body('displayName').custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), 33 body('displayName').custom(isVideoChannelNameValid).withMessage('Should have a valid display name'),
33 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), 34 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'),
34 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), 35 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'),
@@ -43,7 +44,7 @@ const videoChannelsAddValidator = [
43] 44]
44 45
45const videoChannelsUpdateValidator = [ 46const videoChannelsUpdateValidator = [
46 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 47 param('nameWithHost').exists().withMessage('Should have an video channel name with host'),
47 body('displayName').optional().custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), 48 body('displayName').optional().custom(isVideoChannelNameValid).withMessage('Should have a valid display name'),
48 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), 49 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'),
49 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), 50 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'),
@@ -52,7 +53,7 @@ const videoChannelsUpdateValidator = [
52 logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body }) 53 logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body })
53 54
54 if (areValidationErrors(req, res)) return 55 if (areValidationErrors(req, res)) return
55 if (!await isVideoChannelExist(req.params.id, res)) return 56 if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return
56 57
57 // We need to make additional checks 58 // We need to make additional checks
58 if (res.locals.videoChannel.Actor.isOwned() === false) { 59 if (res.locals.videoChannel.Actor.isOwned() === false) {
@@ -72,13 +73,13 @@ const videoChannelsUpdateValidator = [
72] 73]
73 74
74const videoChannelsRemoveValidator = [ 75const videoChannelsRemoveValidator = [
75 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 76 param('nameWithHost').exists().withMessage('Should have an video channel name with host'),
76 77
77 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 78 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
78 logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params }) 79 logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params })
79 80
80 if (areValidationErrors(req, res)) return 81 if (areValidationErrors(req, res)) return
81 if (!await isVideoChannelExist(req.params.id, res)) return 82 if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return
82 83
83 if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return 84 if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return
84 if (!await checkVideoChannelIsNotTheLastOne(res)) return 85 if (!await checkVideoChannelIsNotTheLastOne(res)) return
@@ -87,15 +88,15 @@ const videoChannelsRemoveValidator = [
87 } 88 }
88] 89]
89 90
90const videoChannelsGetValidator = [ 91const videoChannelsNameWithHostValidator = [
91 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 92 param('nameWithHost').exists().withMessage('Should have an video channel name with host'),
92 93
93 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 94 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
94 logger.debug('Checking videoChannelsGet parameters', { parameters: req.params }) 95 logger.debug('Checking videoChannelsNameWithHostValidator parameters', { parameters: req.params })
95 96
96 if (areValidationErrors(req, res)) return 97 if (areValidationErrors(req, res)) return
97 98
98 if (!await isVideoChannelExist(req.params.id, res)) return 99 if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return
99 100
100 return next() 101 return next()
101 } 102 }
@@ -121,7 +122,7 @@ export {
121 videoChannelsAddValidator, 122 videoChannelsAddValidator,
122 videoChannelsUpdateValidator, 123 videoChannelsUpdateValidator,
123 videoChannelsRemoveValidator, 124 videoChannelsRemoveValidator,
124 videoChannelsGetValidator, 125 videoChannelsNameWithHostValidator,
125 localVideoChannelValidator 126 localVideoChannelValidator
126} 127}
127 128