aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-25 11:17:53 +0100
committerChocobozzz <me@florianbigard.com>2021-02-25 11:18:11 +0100
commitd7df188f23bb3c4773ac26e6fa8b3d82b1229e6d (patch)
tree887f4268a16d685f5da74898575d1ecff3fd1ff8
parent24d3352ce4b48bc9ff15e8c0af0c93df6d903e5e (diff)
downloadPeerTube-d7df188f23bb3c4773ac26e6fa8b3d82b1229e6d.tar.gz
PeerTube-d7df188f23bb3c4773ac26e6fa8b3d82b1229e6d.tar.zst
PeerTube-d7df188f23bb3c4773ac26e6fa8b3d82b1229e6d.zip
Fix separate SQL query for video get
-rw-r--r--server/middlewares/validators/videos/videos.ts9
-rw-r--r--server/models/account/user.ts5
-rw-r--r--server/models/video/video.ts5
-rw-r--r--server/types/models/video/video.ts1
4 files changed, 10 insertions, 10 deletions
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index be05b2a69..d51c86972 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -3,7 +3,7 @@ import { body, param, query, ValidationChain } from 'express-validator'
3import { isAbleToUploadVideo } from '@server/lib/user' 3import { isAbleToUploadVideo } from '@server/lib/user'
4import { getServerActor } from '@server/models/application/application' 4import { getServerActor } from '@server/models/application/application'
5import { ExpressPromiseHandler } from '@server/types/express' 5import { ExpressPromiseHandler } from '@server/types/express'
6import { MVideoFullLight } from '@server/types/models' 6import { MVideoFullLight, MVideoWithRights } from '@server/types/models'
7import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' 7import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
9import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model' 9import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
@@ -197,17 +197,16 @@ const videosCustomGetValidator = (
197 // Controllers does not need to check video rights 197 // Controllers does not need to check video rights
198 if (fetchType === 'only-immutable-attributes') return next() 198 if (fetchType === 'only-immutable-attributes') return next()
199 199
200 const video = getVideoWithAttributes(res) 200 const video = getVideoWithAttributes(res) as MVideoWithRights
201 const videoAll = video as MVideoFullLight
202 201
203 // Video private or blacklisted 202 // Video private or blacklisted
204 if (videoAll.requiresAuth()) { 203 if (video.requiresAuth()) {
205 await authenticatePromiseIfNeeded(req, res, authenticateInQuery) 204 await authenticatePromiseIfNeeded(req, res, authenticateInQuery)
206 205
207 const user = res.locals.oauth ? res.locals.oauth.token.User : null 206 const user = res.locals.oauth ? res.locals.oauth.token.User : null
208 207
209 // Only the owner or a user that have blacklist rights can see the video 208 // Only the owner or a user that have blacklist rights can see the video
210 if (!user || !user.canGetVideo(videoAll)) { 209 if (!user || !user.canGetVideo(video)) {
211 return res.status(HttpStatusCode.FORBIDDEN_403) 210 return res.status(HttpStatusCode.FORBIDDEN_403)
212 .json({ error: 'Cannot get this private/internal or blacklisted video.' }) 211 .json({ error: 'Cannot get this private/internal or blacklisted video.' })
213 } 212 }
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 534898f96..0834ecfa5 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -28,7 +28,8 @@ import {
28 MUserFormattable, 28 MUserFormattable,
29 MUserNotifSettingChannelDefault, 29 MUserNotifSettingChannelDefault,
30 MUserWithNotificationSetting, 30 MUserWithNotificationSetting,
31 MVideoFullLight 31 MVideoFullLight,
32 MVideoWithRights
32} from '@server/types/models' 33} from '@server/types/models'
33import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users' 34import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users'
34import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models' 35import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models'
@@ -819,7 +820,7 @@ export class UserModel extends Model {
819 .then(u => u.map(u => u.username)) 820 .then(u => u.map(u => u.username))
820 } 821 }
821 822
822 canGetVideo (video: MVideoFullLight) { 823 canGetVideo (video: MVideoWithRights) {
823 const videoUserId = video.VideoChannel.Account.userId 824 const videoUserId = video.VideoChannel.Account.userId
824 825
825 if (video.isBlacklisted()) { 826 if (video.isBlacklisted()) {
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 48d4ba47a..8894843e0 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -356,6 +356,7 @@ export type AvailableForListIDsOptions = {
356 include: [ 356 include: [
357 { 357 {
358 model: VideoFileModel, 358 model: VideoFileModel,
359 separate: true,
359 required: false, 360 required: false,
360 include: subInclude 361 include: subInclude
361 } 362 }
@@ -383,6 +384,7 @@ export type AvailableForListIDsOptions = {
383 { 384 {
384 model: VideoStreamingPlaylistModel.unscoped(), 385 model: VideoStreamingPlaylistModel.unscoped(),
385 required: false, 386 required: false,
387 separate: true,
386 include: subInclude 388 include: subInclude
387 } 389 }
388 ] 390 ]
@@ -1312,8 +1314,7 @@ export class VideoModel extends Model {
1312 1314
1313 return VideoModel.scope([ 1315 return VideoModel.scope([
1314 ScopeNames.WITH_BLACKLISTED, 1316 ScopeNames.WITH_BLACKLISTED,
1315 ScopeNames.WITH_USER_ID, 1317 ScopeNames.WITH_USER_ID
1316 ScopeNames.WITH_THUMBNAILS
1317 ]).findOne(options) 1318 ]).findOne(options)
1318 } 1319 }
1319 1320
diff --git a/server/types/models/video/video.ts b/server/types/models/video/video.ts
index 692490230..5225fbce5 100644
--- a/server/types/models/video/video.ts
+++ b/server/types/models/video/video.ts
@@ -107,7 +107,6 @@ export type MVideoAccountLight =
107export type MVideoWithRights = 107export type MVideoWithRights =
108 MVideo & 108 MVideo &
109 Use<'VideoBlacklist', MVideoBlacklistLight> & 109 Use<'VideoBlacklist', MVideoBlacklistLight> &
110 Use<'Thumbnails', MThumbnail[]> &
111 Use<'VideoChannel', MChannelUserId> 110 Use<'VideoChannel', MChannelUserId>
112 111
113// ############################################################################ 112// ############################################################################