aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /server/controllers/api/videos
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-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.ts7
-rw-r--r--server/controllers/api/videos/captions.ts5
-rw-r--r--server/controllers/api/videos/comment.ts7
-rw-r--r--server/controllers/api/videos/import.ts3
-rw-r--r--server/controllers/api/videos/index.ts15
-rw-r--r--server/controllers/api/videos/live.ts3
-rw-r--r--server/controllers/api/videos/ownership.ts9
-rw-r--r--server/controllers/api/videos/rate.ts5
-rw-r--r--server/controllers/api/videos/watching.ts5
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'
20import { VideoBlacklistModel } from '../../../models/video/video-blacklist' 20import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
21import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
21 22
22const blacklistRouter = express.Router() 23const 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
75async function updateVideoBlacklistController (req: express.Request, res: express.Response) { 76async 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
87async function listBlacklist (req: express.Request, res: express.Response) { 88async 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'
11import { CONFIG } from '../../../initializers/config' 11import { CONFIG } from '../../../initializers/config'
12import { sequelizeTypescript } from '../../../initializers/database' 12import { sequelizeTypescript } from '../../../initializers/database'
13import { MVideoCaptionVideo } from '@server/types/models' 13import { MVideoCaptionVideo } from '@server/types/models'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
14 15
15const reqVideoCaptionAdd = createReqFiles( 16const 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
78async function deleteVideoCaption (req: express.Request, res: express.Response) { 79async 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'
30import { AccountModel } from '../../../models/account/account' 30import { AccountModel } from '../../../models/account/account'
31import { VideoCommentModel } from '../../../models/video/video-comment' 31import { VideoCommentModel } from '../../../models/video/video-comment'
32import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
32 33
33const auditLogger = auditLoggerFactory('comments') 34const auditLogger = auditLoggerFactory('comments')
34const videoCommentRouter = express.Router() 35const 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
36import { VideoModel } from '../../../models/video/video' 36import { VideoModel } from '../../../models/video/video'
37import { VideoCaptionModel } from '../../../models/video/video-caption' 37import { VideoCaptionModel } from '../../../models/video/video-caption'
38import { VideoImportModel } from '../../../models/video/video-import' 38import { VideoImportModel } from '../../../models/video/video-import'
39import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
39 40
40const auditLogger = auditLoggerFactory('video-imports') 41const auditLogger = auditLoggerFactory('video-imports')
41const videoImportsRouter = express.Router() 42const 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'
66import { ownershipVideoRouter } from './ownership' 66import { ownershipVideoRouter } from './ownership'
67import { rateVideoRouter } from './rate' 67import { rateVideoRouter } from './rate'
68import { watchingRouter } from './watching' 68import { watchingRouter } from './watching'
69import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
69 70
70const auditLogger = auditLoggerFactory('videos') 71const auditLogger = auditLoggerFactory('videos')
71const videosRouter = express.Router() 72const 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
400async function getVideo (req: express.Request, res: express.Response) { 403async 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
460async function getVideoDescription (req: express.Request, res: express.Response) { 463async 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'
16import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' 16import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
17import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' 17import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'
18import { VideoModel } from '../../../models/video/video' 18import { VideoModel } from '../../../models/video/video'
19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
19 20
20const liveRouter = express.Router() 21const 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
81async function addLiveVideo (req: express.Request, res: express.Response) { 82async 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'
19import { sendUpdateVideo } from '../../../lib/activitypub/send' 19import { sendUpdateVideo } from '../../../lib/activitypub/send'
20import { VideoModel } from '../../../models/video/video' 20import { VideoModel } from '../../../models/video/video'
21import { MVideoFullLight } from '@server/types/models' 21import { MVideoFullLight } from '@server/types/models'
22import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
22 23
23const ownershipVideoRouter = express.Router() 24const 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
86async function listVideoOwnership (req: express.Request, res: express.Response) { 89async 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
7import { AccountModel } from '../../../models/account/account' 7import { AccountModel } from '../../../models/account/account'
8import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 8import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
9import { sequelizeTypescript } from '../../../initializers/database' 9import { sequelizeTypescript } from '../../../initializers/database'
10import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
10 11
11const rateVideoRouter = express.Router() 12const 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'
2import { UserWatchingVideo } from '../../../../shared' 2import { UserWatchingVideo } from '../../../../shared'
3import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares' 3import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares'
4import { UserVideoHistoryModel } from '../../../models/account/user-video-history' 4import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5 6
6const watchingRouter = express.Router() 7const 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}