X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=086269921260907b8b921ffa92bf828d6a55356a;hb=f479685678406a5df864d89615b33d29085ebfc6;hp=b3543ddf2457d9eae0858ab88b5e11c89777a345;hpb=534556052ed4aab539325dccaa16c6dd2acecf73;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index b3543ddf2..086269921 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -100,10 +100,10 @@ import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../types/models import { VideoAbuseModel } from '../abuse/video-abuse' import { AccountModel } from '../account/account' import { AccountVideoRateModel } from '../account/account-video-rate' +import { ActorImageModel } from '../account/actor-image' import { UserModel } from '../account/user' import { UserVideoHistoryModel } from '../account/user-video-history' import { ActorModel } from '../activitypub/actor' -import { AvatarModel } from '../avatar/avatar' import { VideoRedundancyModel } from '../redundancy/video-redundancy' import { ServerModel } from '../server/server' import { TrackerModel } from '../server/tracker' @@ -286,7 +286,8 @@ export type AvailableForListIDsOptions = { required: false }, { - model: AvatarModel.unscoped(), + model: ActorImageModel.unscoped(), + as: 'Avatar', required: false } ] @@ -308,7 +309,8 @@ export type AvailableForListIDsOptions = { required: false }, { - model: AvatarModel.unscoped(), + model: ActorImageModel.unscoped(), + as: 'Avatar', required: false } ] @@ -783,21 +785,20 @@ export class VideoModel extends Model { @BeforeDestroy static async sendDelete (instance: MVideoAccountLight, options) { - if (instance.isOwned()) { - if (!instance.VideoChannel) { - instance.VideoChannel = await instance.$get('VideoChannel', { - include: [ - ActorModel, - AccountModel - ], - transaction: options.transaction - }) as MChannelAccountDefault - } + if (!instance.isOwned()) return undefined - return sendDeleteVideo(instance, options.transaction) + // Lazy load channels + if (!instance.VideoChannel) { + instance.VideoChannel = await instance.$get('VideoChannel', { + include: [ + ActorModel, + AccountModel + ], + transaction: options.transaction + }) as MChannelAccountDefault } - return undefined + return sendDeleteVideo(instance, options.transaction) } @BeforeDestroy @@ -862,6 +863,7 @@ export class VideoModel extends Model { logger.info('Saving video abuses details of video %s.', instance.url) + if (!instance.Trackers) instance.Trackers = await instance.$get('Trackers', { transaction: options.transaction }) const details = instance.toFormattedDetailsJSON() for (const abuse of instance.VideoAbuses) { @@ -1703,7 +1705,7 @@ export class VideoModel extends Model { function buildActor (rowActor: any) { const avatarModel = rowActor.Avatar.id !== null - ? new AvatarModel(pick(rowActor.Avatar, avatarKeys), buildOpts) + ? new ActorImageModel(pick(rowActor.Avatar, avatarKeys), buildOpts) : null const serverModel = rowActor.Server.id !== null