diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-12-07 14:32:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 14:32:36 +0100 |
commit | 2d53be0267acc49cda46707b885096193a1f4e9c (patch) | |
tree | 887061a34bc67f40acbb96a6278f9544bf83caeb /server/middlewares/validators/videos/video-channels.ts | |
parent | adc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff) | |
download | PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip |
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/middlewares/validators/videos/video-channels.ts')
-rw-r--r-- | server/middlewares/validators/videos/video-channels.ts | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index 2e4e755e7..57ac548b9 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts | |||
@@ -15,6 +15,7 @@ import { doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } fro | |||
15 | import { ActorModel } from '../../../models/activitypub/actor' | 15 | import { ActorModel } from '../../../models/activitypub/actor' |
16 | import { VideoChannelModel } from '../../../models/video/video-channel' | 16 | import { VideoChannelModel } from '../../../models/video/video-channel' |
17 | import { areValidationErrors } from '../utils' | 17 | import { areValidationErrors } from '../utils' |
18 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
18 | 19 | ||
19 | const videoChannelsAddValidator = [ | 20 | const videoChannelsAddValidator = [ |
20 | body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), | 21 | body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), |
@@ -29,7 +30,7 @@ const videoChannelsAddValidator = [ | |||
29 | 30 | ||
30 | const actor = await ActorModel.loadLocalByName(req.body.name) | 31 | const actor = await ActorModel.loadLocalByName(req.body.name) |
31 | if (actor) { | 32 | if (actor) { |
32 | res.status(409) | 33 | res.status(HttpStatusCode.CONFLICT_409) |
33 | .send({ error: 'Another actor (account/channel) with this name on this instance already exists or has already existed.' }) | 34 | .send({ error: 'Another actor (account/channel) with this name on this instance already exists or has already existed.' }) |
34 | .end() | 35 | .end() |
35 | return false | 36 | return false |
@@ -37,7 +38,7 @@ const videoChannelsAddValidator = [ | |||
37 | 38 | ||
38 | const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id) | 39 | const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id) |
39 | if (count >= VIDEO_CHANNELS.MAX_PER_USER) { | 40 | if (count >= VIDEO_CHANNELS.MAX_PER_USER) { |
40 | res.status(400) | 41 | res.status(HttpStatusCode.BAD_REQUEST_400) |
41 | .send({ error: `You cannot create more than ${VIDEO_CHANNELS.MAX_PER_USER} channels` }) | 42 | .send({ error: `You cannot create more than ${VIDEO_CHANNELS.MAX_PER_USER} channels` }) |
42 | .end() | 43 | .end() |
43 | return false | 44 | return false |
@@ -70,13 +71,13 @@ const videoChannelsUpdateValidator = [ | |||
70 | 71 | ||
71 | // We need to make additional checks | 72 | // We need to make additional checks |
72 | if (res.locals.videoChannel.Actor.isOwned() === false) { | 73 | if (res.locals.videoChannel.Actor.isOwned() === false) { |
73 | return res.status(403) | 74 | return res.status(HttpStatusCode.FORBIDDEN_403) |
74 | .json({ error: 'Cannot update video channel of another server' }) | 75 | .json({ error: 'Cannot update video channel of another server' }) |
75 | .end() | 76 | .end() |
76 | } | 77 | } |
77 | 78 | ||
78 | if (res.locals.videoChannel.Account.userId !== res.locals.oauth.token.User.id) { | 79 | if (res.locals.videoChannel.Account.userId !== res.locals.oauth.token.User.id) { |
79 | return res.status(403) | 80 | return res.status(HttpStatusCode.FORBIDDEN_403) |
80 | .json({ error: 'Cannot update video channel of another user' }) | 81 | .json({ error: 'Cannot update video channel of another user' }) |
81 | .end() | 82 | .end() |
82 | } | 83 | } |
@@ -155,7 +156,7 @@ export { | |||
155 | 156 | ||
156 | function checkUserCanDeleteVideoChannel (user: MUser, videoChannel: MChannelAccountDefault, res: express.Response) { | 157 | function checkUserCanDeleteVideoChannel (user: MUser, videoChannel: MChannelAccountDefault, res: express.Response) { |
157 | if (videoChannel.Actor.isOwned() === false) { | 158 | if (videoChannel.Actor.isOwned() === false) { |
158 | res.status(403) | 159 | res.status(HttpStatusCode.FORBIDDEN_403) |
159 | .json({ error: 'Cannot remove video channel of another server.' }) | 160 | .json({ error: 'Cannot remove video channel of another server.' }) |
160 | .end() | 161 | .end() |
161 | 162 | ||
@@ -166,7 +167,7 @@ function checkUserCanDeleteVideoChannel (user: MUser, videoChannel: MChannelAcco | |||
166 | // The user can delete it if s/he is an admin | 167 | // The user can delete it if s/he is an admin |
167 | // Or if s/he is the video channel's account | 168 | // Or if s/he is the video channel's account |
168 | if (user.hasRight(UserRight.REMOVE_ANY_VIDEO_CHANNEL) === false && videoChannel.Account.userId !== user.id) { | 169 | if (user.hasRight(UserRight.REMOVE_ANY_VIDEO_CHANNEL) === false && videoChannel.Account.userId !== user.id) { |
169 | res.status(403) | 170 | res.status(HttpStatusCode.FORBIDDEN_403) |
170 | .json({ error: 'Cannot remove video channel of another user' }) | 171 | .json({ error: 'Cannot remove video channel of another user' }) |
171 | .end() | 172 | .end() |
172 | 173 | ||
@@ -180,9 +181,9 @@ async function checkVideoChannelIsNotTheLastOne (res: express.Response) { | |||
180 | const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id) | 181 | const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id) |
181 | 182 | ||
182 | if (count <= 1) { | 183 | if (count <= 1) { |
183 | res.status(409) | 184 | res.status(HttpStatusCode.CONFLICT_409) |
184 | .json({ error: 'Cannot remove the last channel of this user' }) | 185 | .json({ error: 'Cannot remove the last channel of this user' }) |
185 | .end() | 186 | .end() |
186 | 187 | ||
187 | return false | 188 | return false |
188 | } | 189 | } |