aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/middlewares/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/middlewares/videos.ts')
-rw-r--r--server/helpers/middlewares/videos.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/server/helpers/middlewares/videos.ts b/server/helpers/middlewares/videos.ts
index 3904f762a..c5eb0607a 100644
--- a/server/helpers/middlewares/videos.ts
+++ b/server/helpers/middlewares/videos.ts
@@ -13,6 +13,7 @@ import {
13 MVideoWithRights 13 MVideoWithRights
14} from '@server/types/models' 14} from '@server/types/models'
15import { VideoFileModel } from '@server/models/video/video-file' 15import { VideoFileModel } from '@server/models/video/video-file'
16import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
16 17
17async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { 18async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') {
18 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined 19 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined
@@ -20,7 +21,7 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi
20 const video = await fetchVideo(id, fetchType, userId) 21 const video = await fetchVideo(id, fetchType, userId)
21 22
22 if (video === null) { 23 if (video === null) {
23 res.status(404) 24 res.status(HttpStatusCode.NOT_FOUND_404)
24 .json({ error: 'Video not found' }) 25 .json({ error: 'Video not found' })
25 .end() 26 .end()
26 27
@@ -54,7 +55,7 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi
54 55
55async function doesVideoFileOfVideoExist (id: number, videoIdOrUUID: number | string, res: Response) { 56async function doesVideoFileOfVideoExist (id: number, videoIdOrUUID: number | string, res: Response) {
56 if (!await VideoFileModel.doesVideoExistForVideoFile(id, videoIdOrUUID)) { 57 if (!await VideoFileModel.doesVideoExistForVideoFile(id, videoIdOrUUID)) {
57 res.status(404) 58 res.status(HttpStatusCode.NOT_FOUND_404)
58 .json({ error: 'VideoFile matching Video not found' }) 59 .json({ error: 'VideoFile matching Video not found' })
59 .end() 60 .end()
60 61
@@ -68,7 +69,7 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc
68 if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { 69 if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
69 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) 70 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
70 if (videoChannel === null) { 71 if (videoChannel === null) {
71 res.status(400) 72 res.status(HttpStatusCode.BAD_REQUEST_400)
72 .json({ error: 'Unknown video `video channel` on this instance.' }) 73 .json({ error: 'Unknown video `video channel` on this instance.' })
73 .end() 74 .end()
74 75
@@ -81,7 +82,7 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc
81 82
82 const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) 83 const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id)
83 if (videoChannel === null) { 84 if (videoChannel === null) {
84 res.status(400) 85 res.status(HttpStatusCode.BAD_REQUEST_400)
85 .json({ error: 'Unknown video `video channel` for this account.' }) 86 .json({ error: 'Unknown video `video channel` for this account.' })
86 .end() 87 .end()
87 88
@@ -95,7 +96,7 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc
95function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right: UserRight, res: Response, onlyOwned = true) { 96function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right: UserRight, res: Response, onlyOwned = true) {
96 // Retrieve the user who did the request 97 // Retrieve the user who did the request
97 if (onlyOwned && video.isOwned() === false) { 98 if (onlyOwned && video.isOwned() === false) {
98 res.status(403) 99 res.status(HttpStatusCode.FORBIDDEN_403)
99 .json({ error: 'Cannot manage a video of another server.' }) 100 .json({ error: 'Cannot manage a video of another server.' })
100 .end() 101 .end()
101 return false 102 return false
@@ -106,7 +107,7 @@ function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right:
106 // Or if s/he is the video's account 107 // Or if s/he is the video's account
107 const account = video.VideoChannel.Account 108 const account = video.VideoChannel.Account
108 if (user.hasRight(right) === false && account.userId !== user.id) { 109 if (user.hasRight(right) === false && account.userId !== user.id) {
109 res.status(403) 110 res.status(HttpStatusCode.FORBIDDEN_403)
110 .json({ error: 'Cannot manage a video of another user.' }) 111 .json({ error: 'Cannot manage a video of another user.' })
111 .end() 112 .end()
112 return false 113 return false