]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/activitypub/actor.ts
Merge branch 'release/3.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / models / activitypub / actor.ts
index 09d96b24dc29fd028d6328fba8e0ddbe2a1faa75..a6c724f26634bf5876c216048feb8a1c55d016dc 100644 (file)
@@ -29,11 +29,19 @@ import {
   isActorPublicKeyValid
 } from '../../helpers/custom-validators/activitypub/actor'
 import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
-import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants'
+import {
+  ACTIVITY_PUB,
+  ACTIVITY_PUB_ACTOR_TYPES,
+  CONSTRAINTS_FIELDS,
+  MIMETYPES,
+  SERVER_ACTOR_NAME,
+  WEBSERVER
+} from '../../initializers/constants'
 import {
   MActor,
   MActorAccountChannelId,
-  MActorAP,
+  MActorAPAccount,
+  MActorAPChannel,
   MActorFormattable,
   MActorFull,
   MActorHost,
@@ -104,6 +112,11 @@ export const unusedActorAttributesForAPI = [
         model: ActorImageModel,
         as: 'Avatar',
         required: false
+      },
+      {
+        model: ActorImageModel,
+        as: 'Banner',
+        required: false
       }
     ]
   }
@@ -531,29 +544,51 @@ export class ActorModel extends Model {
   toFormattedJSON (this: MActorFormattable) {
     const base = this.toFormattedSummaryJSON()
 
+    let banner: ActorImage = null
+    if (this.bannerId) {
+      banner = this.Banner.toFormattedJSON()
+    }
+
     return Object.assign(base, {
       id: this.id,
       hostRedundancyAllowed: this.getRedundancyAllowed(),
       followingCount: this.followingCount,
       followersCount: this.followersCount,
+      banner,
       createdAt: this.createdAt,
       updatedAt: this.updatedAt
     })
   }
 
-  toActivityPubObject (this: MActorAP, name: string) {
+  toActivityPubObject (this: MActorAPChannel | MActorAPAccount, name: string) {
     let icon: ActivityIconObject
+    let image: ActivityIconObject
 
     if (this.avatarId) {
       const extension = extname(this.Avatar.filename)
 
       icon = {
         type: 'Image',
-        mediaType: extension === '.png' ? 'image/png' : 'image/jpeg',
+        mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension],
+        height: this.Avatar.height,
+        width: this.Avatar.width,
         url: this.getAvatarUrl()
       }
     }
 
+    if (this.bannerId) {
+      const banner = (this as MActorAPChannel).Banner
+      const extension = extname(banner.filename)
+
+      image = {
+        type: 'Image',
+        mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension],
+        height: banner.height,
+        width: banner.width,
+        url: this.getBannerUrl()
+      }
+    }
+
     const json = {
       type: this.type,
       id: this.url,
@@ -573,7 +608,8 @@ export class ActorModel extends Model {
         owner: this.url,
         publicKeyPem: this.publicKey
       },
-      icon
+      icon,
+      image
     }
 
     return activityPubContextify(json)
@@ -643,6 +679,12 @@ export class ActorModel extends Model {
     return WEBSERVER.URL + this.Avatar.getStaticPath()
   }
 
+  getBannerUrl () {
+    if (!this.bannerId) return undefined
+
+    return WEBSERVER.URL + this.Banner.getStaticPath()
+  }
+
   isOutdated () {
     if (this.isOwned()) return false