X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Factors%2Fupdater.ts;h=5a92e7a2241cc6c8fbfc129ce7f50e66f244d7be;hb=823c34c07fc0df81110098ee1032e9d3ed70b662;hp=042438d9cc6af43b09f7d63489a3f7ee8ebb4878;hpb=3318147300b4f998adf728eb0a5a14a4c1829c51;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/actors/updater.ts b/server/lib/activitypub/actors/updater.ts index 042438d9c..5a92e7a22 100644 --- a/server/lib/activitypub/actors/updater.ts +++ b/server/lib/activitypub/actors/updater.ts @@ -5,32 +5,25 @@ import { VideoChannelModel } from '@server/models/video/video-channel' import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models' import { ActivityPubActor, ActorImageType } from '@shared/models' import { getOrCreateAPOwner } from './get' -import { updateActorImageInstance } from './image' +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 { - private accountOrChannel: MAccount | MChannel - - private readonly actorFieldsSave: object - private readonly accountOrChannelFieldsSave: object + private readonly accountOrChannel: MAccount | MChannel constructor ( private readonly actorObject: ActivityPubActor, private readonly actor: MActorFull ) { - this.actorFieldsSave = this.actor.toJSON() - if (this.actorObject.type === 'Group') this.accountOrChannel = this.actor.VideoChannel else this.accountOrChannel = this.actor.Account - - this.accountOrChannelFieldsSave = this.accountOrChannel.toJSON() } 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) @@ -47,8 +40,8 @@ export class APActorUpdater { } 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 => { @@ -58,12 +51,12 @@ export class APActorUpdater { logger.info('Remote account %s updated', this.actorObject.url) } catch (err) { - if (this.actor !== undefined && this.actorFieldsSave !== undefined) { - resetSequelizeInstance(this.actor, this.actorFieldsSave) + if (this.actor !== undefined) { + await resetSequelizeInstance(this.actor) } - if (this.accountOrChannel !== undefined && this.accountOrChannelFieldsSave !== undefined) { - resetSequelizeInstance(this.accountOrChannel, this.accountOrChannelFieldsSave) + if (this.accountOrChannel !== undefined) { + await resetSequelizeInstance(this.accountOrChannel) } // This is just a debug because we will retry the insert