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-live.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-live.ts')
-rw-r--r-- | server/middlewares/validators/videos/video-live.ts | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts index 69a14ccb1..3a73e1272 100644 --- a/server/middlewares/validators/videos/video-live.ts +++ b/server/middlewares/validators/videos/video-live.ts | |||
@@ -13,6 +13,7 @@ import { getCommonVideoEditAttributes } from './videos' | |||
13 | import { VideoModel } from '@server/models/video/video' | 13 | import { VideoModel } from '@server/models/video/video' |
14 | import { Hooks } from '@server/lib/plugins/hooks' | 14 | import { Hooks } from '@server/lib/plugins/hooks' |
15 | import { isLocalLiveVideoAccepted } from '@server/lib/moderation' | 15 | import { isLocalLiveVideoAccepted } from '@server/lib/moderation' |
16 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | ||
16 | 17 | ||
17 | const videoLiveGetValidator = [ | 18 | const videoLiveGetValidator = [ |
18 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | 19 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), |
@@ -28,7 +29,7 @@ const videoLiveGetValidator = [ | |||
28 | if (!checkUserCanManageVideo(user, res.locals.videoAll, UserRight.GET_ANY_LIVE, res, false)) return | 29 | if (!checkUserCanManageVideo(user, res.locals.videoAll, UserRight.GET_ANY_LIVE, res, false)) return |
29 | 30 | ||
30 | const videoLive = await VideoLiveModel.loadByVideoId(res.locals.videoAll.id) | 31 | const videoLive = await VideoLiveModel.loadByVideoId(res.locals.videoAll.id) |
31 | if (!videoLive) return res.sendStatus(404) | 32 | if (!videoLive) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) |
32 | 33 | ||
33 | res.locals.videoLive = videoLive | 34 | res.locals.videoLive = videoLive |
34 | 35 | ||
@@ -62,21 +63,21 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ | |||
62 | if (CONFIG.LIVE.ENABLED !== true) { | 63 | if (CONFIG.LIVE.ENABLED !== true) { |
63 | cleanUpReqFiles(req) | 64 | cleanUpReqFiles(req) |
64 | 65 | ||
65 | return res.status(403) | 66 | return res.status(HttpStatusCode.FORBIDDEN_403) |
66 | .json({ error: 'Live is not enabled on this instance' }) | 67 | .json({ error: 'Live is not enabled on this instance' }) |
67 | } | 68 | } |
68 | 69 | ||
69 | if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) { | 70 | if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) { |
70 | cleanUpReqFiles(req) | 71 | cleanUpReqFiles(req) |
71 | 72 | ||
72 | return res.status(403) | 73 | return res.status(HttpStatusCode.FORBIDDEN_403) |
73 | .json({ error: 'Saving live replay is not allowed instance' }) | 74 | .json({ error: 'Saving live replay is not allowed instance' }) |
74 | } | 75 | } |
75 | 76 | ||
76 | if (req.body.permanentLive && req.body.saveReplay) { | 77 | if (req.body.permanentLive && req.body.saveReplay) { |
77 | cleanUpReqFiles(req) | 78 | cleanUpReqFiles(req) |
78 | 79 | ||
79 | return res.status(400) | 80 | return res.status(HttpStatusCode.BAD_REQUEST_400) |
80 | .json({ error: 'Cannot set this live as permanent while saving its replay' }) | 81 | .json({ error: 'Cannot set this live as permanent while saving its replay' }) |
81 | } | 82 | } |
82 | 83 | ||
@@ -89,7 +90,7 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ | |||
89 | if (totalInstanceLives >= CONFIG.LIVE.MAX_INSTANCE_LIVES) { | 90 | if (totalInstanceLives >= CONFIG.LIVE.MAX_INSTANCE_LIVES) { |
90 | cleanUpReqFiles(req) | 91 | cleanUpReqFiles(req) |
91 | 92 | ||
92 | return res.status(403) | 93 | return res.status(HttpStatusCode.FORBIDDEN_403) |
93 | .json({ | 94 | .json({ |
94 | code: ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED, | 95 | code: ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED, |
95 | error: 'Cannot create this live because the max instance lives limit is reached.' | 96 | error: 'Cannot create this live because the max instance lives limit is reached.' |
@@ -103,7 +104,7 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ | |||
103 | if (totalUserLives >= CONFIG.LIVE.MAX_USER_LIVES) { | 104 | if (totalUserLives >= CONFIG.LIVE.MAX_USER_LIVES) { |
104 | cleanUpReqFiles(req) | 105 | cleanUpReqFiles(req) |
105 | 106 | ||
106 | return res.status(403) | 107 | return res.status(HttpStatusCode.FORBIDDEN_403) |
107 | .json({ | 108 | .json({ |
108 | code: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED, | 109 | code: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED, |
109 | error: 'Cannot create this live because the max user lives limit is reached.' | 110 | error: 'Cannot create this live because the max user lives limit is reached.' |
@@ -129,17 +130,17 @@ const videoLiveUpdateValidator = [ | |||
129 | if (areValidationErrors(req, res)) return | 130 | if (areValidationErrors(req, res)) return |
130 | 131 | ||
131 | if (req.body.permanentLive && req.body.saveReplay) { | 132 | if (req.body.permanentLive && req.body.saveReplay) { |
132 | return res.status(400) | 133 | return res.status(HttpStatusCode.BAD_REQUEST_400) |
133 | .json({ error: 'Cannot set this live as permanent while saving its replay' }) | 134 | .json({ error: 'Cannot set this live as permanent while saving its replay' }) |
134 | } | 135 | } |
135 | 136 | ||
136 | if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) { | 137 | if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) { |
137 | return res.status(403) | 138 | return res.status(HttpStatusCode.FORBIDDEN_403) |
138 | .json({ error: 'Saving live replay is not allowed instance' }) | 139 | .json({ error: 'Saving live replay is not allowed instance' }) |
139 | } | 140 | } |
140 | 141 | ||
141 | if (res.locals.videoAll.state !== VideoState.WAITING_FOR_LIVE) { | 142 | if (res.locals.videoAll.state !== VideoState.WAITING_FOR_LIVE) { |
142 | return res.status(400) | 143 | return res.status(HttpStatusCode.BAD_REQUEST_400) |
143 | .json({ error: 'Cannot update a live that has already started' }) | 144 | .json({ error: 'Cannot update a live that has already started' }) |
144 | } | 145 | } |
145 | 146 | ||
@@ -176,7 +177,7 @@ async function isLiveVideoAccepted (req: express.Request, res: express.Response) | |||
176 | if (!acceptedResult || acceptedResult.accepted !== true) { | 177 | if (!acceptedResult || acceptedResult.accepted !== true) { |
177 | logger.info('Refused local live video.', { acceptedResult, acceptParameters }) | 178 | logger.info('Refused local live video.', { acceptedResult, acceptParameters }) |
178 | 179 | ||
179 | res.status(403) | 180 | res.status(HttpStatusCode.FORBIDDEN_403) |
180 | .json({ error: acceptedResult.errorMessage || 'Refused local live video' }) | 181 | .json({ error: acceptedResult.errorMessage || 'Refused local live video' }) |
181 | 182 | ||
182 | return false | 183 | return false |