diff options
author | Chocobozzz <me@florianbigard.com> | 2019-11-29 16:35:27 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-11-29 16:35:27 +0100 |
commit | a3ce4ae847b749d4cb2ebebb4134264b7c58dcc5 (patch) | |
tree | 9c3ba1efaa65d6abc8525d38e1c0862b5fa67648 /server/middlewares/validators/videos | |
parent | 1689176a7bff6edd90d162994cccec2e4bfe9a45 (diff) | |
download | PeerTube-a3ce4ae847b749d4cb2ebebb4134264b7c58dcc5.tar.gz PeerTube-a3ce4ae847b749d4cb2ebebb4134264b7c58dcc5.tar.zst PeerTube-a3ce4ae847b749d4cb2ebebb4134264b7c58dcc5.zip |
Limit channel numbers
We can't load too much channels in selects and it helps to prevent actor
name squatting
Diffstat (limited to 'server/middlewares/validators/videos')
-rw-r--r-- | server/middlewares/validators/videos/video-channels.ts | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index d21274527..ce2d61d49 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts | |||
@@ -14,6 +14,7 @@ import { ActorModel } from '../../../models/activitypub/actor' | |||
14 | import { isBooleanValid } from '../../../helpers/custom-validators/misc' | 14 | import { isBooleanValid } from '../../../helpers/custom-validators/misc' |
15 | import { doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../../../helpers/middlewares' | 15 | import { doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../../../helpers/middlewares' |
16 | import { MChannelAccountDefault, MUser } from '@server/typings/models' | 16 | import { MChannelAccountDefault, MUser } from '@server/typings/models' |
17 | import { VIDEO_CHANNELS } from '@server/initializers/constants' | ||
17 | 18 | ||
18 | const videoChannelsAddValidator = [ | 19 | const videoChannelsAddValidator = [ |
19 | body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), | 20 | body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), |
@@ -34,6 +35,14 @@ const videoChannelsAddValidator = [ | |||
34 | return false | 35 | return false |
35 | } | 36 | } |
36 | 37 | ||
38 | const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id) | ||
39 | if (count > VIDEO_CHANNELS.MAX_PER_USER) { | ||
40 | res.status(400) | ||
41 | .send({ error: `You cannot create more than ${VIDEO_CHANNELS.MAX_PER_USER} channels` }) | ||
42 | .end() | ||
43 | return false | ||
44 | } | ||
45 | |||
37 | return next() | 46 | return next() |
38 | } | 47 | } |
39 | ] | 48 | ] |