aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/shared/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/shared/videos.ts')
-rw-r--r--server/middlewares/validators/shared/videos.ts26
1 files changed, 24 insertions, 2 deletions
diff --git a/server/middlewares/validators/shared/videos.ts b/server/middlewares/validators/shared/videos.ts
index fc978b63a..8807435f6 100644
--- a/server/middlewares/validators/shared/videos.ts
+++ b/server/middlewares/validators/shared/videos.ts
@@ -1,5 +1,6 @@
1import { Request, Response } from 'express' 1import { Request, Response } from 'express'
2import { loadVideo, VideoLoadType } from '@server/lib/model-loaders' 2import { loadVideo, VideoLoadType } from '@server/lib/model-loaders'
3import { isAbleToUploadVideo } from '@server/lib/user'
3import { authenticatePromiseIfNeeded } from '@server/middlewares/auth' 4import { authenticatePromiseIfNeeded } from '@server/middlewares/auth'
4import { VideoModel } from '@server/models/video/video' 5import { VideoModel } from '@server/models/video/video'
5import { VideoChannelModel } from '@server/models/video/video-channel' 6import { VideoChannelModel } from '@server/models/video/video-channel'
@@ -7,6 +8,7 @@ import { VideoFileModel } from '@server/models/video/video-file'
7import { 8import {
8 MUser, 9 MUser,
9 MUserAccountId, 10 MUserAccountId,
11 MUserId,
10 MVideo, 12 MVideo,
11 MVideoAccountLight, 13 MVideoAccountLight,
12 MVideoFormattableDetails, 14 MVideoFormattableDetails,
@@ -16,7 +18,7 @@ import {
16 MVideoThumbnail, 18 MVideoThumbnail,
17 MVideoWithRights 19 MVideoWithRights
18} from '@server/types/models' 20} from '@server/types/models'
19import { HttpStatusCode, UserRight } from '@shared/models' 21import { HttpStatusCode, ServerErrorCode, UserRight } from '@shared/models'
20 22
21async function doesVideoExist (id: number | string, res: Response, fetchType: VideoLoadType = 'all') { 23async function doesVideoExist (id: number | string, res: Response, fetchType: VideoLoadType = 'all') {
22 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined 24 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined
@@ -108,6 +110,11 @@ async function checkCanSeePrivateVideo (req: Request, res: Response, video: MVid
108 110
109 // Only the owner or a user that have blocklist rights can see the video 111 // Only the owner or a user that have blocklist rights can see the video
110 if (!user || !user.canGetVideo(video)) { 112 if (!user || !user.canGetVideo(video)) {
113 res.fail({
114 status: HttpStatusCode.FORBIDDEN_403,
115 message: 'Cannot fetch information of private/internal/blocklisted video'
116 })
117
111 return false 118 return false
112 } 119 }
113 120
@@ -139,13 +146,28 @@ function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right:
139 return true 146 return true
140} 147}
141 148
149async function checkUserQuota (user: MUserId, videoFileSize: number, res: Response) {
150 if (await isAbleToUploadVideo(user.id, videoFileSize) === false) {
151 res.fail({
152 status: HttpStatusCode.PAYLOAD_TOO_LARGE_413,
153 message: 'The user video quota is exceeded with this video.',
154 type: ServerErrorCode.QUOTA_REACHED
155 })
156 return false
157 }
158
159 return true
160}
161
142// --------------------------------------------------------------------------- 162// ---------------------------------------------------------------------------
143 163
144export { 164export {
145 doesVideoChannelOfAccountExist, 165 doesVideoChannelOfAccountExist,
146 doesVideoExist, 166 doesVideoExist,
147 doesVideoFileOfVideoExist, 167 doesVideoFileOfVideoExist,
168
148 checkUserCanManageVideo, 169 checkUserCanManageVideo,
149 checkCanSeeVideoIfPrivate, 170 checkCanSeeVideoIfPrivate,
150 checkCanSeePrivateVideo 171 checkCanSeePrivateVideo,
172 checkUserQuota
151} 173}