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,
model: ActorImageModel,
as: 'Avatar',
required: false
+ },
+ {
+ model: ActorImageModel,
+ as: 'Banner',
+ required: false
}
]
}
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,
owner: this.url,
publicKeyPem: this.publicKey
},
- icon
+ icon,
+ image
}
return activityPubContextify(json)
return WEBSERVER.URL + this.Avatar.getStaticPath()
}
+ getBannerUrl () {
+ if (!this.bannerId) return undefined
+
+ return WEBSERVER.URL + this.Banner.getStaticPath()
+ }
+
isOutdated () {
if (this.isOwned()) return false