aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/video-channels.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-10-01 15:18:07 +0200
committerChocobozzz <me@florianbigard.com>2018-10-01 15:20:14 +0200
commit601527d7953a83d6ad08dbb2ed8ac02851beaf1e (patch)
tree8c2c83b526a6f137043ef3c7c06cb13e03b94438 /server/middlewares/validators/video-channels.ts
parent7361c401b17415931f25f3a2137ba22a06a6a4ed (diff)
downloadPeerTube-601527d7953a83d6ad08dbb2ed8ac02851beaf1e.tar.gz
PeerTube-601527d7953a83d6ad08dbb2ed8ac02851beaf1e.tar.zst
PeerTube-601527d7953a83d6ad08dbb2ed8ac02851beaf1e.zip
Check video channel name is unique on our instance
Diffstat (limited to 'server/middlewares/validators/video-channels.ts')
-rw-r--r--server/middlewares/validators/video-channels.ts11
1 files changed, 10 insertions, 1 deletions
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts
index 79587b028..56a347b39 100644
--- a/server/middlewares/validators/video-channels.ts
+++ b/server/middlewares/validators/video-channels.ts
@@ -14,6 +14,7 @@ import { UserModel } from '../../models/account/user'
14import { VideoChannelModel } from '../../models/video/video-channel' 14import { VideoChannelModel } from '../../models/video/video-channel'
15import { areValidationErrors } from './utils' 15import { areValidationErrors } from './utils'
16import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' 16import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor'
17import { ActorModel } from '../../models/activitypub/actor'
17 18
18const listVideoAccountChannelsValidator = [ 19const listVideoAccountChannelsValidator = [
19 param('accountName').exists().withMessage('Should have a valid account name'), 20 param('accountName').exists().withMessage('Should have a valid account name'),
@@ -34,11 +35,19 @@ const videoChannelsAddValidator = [
34 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), 35 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'),
35 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), 36 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'),
36 37
37 (req: express.Request, res: express.Response, next: express.NextFunction) => { 38 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
38 logger.debug('Checking videoChannelsAdd parameters', { parameters: req.body }) 39 logger.debug('Checking videoChannelsAdd parameters', { parameters: req.body })
39 40
40 if (areValidationErrors(req, res)) return 41 if (areValidationErrors(req, res)) return
41 42
43 const actor = await ActorModel.loadLocalByName(req.body.name)
44 if (actor) {
45 res.status(409)
46 .send({ error: 'Another actor (account/channel) with this name on this instance already exists or has already existed.' })
47 .end()
48 return false
49 }
50
42 return next() 51 return next()
43 } 52 }
44] 53]