diff options
Diffstat (limited to 'server/models/activitypub')
-rw-r--r-- | server/models/activitypub/actor-follow.ts | 7 | ||||
-rw-r--r-- | server/models/activitypub/actor.ts | 87 |
2 files changed, 74 insertions, 20 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts index ce6a4e267..4c5f37620 100644 --- a/server/models/activitypub/actor-follow.ts +++ b/server/models/activitypub/actor-follow.ts | |||
@@ -248,13 +248,6 @@ export class ActorFollowModel extends Model { | |||
248 | } | 248 | } |
249 | 249 | ||
250 | return ActorFollowModel.findOne(query) | 250 | return ActorFollowModel.findOne(query) |
251 | .then(result => { | ||
252 | if (result?.ActorFollowing.VideoChannel) { | ||
253 | result.ActorFollowing.VideoChannel.Actor = result.ActorFollowing | ||
254 | } | ||
255 | |||
256 | return result | ||
257 | }) | ||
258 | } | 251 | } |
259 | 252 | ||
260 | static listSubscribedIn (actorId: number, targets: { name: string, host?: string }[]): Promise<MActorFollowFollowingHost[]> { | 253 | static listSubscribedIn (actorId: number, targets: { name: string, host?: string }[]): Promise<MActorFollowFollowingHost[]> { |
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 3b98e8841..19f3f7e04 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts | |||
@@ -19,7 +19,7 @@ import { | |||
19 | } from 'sequelize-typescript' | 19 | } from 'sequelize-typescript' |
20 | import { ModelCache } from '@server/models/model-cache' | 20 | import { ModelCache } from '@server/models/model-cache' |
21 | import { ActivityIconObject, ActivityPubActorType } from '../../../shared/models/activitypub' | 21 | import { ActivityIconObject, ActivityPubActorType } from '../../../shared/models/activitypub' |
22 | import { Avatar } from '../../../shared/models/avatars/avatar.model' | 22 | import { ActorImage } from '../../../shared/models/actors/actor-image.model' |
23 | import { activityPubContextify } from '../../helpers/activitypub' | 23 | import { activityPubContextify } from '../../helpers/activitypub' |
24 | import { | 24 | import { |
25 | isActorFollowersCountValid, | 25 | isActorFollowersCountValid, |
@@ -29,11 +29,19 @@ import { | |||
29 | isActorPublicKeyValid | 29 | isActorPublicKeyValid |
30 | } from '../../helpers/custom-validators/activitypub/actor' | 30 | } from '../../helpers/custom-validators/activitypub/actor' |
31 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 31 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
32 | import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' | 32 | import { |
33 | ACTIVITY_PUB, | ||
34 | ACTIVITY_PUB_ACTOR_TYPES, | ||
35 | CONSTRAINTS_FIELDS, | ||
36 | MIMETYPES, | ||
37 | SERVER_ACTOR_NAME, | ||
38 | WEBSERVER | ||
39 | } from '../../initializers/constants' | ||
33 | import { | 40 | import { |
34 | MActor, | 41 | MActor, |
35 | MActorAccountChannelId, | 42 | MActorAccountChannelId, |
36 | MActorAP, | 43 | MActorAPAccount, |
44 | MActorAPChannel, | ||
37 | MActorFormattable, | 45 | MActorFormattable, |
38 | MActorFull, | 46 | MActorFull, |
39 | MActorHost, | 47 | MActorHost, |
@@ -43,7 +51,7 @@ import { | |||
43 | MActorWithInboxes | 51 | MActorWithInboxes |
44 | } from '../../types/models' | 52 | } from '../../types/models' |
45 | import { AccountModel } from '../account/account' | 53 | import { AccountModel } from '../account/account' |
46 | import { AvatarModel } from '../avatar/avatar' | 54 | import { ActorImageModel } from '../account/actor-image' |
47 | import { ServerModel } from '../server/server' | 55 | import { ServerModel } from '../server/server' |
48 | import { isOutdated, throwIfNotValid } from '../utils' | 56 | import { isOutdated, throwIfNotValid } from '../utils' |
49 | import { VideoModel } from '../video/video' | 57 | import { VideoModel } from '../video/video' |
@@ -73,7 +81,8 @@ export const unusedActorAttributesForAPI = [ | |||
73 | required: false | 81 | required: false |
74 | }, | 82 | }, |
75 | { | 83 | { |
76 | model: AvatarModel, | 84 | model: ActorImageModel, |
85 | as: 'Avatar', | ||
77 | required: false | 86 | required: false |
78 | } | 87 | } |
79 | ] | 88 | ] |
@@ -100,7 +109,13 @@ export const unusedActorAttributesForAPI = [ | |||
100 | required: false | 109 | required: false |
101 | }, | 110 | }, |
102 | { | 111 | { |
103 | model: AvatarModel, | 112 | model: ActorImageModel, |
113 | as: 'Avatar', | ||
114 | required: false | ||
115 | }, | ||
116 | { | ||
117 | model: ActorImageModel, | ||
118 | as: 'Banner', | ||
104 | required: false | 119 | required: false |
105 | } | 120 | } |
106 | ] | 121 | ] |
@@ -213,18 +228,35 @@ export class ActorModel extends Model { | |||
213 | @UpdatedAt | 228 | @UpdatedAt |
214 | updatedAt: Date | 229 | updatedAt: Date |
215 | 230 | ||
216 | @ForeignKey(() => AvatarModel) | 231 | @ForeignKey(() => ActorImageModel) |
217 | @Column | 232 | @Column |
218 | avatarId: number | 233 | avatarId: number |
219 | 234 | ||
220 | @BelongsTo(() => AvatarModel, { | 235 | @ForeignKey(() => ActorImageModel) |
236 | @Column | ||
237 | bannerId: number | ||
238 | |||
239 | @BelongsTo(() => ActorImageModel, { | ||
221 | foreignKey: { | 240 | foreignKey: { |
241 | name: 'avatarId', | ||
222 | allowNull: true | 242 | allowNull: true |
223 | }, | 243 | }, |
244 | as: 'Avatar', | ||
224 | onDelete: 'set null', | 245 | onDelete: 'set null', |
225 | hooks: true | 246 | hooks: true |
226 | }) | 247 | }) |
227 | Avatar: AvatarModel | 248 | Avatar: ActorImageModel |
249 | |||
250 | @BelongsTo(() => ActorImageModel, { | ||
251 | foreignKey: { | ||
252 | name: 'bannerId', | ||
253 | allowNull: true | ||
254 | }, | ||
255 | as: 'Banner', | ||
256 | onDelete: 'set null', | ||
257 | hooks: true | ||
258 | }) | ||
259 | Banner: ActorImageModel | ||
228 | 260 | ||
229 | @HasMany(() => ActorFollowModel, { | 261 | @HasMany(() => ActorFollowModel, { |
230 | foreignKey: { | 262 | foreignKey: { |
@@ -496,7 +528,7 @@ export class ActorModel extends Model { | |||
496 | } | 528 | } |
497 | 529 | ||
498 | toFormattedSummaryJSON (this: MActorSummaryFormattable) { | 530 | toFormattedSummaryJSON (this: MActorSummaryFormattable) { |
499 | let avatar: Avatar = null | 531 | let avatar: ActorImage = null |
500 | if (this.Avatar) { | 532 | if (this.Avatar) { |
501 | avatar = this.Avatar.toFormattedJSON() | 533 | avatar = this.Avatar.toFormattedJSON() |
502 | } | 534 | } |
@@ -512,29 +544,51 @@ export class ActorModel extends Model { | |||
512 | toFormattedJSON (this: MActorFormattable) { | 544 | toFormattedJSON (this: MActorFormattable) { |
513 | const base = this.toFormattedSummaryJSON() | 545 | const base = this.toFormattedSummaryJSON() |
514 | 546 | ||
547 | let banner: ActorImage = null | ||
548 | if (this.Banner) { | ||
549 | banner = this.Banner.toFormattedJSON() | ||
550 | } | ||
551 | |||
515 | return Object.assign(base, { | 552 | return Object.assign(base, { |
516 | id: this.id, | 553 | id: this.id, |
517 | hostRedundancyAllowed: this.getRedundancyAllowed(), | 554 | hostRedundancyAllowed: this.getRedundancyAllowed(), |
518 | followingCount: this.followingCount, | 555 | followingCount: this.followingCount, |
519 | followersCount: this.followersCount, | 556 | followersCount: this.followersCount, |
557 | banner, | ||
520 | createdAt: this.createdAt, | 558 | createdAt: this.createdAt, |
521 | updatedAt: this.updatedAt | 559 | updatedAt: this.updatedAt |
522 | }) | 560 | }) |
523 | } | 561 | } |
524 | 562 | ||
525 | toActivityPubObject (this: MActorAP, name: string) { | 563 | toActivityPubObject (this: MActorAPChannel | MActorAPAccount, name: string) { |
526 | let icon: ActivityIconObject | 564 | let icon: ActivityIconObject |
565 | let image: ActivityIconObject | ||
527 | 566 | ||
528 | if (this.avatarId) { | 567 | if (this.avatarId) { |
529 | const extension = extname(this.Avatar.filename) | 568 | const extension = extname(this.Avatar.filename) |
530 | 569 | ||
531 | icon = { | 570 | icon = { |
532 | type: 'Image', | 571 | type: 'Image', |
533 | mediaType: extension === '.png' ? 'image/png' : 'image/jpeg', | 572 | mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension], |
573 | height: this.Avatar.height, | ||
574 | width: this.Avatar.width, | ||
534 | url: this.getAvatarUrl() | 575 | url: this.getAvatarUrl() |
535 | } | 576 | } |
536 | } | 577 | } |
537 | 578 | ||
579 | if (this.bannerId) { | ||
580 | const banner = (this as MActorAPChannel).Banner | ||
581 | const extension = extname(banner.filename) | ||
582 | |||
583 | image = { | ||
584 | type: 'Image', | ||
585 | mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension], | ||
586 | height: banner.height, | ||
587 | width: banner.width, | ||
588 | url: this.getBannerUrl() | ||
589 | } | ||
590 | } | ||
591 | |||
538 | const json = { | 592 | const json = { |
539 | type: this.type, | 593 | type: this.type, |
540 | id: this.url, | 594 | id: this.url, |
@@ -554,7 +608,8 @@ export class ActorModel extends Model { | |||
554 | owner: this.url, | 608 | owner: this.url, |
555 | publicKeyPem: this.publicKey | 609 | publicKeyPem: this.publicKey |
556 | }, | 610 | }, |
557 | icon | 611 | icon, |
612 | image | ||
558 | } | 613 | } |
559 | 614 | ||
560 | return activityPubContextify(json) | 615 | return activityPubContextify(json) |
@@ -624,6 +679,12 @@ export class ActorModel extends Model { | |||
624 | return WEBSERVER.URL + this.Avatar.getStaticPath() | 679 | return WEBSERVER.URL + this.Avatar.getStaticPath() |
625 | } | 680 | } |
626 | 681 | ||
682 | getBannerUrl () { | ||
683 | if (!this.bannerId) return undefined | ||
684 | |||
685 | return WEBSERVER.URL + this.Banner.getStaticPath() | ||
686 | } | ||
687 | |||
627 | isOutdated () { | 688 | isOutdated () { |
628 | if (this.isOwned()) return false | 689 | if (this.isOwned()) return false |
629 | 690 | ||