From: Chocobozzz Date: Thu, 17 Dec 2020 08:23:57 +0000 (+0100) Subject: Fix redundancy federation in some cases X-Git-Tag: v3.0.0~72 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=9cfeb3cf989fffccdfe3e575903dc00baab255b2;hp=9e454eba570ca459a2dc2bb99ed6a700622e4f32;p=github%2FChocobozzz%2FPeerTube.git Fix redundancy federation in some cases --- diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 352c158fd..d2b738bef 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts @@ -79,8 +79,13 @@ async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: T async function sendUndoCacheFile (byActor: MActor, redundancyModel: MVideoRedundancyVideo, t: Transaction) { logger.info('Creating job to undo cache file %s.', redundancyModel.url) - const videoId = redundancyModel.getVideo().id - const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId) + const associatedVideo = redundancyModel.getVideo() + if (!associatedVideo) { + logger.warn('Cannot send undo activity for redundancy %s: no video files associated.', redundancyModel.url) + return + } + + const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(associatedVideo.id) const createActivity = buildCreateActivity(redundancyModel.url, byActor, redundancyModel.toActivityPubObject()) return sendUndoVideoRelatedActivity({ byActor, video, url: redundancyModel.url, activity: createActivity, transaction: t }) diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 305edf429..bcf6e1569 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts @@ -75,7 +75,13 @@ async function sendUpdateActor (accountOrChannel: MChannelDefault | MAccountDefa async function sendUpdateCacheFile (byActor: MActorLight, redundancyModel: MVideoRedundancyVideo) { logger.info('Creating job to update cache file %s.', redundancyModel.url) - const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(redundancyModel.getVideo().id) + const associatedVideo = redundancyModel.getVideo() + if (!associatedVideo) { + logger.warn('Cannot send update activity for redundancy %s: no video files associated.', redundancyModel.url) + return + } + + const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(associatedVideo.id) const activityBuilder = (audience: ActivityAudience) => { const redundancyObject = redundancyModel.toActivityPubObject() diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index fa96a1e39..c536c288b 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts @@ -651,7 +651,9 @@ export class VideoRedundancyModel extends Model { getVideo () { if (this.VideoFile) return this.VideoFile.Video - return this.VideoStreamingPlaylist.Video + if (this.VideoStreamingPlaylist.Video) return this.VideoStreamingPlaylist.Video + + return undefined } isOwned () {