mirror of https://github.com/Chocobozzz/PeerTube
Fix separate SQL query for video get
parent
24d3352ce4
commit
d7df188f23
|
@ -3,7 +3,7 @@ import { body, param, query, ValidationChain } from 'express-validator'
|
||||||
import { isAbleToUploadVideo } from '@server/lib/user'
|
import { isAbleToUploadVideo } from '@server/lib/user'
|
||||||
import { getServerActor } from '@server/models/application/application'
|
import { getServerActor } from '@server/models/application/application'
|
||||||
import { ExpressPromiseHandler } from '@server/types/express'
|
import { ExpressPromiseHandler } from '@server/types/express'
|
||||||
import { MVideoFullLight } from '@server/types/models'
|
import { MVideoFullLight, MVideoWithRights } from '@server/types/models'
|
||||||
import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
|
import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||||
import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
|
import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
|
||||||
|
@ -197,17 +197,16 @@ const videosCustomGetValidator = (
|
||||||
// Controllers does not need to check video rights
|
// Controllers does not need to check video rights
|
||||||
if (fetchType === 'only-immutable-attributes') return next()
|
if (fetchType === 'only-immutable-attributes') return next()
|
||||||
|
|
||||||
const video = getVideoWithAttributes(res)
|
const video = getVideoWithAttributes(res) as MVideoWithRights
|
||||||
const videoAll = video as MVideoFullLight
|
|
||||||
|
|
||||||
// Video private or blacklisted
|
// Video private or blacklisted
|
||||||
if (videoAll.requiresAuth()) {
|
if (video.requiresAuth()) {
|
||||||
await authenticatePromiseIfNeeded(req, res, authenticateInQuery)
|
await authenticatePromiseIfNeeded(req, res, authenticateInQuery)
|
||||||
|
|
||||||
const user = res.locals.oauth ? res.locals.oauth.token.User : null
|
const user = res.locals.oauth ? res.locals.oauth.token.User : null
|
||||||
|
|
||||||
// Only the owner or a user that have blacklist rights can see the video
|
// Only the owner or a user that have blacklist rights can see the video
|
||||||
if (!user || !user.canGetVideo(videoAll)) {
|
if (!user || !user.canGetVideo(video)) {
|
||||||
return res.status(HttpStatusCode.FORBIDDEN_403)
|
return res.status(HttpStatusCode.FORBIDDEN_403)
|
||||||
.json({ error: 'Cannot get this private/internal or blacklisted video.' })
|
.json({ error: 'Cannot get this private/internal or blacklisted video.' })
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ import {
|
||||||
MUserFormattable,
|
MUserFormattable,
|
||||||
MUserNotifSettingChannelDefault,
|
MUserNotifSettingChannelDefault,
|
||||||
MUserWithNotificationSetting,
|
MUserWithNotificationSetting,
|
||||||
MVideoFullLight
|
MVideoFullLight,
|
||||||
|
MVideoWithRights
|
||||||
} from '@server/types/models'
|
} from '@server/types/models'
|
||||||
import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users'
|
import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users'
|
||||||
import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models'
|
import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models'
|
||||||
|
@ -819,7 +820,7 @@ export class UserModel extends Model {
|
||||||
.then(u => u.map(u => u.username))
|
.then(u => u.map(u => u.username))
|
||||||
}
|
}
|
||||||
|
|
||||||
canGetVideo (video: MVideoFullLight) {
|
canGetVideo (video: MVideoWithRights) {
|
||||||
const videoUserId = video.VideoChannel.Account.userId
|
const videoUserId = video.VideoChannel.Account.userId
|
||||||
|
|
||||||
if (video.isBlacklisted()) {
|
if (video.isBlacklisted()) {
|
||||||
|
|
|
@ -356,6 +356,7 @@ export type AvailableForListIDsOptions = {
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: VideoFileModel,
|
model: VideoFileModel,
|
||||||
|
separate: true,
|
||||||
required: false,
|
required: false,
|
||||||
include: subInclude
|
include: subInclude
|
||||||
}
|
}
|
||||||
|
@ -383,6 +384,7 @@ export type AvailableForListIDsOptions = {
|
||||||
{
|
{
|
||||||
model: VideoStreamingPlaylistModel.unscoped(),
|
model: VideoStreamingPlaylistModel.unscoped(),
|
||||||
required: false,
|
required: false,
|
||||||
|
separate: true,
|
||||||
include: subInclude
|
include: subInclude
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1312,8 +1314,7 @@ export class VideoModel extends Model {
|
||||||
|
|
||||||
return VideoModel.scope([
|
return VideoModel.scope([
|
||||||
ScopeNames.WITH_BLACKLISTED,
|
ScopeNames.WITH_BLACKLISTED,
|
||||||
ScopeNames.WITH_USER_ID,
|
ScopeNames.WITH_USER_ID
|
||||||
ScopeNames.WITH_THUMBNAILS
|
|
||||||
]).findOne(options)
|
]).findOne(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,6 @@ export type MVideoAccountLight =
|
||||||
export type MVideoWithRights =
|
export type MVideoWithRights =
|
||||||
MVideo &
|
MVideo &
|
||||||
Use<'VideoBlacklist', MVideoBlacklistLight> &
|
Use<'VideoBlacklist', MVideoBlacklistLight> &
|
||||||
Use<'Thumbnails', MThumbnail[]> &
|
|
||||||
Use<'VideoChannel', MChannelUserId>
|
Use<'VideoChannel', MChannelUserId>
|
||||||
|
|
||||||
// ############################################################################
|
// ############################################################################
|
||||||
|
|
Loading…
Reference in New Issue