]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-update.ts
Split files in activitypub server
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-update.ts
index 566e5938b3b918707fe058dfb9435dfa62e61e19..2750f48c3692eeb75195fd9a7bf2359a9a2a6b7f 100644 (file)
@@ -15,6 +15,7 @@ import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvat
 import {
   generateThumbnailFromUrl,
   getOrCreateAccountAndVideoAndChannel,
+  getOrCreateVideoChannel,
   videoActivityObjectToDBAttributes,
   videoFileActivityUrlToDBAttributes
 } from '../videos'
@@ -54,6 +55,10 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
 
   const res = await getOrCreateAccountAndVideoAndChannel(videoAttributesToUpdate.id)
 
+  // Fetch video channel outside the transaction
+  const newVideoChannelActor = await getOrCreateVideoChannel(videoAttributesToUpdate)
+  const newVideoChannel = newVideoChannelActor.VideoChannel
+
   logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid)
   let videoInstance = res.video
   let videoFieldsSave: any
@@ -66,12 +71,13 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
 
       videoFieldsSave = videoInstance.toJSON()
 
+      // Check actor has the right to update the video
       const videoChannel = videoInstance.VideoChannel
       if (videoChannel.Account.Actor.id !== actor.id) {
         throw new Error('Account ' + actor.url + ' does not own video channel ' + videoChannel.Actor.url)
       }
 
-      const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoAttributesToUpdate, activity.to, activity.cc)
+      const videoData = await videoActivityObjectToDBAttributes(newVideoChannel, videoAttributesToUpdate, activity.to)
       videoInstance.set('name', videoData.name)
       videoInstance.set('uuid', videoData.uuid)
       videoInstance.set('url', videoData.url)
@@ -87,12 +93,13 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
       videoInstance.set('updatedAt', videoData.updatedAt)
       videoInstance.set('views', videoData.views)
       videoInstance.set('privacy', videoData.privacy)
+      videoInstance.set('channelId', videoData.channelId)
 
       await videoInstance.save(sequelizeOptions)
 
       // Don't block on request
       generateThumbnailFromUrl(videoInstance, videoAttributesToUpdate.icon)
-        .catch(err => logger.warn('Cannot generate thumbnail of %s.', videoAttributesToUpdate.id, err))
+        .catch(err => logger.warn('Cannot generate thumbnail of %s.', videoAttributesToUpdate.id, { err }))
 
       // Remove old video files
       const videoFileDestroyTasks: Bluebird<void>[] = []
@@ -117,7 +124,7 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
     }
 
     // This is just a debug because we will retry the insert
-    logger.debug('Cannot update the remote video.', err)
+    logger.debug('Cannot update the remote video.', { err })
     throw err
   }
 }
@@ -176,7 +183,7 @@ async function updateRemoteActor (actor: ActorModel, activity: ActivityUpdate) {
     }
 
     // This is just a debug because we will retry the insert
-    logger.debug('Cannot update the remote account.', err)
+    logger.debug('Cannot update the remote account.', { err })
     throw err
   }
 }