]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/actors/updater.ts
Fix incorrect error logs
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / actors / updater.ts
index de5e03eee298070ba885bd2f1ba74a52489849e0..fe94af9f1120da0aaa524a970afba66804b3e433 100644 (file)
@@ -1,11 +1,13 @@
 import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils'
 import { logger } from '@server/helpers/logger'
+import { AccountModel } from '@server/models/account/account'
 import { VideoChannelModel } from '@server/models/video/video-channel'
 import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models'
 import { ActivityPubActor, ActorImageType } from '@shared/models'
-import { updateActorImageInstance } from './image'
+import { getOrCreateAPOwner } from './get'
+import { updateActorImages } from './image'
 import { fetchActorFollowsCount } from './shared'
-import { getImageInfoFromObject } from './shared/object-to-model-attributes'
+import { getImagesInfoFromObject } from './shared/object-to-model-attributes'
 
 export class APActorUpdater {
 
@@ -27,8 +29,8 @@ export class APActorUpdater {
   }
 
   async update () {
-    const avatarInfo = getImageInfoFromObject(this.actorObject, ActorImageType.AVATAR)
-    const bannerInfo = getImageInfoFromObject(this.actorObject, ActorImageType.BANNER)
+    const avatarsInfo = getImagesInfoFromObject(this.actorObject, ActorImageType.AVATAR)
+    const bannersInfo = getImagesInfoFromObject(this.actorObject, ActorImageType.BANNER)
 
     try {
       await this.updateActorInstance(this.actor, this.actorObject)
@@ -36,11 +38,17 @@ export class APActorUpdater {
       this.accountOrChannel.name = this.actorObject.name || this.actorObject.preferredUsername
       this.accountOrChannel.description = this.actorObject.summary
 
-      if (this.accountOrChannel instanceof VideoChannelModel) this.accountOrChannel.support = this.actorObject.support
+      if (this.accountOrChannel instanceof VideoChannelModel) {
+        const owner = await getOrCreateAPOwner(this.actorObject, this.actorObject.url)
+        this.accountOrChannel.accountId = owner.Account.id
+        this.accountOrChannel.Account = owner.Account as AccountModel
+
+        this.accountOrChannel.support = this.actorObject.support
+      }
 
       await runInReadCommittedTransaction(async t => {
-        await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t)
-        await updateActorImageInstance(this.actor, ActorImageType.BANNER, bannerInfo, t)
+        await updateActorImages(this.actor, ActorImageType.BANNER, bannersInfo, t)
+        await updateActorImages(this.actor, ActorImageType.AVATAR, avatarsInfo, t)
       })
 
       await runInReadCommittedTransaction(async t => {