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/controllers/api/videos | |
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/controllers/api/videos')
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 7 | ||||
-rw-r--r-- | server/controllers/api/videos/captions.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/videos/comment.ts | 7 | ||||
-rw-r--r-- | server/controllers/api/videos/import.ts | 3 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 15 | ||||
-rw-r--r-- | server/controllers/api/videos/live.ts | 3 | ||||
-rw-r--r-- | server/controllers/api/videos/ownership.ts | 9 | ||||
-rw-r--r-- | server/controllers/api/videos/rate.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/videos/watching.ts | 5 |
9 files changed, 40 insertions, 19 deletions
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 3b25ceea2..fa8448c86 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -18,6 +18,7 @@ import { | |||
18 | videosBlacklistUpdateValidator | 18 | videosBlacklistUpdateValidator |
19 | } from '../../../middlewares' | 19 | } from '../../../middlewares' |
20 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' | 20 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' |
21 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
21 | 22 | ||
22 | const blacklistRouter = express.Router() | 23 | const blacklistRouter = express.Router() |
23 | 24 | ||
@@ -69,7 +70,7 @@ async function addVideoToBlacklistController (req: express.Request, res: express | |||
69 | 70 | ||
70 | logger.info('Video %s blacklisted.', videoInstance.uuid) | 71 | logger.info('Video %s blacklisted.', videoInstance.uuid) |
71 | 72 | ||
72 | return res.type('json').sendStatus(204) | 73 | return res.type('json').sendStatus(HttpStatusCode.NO_CONTENT_204) |
73 | } | 74 | } |
74 | 75 | ||
75 | async function updateVideoBlacklistController (req: express.Request, res: express.Response) { | 76 | async function updateVideoBlacklistController (req: express.Request, res: express.Response) { |
@@ -81,7 +82,7 @@ async function updateVideoBlacklistController (req: express.Request, res: expres | |||
81 | return videoBlacklist.save({ transaction: t }) | 82 | return videoBlacklist.save({ transaction: t }) |
82 | }) | 83 | }) |
83 | 84 | ||
84 | return res.type('json').sendStatus(204) | 85 | return res.type('json').sendStatus(HttpStatusCode.NO_CONTENT_204) |
85 | } | 86 | } |
86 | 87 | ||
87 | async function listBlacklist (req: express.Request, res: express.Response) { | 88 | async function listBlacklist (req: express.Request, res: express.Response) { |
@@ -104,5 +105,5 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex | |||
104 | 105 | ||
105 | logger.info('Video %s removed from blacklist.', video.uuid) | 106 | logger.info('Video %s removed from blacklist.', video.uuid) |
106 | 107 | ||
107 | return res.type('json').sendStatus(204) | 108 | return res.type('json').sendStatus(HttpStatusCode.NO_CONTENT_204) |
108 | } | 109 | } |
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts index c4e2ee72c..bf82e2c19 100644 --- a/server/controllers/api/videos/captions.ts +++ b/server/controllers/api/videos/captions.ts | |||
@@ -11,6 +11,7 @@ import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | |||
11 | import { CONFIG } from '../../../initializers/config' | 11 | import { CONFIG } from '../../../initializers/config' |
12 | import { sequelizeTypescript } from '../../../initializers/database' | 12 | import { sequelizeTypescript } from '../../../initializers/database' |
13 | import { MVideoCaptionVideo } from '@server/types/models' | 13 | import { MVideoCaptionVideo } from '@server/types/models' |
14 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
14 | 15 | ||
15 | const reqVideoCaptionAdd = createReqFiles( | 16 | const reqVideoCaptionAdd = createReqFiles( |
16 | [ 'captionfile' ], | 17 | [ 'captionfile' ], |
@@ -72,7 +73,7 @@ async function addVideoCaption (req: express.Request, res: express.Response) { | |||
72 | await federateVideoIfNeeded(video, false, t) | 73 | await federateVideoIfNeeded(video, false, t) |
73 | }) | 74 | }) |
74 | 75 | ||
75 | return res.status(204).end() | 76 | return res.status(HttpStatusCode.NO_CONTENT_204).end() |
76 | } | 77 | } |
77 | 78 | ||
78 | async function deleteVideoCaption (req: express.Request, res: express.Response) { | 79 | async function deleteVideoCaption (req: express.Request, res: express.Response) { |
@@ -88,5 +89,5 @@ async function deleteVideoCaption (req: express.Request, res: express.Response) | |||
88 | 89 | ||
89 | logger.info('Video caption %s of video %s deleted.', videoCaption.language, video.uuid) | 90 | logger.info('Video caption %s of video %s deleted.', videoCaption.language, video.uuid) |
90 | 91 | ||
91 | return res.type('json').status(204).end() | 92 | return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end() |
92 | } | 93 | } |
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 020d0b104..752a33596 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -29,6 +29,7 @@ import { | |||
29 | } from '../../../middlewares/validators' | 29 | } from '../../../middlewares/validators' |
30 | import { AccountModel } from '../../../models/account/account' | 30 | import { AccountModel } from '../../../models/account/account' |
31 | import { VideoCommentModel } from '../../../models/video/video-comment' | 31 | import { VideoCommentModel } from '../../../models/video/video-comment' |
32 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
32 | 33 | ||
33 | const auditLogger = auditLoggerFactory('comments') | 34 | const auditLogger = auditLoggerFactory('comments') |
34 | const videoCommentRouter = express.Router() | 35 | const videoCommentRouter = express.Router() |
@@ -161,7 +162,7 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo | |||
161 | } | 162 | } |
162 | 163 | ||
163 | if (resultList.data.length === 0) { | 164 | if (resultList.data.length === 0) { |
164 | return res.sendStatus(404) | 165 | return res.sendStatus(HttpStatusCode.NOT_FOUND_404) |
165 | } | 166 | } |
166 | 167 | ||
167 | return res.json(buildFormattedCommentTree(resultList)) | 168 | return res.json(buildFormattedCommentTree(resultList)) |
@@ -218,5 +219,7 @@ async function removeVideoComment (req: express.Request, res: express.Response) | |||
218 | 219 | ||
219 | auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON())) | 220 | auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON())) |
220 | 221 | ||
221 | return res.type('json').status(204).end() | 222 | return res.type('json') |
223 | .status(HttpStatusCode.NO_CONTENT_204) | ||
224 | .end() | ||
222 | } | 225 | } |
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index bc5fea7aa..cd9ba046d 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts | |||
@@ -36,6 +36,7 @@ import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoIm | |||
36 | import { VideoModel } from '../../../models/video/video' | 36 | import { VideoModel } from '../../../models/video/video' |
37 | import { VideoCaptionModel } from '../../../models/video/video-caption' | 37 | import { VideoCaptionModel } from '../../../models/video/video-caption' |
38 | import { VideoImportModel } from '../../../models/video/video-import' | 38 | import { VideoImportModel } from '../../../models/video/video-import' |
39 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
39 | 40 | ||
40 | const auditLogger = auditLoggerFactory('video-imports') | 41 | const auditLogger = auditLoggerFactory('video-imports') |
41 | const videoImportsRouter = express.Router() | 42 | const videoImportsRouter = express.Router() |
@@ -146,7 +147,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) | |||
146 | } catch (err) { | 147 | } catch (err) { |
147 | logger.info('Cannot fetch information from import for URL %s.', targetUrl, { err }) | 148 | logger.info('Cannot fetch information from import for URL %s.', targetUrl, { err }) |
148 | 149 | ||
149 | return res.status(400).json({ | 150 | return res.status(HttpStatusCode.BAD_REQUEST_400).json({ |
150 | error: 'Cannot fetch remote information of this URL.' | 151 | error: 'Cannot fetch remote information of this URL.' |
151 | }).end() | 152 | }).end() |
152 | } | 153 | } |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 71a0f97e2..e1c775180 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -66,6 +66,7 @@ import { liveRouter } from './live' | |||
66 | import { ownershipVideoRouter } from './ownership' | 66 | import { ownershipVideoRouter } from './ownership' |
67 | import { rateVideoRouter } from './rate' | 67 | import { rateVideoRouter } from './rate' |
68 | import { watchingRouter } from './watching' | 68 | import { watchingRouter } from './watching' |
69 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
69 | 70 | ||
70 | const auditLogger = auditLoggerFactory('videos') | 71 | const auditLogger = auditLoggerFactory('videos') |
71 | const videosRouter = express.Router() | 72 | const videosRouter = express.Router() |
@@ -178,7 +179,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
178 | // Set timeout to 10 minutes, as Express's default is 2 minutes | 179 | // Set timeout to 10 minutes, as Express's default is 2 minutes |
179 | req.setTimeout(1000 * 60 * 10, () => { | 180 | req.setTimeout(1000 * 60 * 10, () => { |
180 | logger.error('Upload video has timed out.') | 181 | logger.error('Upload video has timed out.') |
181 | return res.sendStatus(408) | 182 | return res.sendStatus(HttpStatusCode.REQUEST_TIMEOUT_408) |
182 | }) | 183 | }) |
183 | 184 | ||
184 | const videoPhysicalFile = req.files['videofile'][0] | 185 | const videoPhysicalFile = req.files['videofile'][0] |
@@ -394,7 +395,9 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
394 | throw err | 395 | throw err |
395 | } | 396 | } |
396 | 397 | ||
397 | return res.type('json').status(204).end() | 398 | return res.type('json') |
399 | .status(HttpStatusCode.NO_CONTENT_204) | ||
400 | .end() | ||
398 | } | 401 | } |
399 | 402 | ||
400 | async function getVideo (req: express.Request, res: express.Response) { | 403 | async function getVideo (req: express.Request, res: express.Response) { |
@@ -421,7 +424,7 @@ async function viewVideo (req: express.Request, res: express.Response) { | |||
421 | const exists = await Redis.Instance.doesVideoIPViewExist(ip, immutableVideoAttrs.uuid) | 424 | const exists = await Redis.Instance.doesVideoIPViewExist(ip, immutableVideoAttrs.uuid) |
422 | if (exists) { | 425 | if (exists) { |
423 | logger.debug('View for ip %s and video %s already exists.', ip, immutableVideoAttrs.uuid) | 426 | logger.debug('View for ip %s and video %s already exists.', ip, immutableVideoAttrs.uuid) |
424 | return res.sendStatus(204) | 427 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) |
425 | } | 428 | } |
426 | 429 | ||
427 | const video = await VideoModel.load(immutableVideoAttrs.id) | 430 | const video = await VideoModel.load(immutableVideoAttrs.id) |
@@ -454,7 +457,7 @@ async function viewVideo (req: express.Request, res: express.Response) { | |||
454 | 457 | ||
455 | Hooks.runAction('action:api.video.viewed', { video, ip }) | 458 | Hooks.runAction('action:api.video.viewed', { video, ip }) |
456 | 459 | ||
457 | return res.sendStatus(204) | 460 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) |
458 | } | 461 | } |
459 | 462 | ||
460 | async function getVideoDescription (req: express.Request, res: express.Response) { | 463 | async function getVideoDescription (req: express.Request, res: express.Response) { |
@@ -517,5 +520,7 @@ async function removeVideo (req: express.Request, res: express.Response) { | |||
517 | 520 | ||
518 | Hooks.runAction('action:api.video.deleted', { video: videoInstance }) | 521 | Hooks.runAction('action:api.video.deleted', { video: videoInstance }) |
519 | 522 | ||
520 | return res.type('json').status(204).end() | 523 | return res.type('json') |
524 | .status(HttpStatusCode.NO_CONTENT_204) | ||
525 | .end() | ||
521 | } | 526 | } |
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts index e67d89612..04d2494ce 100644 --- a/server/controllers/api/videos/live.ts +++ b/server/controllers/api/videos/live.ts | |||
@@ -16,6 +16,7 @@ import { sequelizeTypescript } from '../../../initializers/database' | |||
16 | import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' | 16 | import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' |
17 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' | 17 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' |
18 | import { VideoModel } from '../../../models/video/video' | 18 | import { VideoModel } from '../../../models/video/video' |
19 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
19 | 20 | ||
20 | const liveRouter = express.Router() | 21 | const liveRouter = express.Router() |
21 | 22 | ||
@@ -75,7 +76,7 @@ async function updateLiveVideo (req: express.Request, res: express.Response) { | |||
75 | 76 | ||
76 | await federateVideoIfNeeded(video, false) | 77 | await federateVideoIfNeeded(video, false) |
77 | 78 | ||
78 | return res.sendStatus(204) | 79 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) |
79 | } | 80 | } |
80 | 81 | ||
81 | async function addLiveVideo (req: express.Request, res: express.Response) { | 82 | async function addLiveVideo (req: express.Request, res: express.Response) { |
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts index d76fee51d..86adb6c69 100644 --- a/server/controllers/api/videos/ownership.ts +++ b/server/controllers/api/videos/ownership.ts | |||
@@ -19,6 +19,7 @@ import { changeVideoChannelShare } from '../../../lib/activitypub/share' | |||
19 | import { sendUpdateVideo } from '../../../lib/activitypub/send' | 19 | import { sendUpdateVideo } from '../../../lib/activitypub/send' |
20 | import { VideoModel } from '../../../models/video/video' | 20 | import { VideoModel } from '../../../models/video/video' |
21 | import { MVideoFullLight } from '@server/types/models' | 21 | import { MVideoFullLight } from '@server/types/models' |
22 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
22 | 23 | ||
23 | const ownershipVideoRouter = express.Router() | 24 | const ownershipVideoRouter = express.Router() |
24 | 25 | ||
@@ -80,7 +81,9 @@ async function giveVideoOwnership (req: express.Request, res: express.Response) | |||
80 | }) | 81 | }) |
81 | 82 | ||
82 | logger.info('Ownership change for video %s created.', videoInstance.name) | 83 | logger.info('Ownership change for video %s created.', videoInstance.name) |
83 | return res.type('json').status(204).end() | 84 | return res.type('json') |
85 | .status(HttpStatusCode.NO_CONTENT_204) | ||
86 | .end() | ||
84 | } | 87 | } |
85 | 88 | ||
86 | async function listVideoOwnership (req: express.Request, res: express.Response) { | 89 | async function listVideoOwnership (req: express.Request, res: express.Response) { |
@@ -119,7 +122,7 @@ async function acceptOwnership (req: express.Request, res: express.Response) { | |||
119 | videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED | 122 | videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED |
120 | await videoChangeOwnership.save({ transaction: t }) | 123 | await videoChangeOwnership.save({ transaction: t }) |
121 | 124 | ||
122 | return res.sendStatus(204) | 125 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) |
123 | }) | 126 | }) |
124 | } | 127 | } |
125 | 128 | ||
@@ -130,6 +133,6 @@ async function refuseOwnership (req: express.Request, res: express.Response) { | |||
130 | videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED | 133 | videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED |
131 | await videoChangeOwnership.save({ transaction: t }) | 134 | await videoChangeOwnership.save({ transaction: t }) |
132 | 135 | ||
133 | return res.sendStatus(204) | 136 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) |
134 | }) | 137 | }) |
135 | } | 138 | } |
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index df1eddb4f..520932c63 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts | |||
@@ -7,6 +7,7 @@ import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoUp | |||
7 | import { AccountModel } from '../../../models/account/account' | 7 | import { AccountModel } from '../../../models/account/account' |
8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
9 | import { sequelizeTypescript } from '../../../initializers/database' | 9 | import { sequelizeTypescript } from '../../../initializers/database' |
10 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
10 | 11 | ||
11 | const rateVideoRouter = express.Router() | 12 | const rateVideoRouter = express.Router() |
12 | 13 | ||
@@ -78,5 +79,7 @@ async function rateVideo (req: express.Request, res: express.Response) { | |||
78 | logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name) | 79 | logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name) |
79 | }) | 80 | }) |
80 | 81 | ||
81 | return res.type('json').status(204).end() | 82 | return res.type('json') |
83 | .status(HttpStatusCode.NO_CONTENT_204) | ||
84 | .end() | ||
82 | } | 85 | } |
diff --git a/server/controllers/api/videos/watching.ts b/server/controllers/api/videos/watching.ts index 036e16f3a..627f12aa9 100644 --- a/server/controllers/api/videos/watching.ts +++ b/server/controllers/api/videos/watching.ts | |||
@@ -2,6 +2,7 @@ import * as express from 'express' | |||
2 | import { UserWatchingVideo } from '../../../../shared' | 2 | import { UserWatchingVideo } from '../../../../shared' |
3 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares' | 3 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares' |
4 | import { UserVideoHistoryModel } from '../../../models/account/user-video-history' | 4 | import { UserVideoHistoryModel } from '../../../models/account/user-video-history' |
5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
5 | 6 | ||
6 | const watchingRouter = express.Router() | 7 | const watchingRouter = express.Router() |
7 | 8 | ||
@@ -31,5 +32,7 @@ async function userWatchVideo (req: express.Request, res: express.Response) { | |||
31 | currentTime: body.currentTime | 32 | currentTime: body.currentTime |
32 | }) | 33 | }) |
33 | 34 | ||
34 | return res.type('json').status(204).end() | 35 | return res.type('json') |
36 | .status(HttpStatusCode.NO_CONTENT_204) | ||
37 | .end() | ||
35 | } | 38 | } |