]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix redundancy federation in some cases
authorChocobozzz <me@florianbigard.com>
Thu, 17 Dec 2020 08:23:57 +0000 (09:23 +0100)
committerChocobozzz <me@florianbigard.com>
Thu, 17 Dec 2020 08:23:57 +0000 (09:23 +0100)
server/lib/activitypub/send/send-undo.ts
server/lib/activitypub/send/send-update.ts
server/models/redundancy/video-redundancy.ts

index 352c158fd6be237e7fce9befe1a3147b7d3fcb43..d2b738befc164c53447ea5d8675a6e4cebb3d837 100644 (file)
@@ -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 })
index 305edf429d7f6146db535d53bc6e68651909489c..bcf6e15696851c904b936fb33d2966c59b98e705 100644 (file)
@@ -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()
index fa96a1e39c0fa54484e0685d6f0b8571c8d40d46..c536c288ba4d9241d917529ebda9af0f8e5cced6 100644 (file)
@@ -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 () {