]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-update.ts
Move AP video channel creation
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-update.ts
index 6cd9d0fbae3eb03fdf9ae145c696df4b55707c02..516bd8d706818c37cb6b1331392bfc323ec3adef 100644 (file)
@@ -12,12 +12,12 @@ import { AccountModel } from '../../../models/account/account'
 import { ActorModel } from '../../../models/actor/actor'
 import { VideoChannelModel } from '../../../models/video/video-channel'
 import { APProcessorOptions } from '../../../types/activitypub-processor.model'
-import { MAccountIdActor, MActorSignature } from '../../../types/models'
+import { MActorSignature } from '../../../types/models'
 import { getImageInfoIfExists, updateActorImageInstance, updateActorInstance } from '../actor'
 import { createOrUpdateCacheFile } from '../cache-file'
 import { createOrUpdateVideoPlaylist } from '../playlist'
 import { forwardVideoRelatedActivity } from '../send/utils'
-import { getOrCreateVideoAndAccountAndChannel, getOrCreateVideoChannelFromVideoObject, updateVideoFromAP } from '../videos'
+import { APVideoUpdater, getOrCreateVideoAndAccountAndChannel } from '../videos'
 
 async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate>) {
   const { activity, byActor } = options
@@ -25,7 +25,7 @@ async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate
   const objectType = activity.object.type
 
   if (objectType === 'Video') {
-    return retryTransactionWrapper(processUpdateVideo, byActor, activity)
+    return retryTransactionWrapper(processUpdateVideo, activity)
   }
 
   if (objectType === 'Person' || objectType === 'Application' || objectType === 'Group') {
@@ -55,7 +55,7 @@ export {
 
 // ---------------------------------------------------------------------------
 
-async function processUpdateVideo (actor: MActorSignature, activity: ActivityUpdate) {
+async function processUpdateVideo (activity: ActivityUpdate) {
   const videoObject = activity.object as VideoObject
 
   if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) {
@@ -71,20 +71,8 @@ async function processUpdateVideo (actor: MActorSignature, activity: ActivityUpd
   // We did not have this video, it has been created so no need to update
   if (created) return
 
-  // Load new channel
-  const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject)
-
-  const account = actor.Account as MAccountIdActor
-  account.Actor = actor
-
-  const updateOptions = {
-    video,
-    videoObject,
-    account,
-    channel: channelActor.VideoChannel,
-    overrideTo: activity.to
-  }
-  return updateVideoFromAP(updateOptions)
+  const updater = new APVideoUpdater(videoObject, video)
+  return updater.update(activity.to)
 }
 
 async function processUpdateCacheFile (byActor: MActorSignature, activity: ActivityUpdate) {