]> 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 ad3bb392dd8cf4ae121519eaaef939507829b835..516bd8d706818c37cb6b1331392bfc323ec3adef 100644 (file)
@@ -1,23 +1,23 @@
+import { isRedundancyAccepted } from '@server/lib/redundancy'
+import { ActorImageType } from '@shared/models'
 import { ActivityUpdate, CacheFileObject, VideoObject } from '../../../../shared/models/activitypub'
 import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor'
+import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object'
+import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file'
+import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos'
 import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils'
 import { logger } from '../../../helpers/logger'
 import { sequelizeTypescript } from '../../../initializers/database'
 import { AccountModel } from '../../../models/account/account'
-import { ActorModel } from '../../../models/activitypub/actor'
+import { ActorModel } from '../../../models/actor/actor'
 import { VideoChannelModel } from '../../../models/video/video-channel'
+import { APProcessorOptions } from '../../../types/activitypub-processor.model'
+import { MActorSignature } from '../../../types/models'
 import { getImageInfoIfExists, updateActorImageInstance, updateActorInstance } from '../actor'
-import { getOrCreateVideoAndAccountAndChannel, getOrCreateVideoChannelFromVideoObject, updateVideoFromAP } from '../videos'
-import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos'
-import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file'
 import { createOrUpdateCacheFile } from '../cache-file'
-import { forwardVideoRelatedActivity } from '../send/utils'
-import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object'
 import { createOrUpdateVideoPlaylist } from '../playlist'
-import { APProcessorOptions } from '../../../types/activitypub-processor.model'
-import { MActorSignature, MAccountIdActor } from '../../../types/models'
-import { isRedundancyAccepted } from '@server/lib/redundancy'
-import { ActorImageType } from '@shared/models'
+import { forwardVideoRelatedActivity } from '../send/utils'
+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) {
@@ -134,13 +122,8 @@ async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate)
 
       await updateActorInstance(actor, actorAttributesToUpdate)
 
-      for (const imageInfo of [ avatarInfo, bannerInfo ]) {
-        if (!imageInfo) continue
-
-        const imageOptions = Object.assign({}, imageInfo, { onDisk: false })
-
-        await updateActorImageInstance(actor, imageOptions, t)
-      }
+      await updateActorImageInstance(actor, ActorImageType.AVATAR, avatarInfo, t)
+      await updateActorImageInstance(actor, ActorImageType.BANNER, bannerInfo, t)
 
       await actor.save({ transaction: t })