aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub/actor.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/activitypub/actor.ts')
-rw-r--r--server/models/activitypub/actor.ts47
1 files changed, 42 insertions, 5 deletions
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 09d96b24d..6595f11e2 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -29,11 +29,19 @@ import {
29 isActorPublicKeyValid 29 isActorPublicKeyValid
30} from '../../helpers/custom-validators/activitypub/actor' 30} from '../../helpers/custom-validators/activitypub/actor'
31import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 31import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
32import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' 32import {
33 ACTIVITY_PUB,
34 ACTIVITY_PUB_ACTOR_TYPES,
35 CONSTRAINTS_FIELDS,
36 MIMETYPES,
37 SERVER_ACTOR_NAME,
38 WEBSERVER
39} from '../../initializers/constants'
33import { 40import {
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,
@@ -104,6 +112,11 @@ export const unusedActorAttributesForAPI = [
104 model: ActorImageModel, 112 model: ActorImageModel,
105 as: 'Avatar', 113 as: 'Avatar',
106 required: false 114 required: false
115 },
116 {
117 model: ActorImageModel,
118 as: 'Banner',
119 required: false
107 } 120 }
108 ] 121 ]
109 } 122 }
@@ -531,29 +544,46 @@ export class ActorModel extends Model {
531 toFormattedJSON (this: MActorFormattable) { 544 toFormattedJSON (this: MActorFormattable) {
532 const base = this.toFormattedSummaryJSON() 545 const base = this.toFormattedSummaryJSON()
533 546
547 let banner: ActorImage = null
548 if (this.bannerId) {
549 banner = this.Banner.toFormattedJSON()
550 }
551
534 return Object.assign(base, { 552 return Object.assign(base, {
535 id: this.id, 553 id: this.id,
536 hostRedundancyAllowed: this.getRedundancyAllowed(), 554 hostRedundancyAllowed: this.getRedundancyAllowed(),
537 followingCount: this.followingCount, 555 followingCount: this.followingCount,
538 followersCount: this.followersCount, 556 followersCount: this.followersCount,
557 banner,
539 createdAt: this.createdAt, 558 createdAt: this.createdAt,
540 updatedAt: this.updatedAt 559 updatedAt: this.updatedAt
541 }) 560 })
542 } 561 }
543 562
544 toActivityPubObject (this: MActorAP, name: string) { 563 toActivityPubObject (this: MActorAPChannel | MActorAPAccount, name: string) {
545 let icon: ActivityIconObject 564 let icon: ActivityIconObject
565 let image: ActivityIconObject
546 566
547 if (this.avatarId) { 567 if (this.avatarId) {
548 const extension = extname(this.Avatar.filename) 568 const extension = extname(this.Avatar.filename)
549 569
550 icon = { 570 icon = {
551 type: 'Image', 571 type: 'Image',
552 mediaType: extension === '.png' ? 'image/png' : 'image/jpeg', 572 mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension],
553 url: this.getAvatarUrl() 573 url: this.getAvatarUrl()
554 } 574 }
555 } 575 }
556 576
577 if (this.bannerId) {
578 const extension = extname((this as MActorAPChannel).Banner.filename)
579
580 image = {
581 type: 'Image',
582 mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension],
583 url: this.getBannerUrl()
584 }
585 }
586
557 const json = { 587 const json = {
558 type: this.type, 588 type: this.type,
559 id: this.url, 589 id: this.url,
@@ -573,7 +603,8 @@ export class ActorModel extends Model {
573 owner: this.url, 603 owner: this.url,
574 publicKeyPem: this.publicKey 604 publicKeyPem: this.publicKey
575 }, 605 },
576 icon 606 icon,
607 image
577 } 608 }
578 609
579 return activityPubContextify(json) 610 return activityPubContextify(json)
@@ -643,6 +674,12 @@ export class ActorModel extends Model {
643 return WEBSERVER.URL + this.Avatar.getStaticPath() 674 return WEBSERVER.URL + this.Avatar.getStaticPath()
644 } 675 }
645 676
677 getBannerUrl () {
678 if (!this.bannerId) return undefined
679
680 return WEBSERVER.URL + this.Banner.getStaticPath()
681 }
682
646 isOutdated () { 683 isOutdated () {
647 if (this.isOwned()) return false 684 if (this.isOwned()) return false
648 685