From f479685678406a5df864d89615b33d29085ebfc6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Apr 2021 11:35:56 +0200 Subject: Agnostic actor image storage --- server/models/activitypub/actor.ts | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'server/models/activitypub/actor.ts') diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 3b98e8841..09d96b24d 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -19,7 +19,7 @@ import { } from 'sequelize-typescript' import { ModelCache } from '@server/models/model-cache' import { ActivityIconObject, ActivityPubActorType } from '../../../shared/models/activitypub' -import { Avatar } from '../../../shared/models/avatars/avatar.model' +import { ActorImage } from '../../../shared/models/actors/actor-image.model' import { activityPubContextify } from '../../helpers/activitypub' import { isActorFollowersCountValid, @@ -43,7 +43,7 @@ import { MActorWithInboxes } from '../../types/models' import { AccountModel } from '../account/account' -import { AvatarModel } from '../avatar/avatar' +import { ActorImageModel } from '../account/actor-image' import { ServerModel } from '../server/server' import { isOutdated, throwIfNotValid } from '../utils' import { VideoModel } from '../video/video' @@ -73,7 +73,8 @@ export const unusedActorAttributesForAPI = [ required: false }, { - model: AvatarModel, + model: ActorImageModel, + as: 'Avatar', required: false } ] @@ -100,7 +101,8 @@ export const unusedActorAttributesForAPI = [ required: false }, { - model: AvatarModel, + model: ActorImageModel, + as: 'Avatar', required: false } ] @@ -213,18 +215,35 @@ export class ActorModel extends Model { @UpdatedAt updatedAt: Date - @ForeignKey(() => AvatarModel) + @ForeignKey(() => ActorImageModel) @Column avatarId: number - @BelongsTo(() => AvatarModel, { + @ForeignKey(() => ActorImageModel) + @Column + bannerId: number + + @BelongsTo(() => ActorImageModel, { + foreignKey: { + name: 'avatarId', + allowNull: true + }, + as: 'Avatar', + onDelete: 'set null', + hooks: true + }) + Avatar: ActorImageModel + + @BelongsTo(() => ActorImageModel, { foreignKey: { + name: 'bannerId', allowNull: true }, + as: 'Banner', onDelete: 'set null', hooks: true }) - Avatar: AvatarModel + Banner: ActorImageModel @HasMany(() => ActorFollowModel, { foreignKey: { @@ -496,7 +515,7 @@ export class ActorModel extends Model { } toFormattedSummaryJSON (this: MActorSummaryFormattable) { - let avatar: Avatar = null + let avatar: ActorImage = null if (this.Avatar) { avatar = this.Avatar.toFormattedJSON() } -- cgit v1.2.3