1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { Account as ServerAccount, ActorImage, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models'
3 import { Account } from '../account/account.model'
4 import { Actor } from '../account/actor.model'
6 export class VideoChannel extends Actor implements ServerVideoChannel {
14 nameWithHostForced: string
19 updatedAt: Date | string
21 ownerAccount?: ServerAccount
26 viewsPerDay?: ViewsPerDate[]
28 static GET_ACTOR_AVATAR_URL (actor: object) {
29 return Actor.GET_ACTOR_AVATAR_URL(actor)
32 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
33 if (channel?.banner?.url) return channel.banner.url
35 if (channel && channel.banner) {
36 const absoluteAPIUrl = getAbsoluteAPIUrl()
38 return absoluteAPIUrl + channel.banner.path
44 static GET_DEFAULT_AVATAR_URL () {
45 return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
48 constructor (hash: Partial<ServerVideoChannel>) {
51 this.displayName = hash.displayName
52 this.description = hash.description
53 this.support = hash.support
55 this.banner = hash.banner
57 this.isLocal = hash.isLocal
59 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
60 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
62 this.videosCount = hash.videosCount
64 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
66 if (hash.viewsPerDay) {
67 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
70 if (hash.ownerAccount) {
71 this.ownerAccount = hash.ownerAccount
72 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
75 this.updateComputedAttributes()
78 updateAvatar (newAvatar: ActorImage) {
79 this.avatar = newAvatar
81 this.updateComputedAttributes()
85 this.updateAvatar(null)
88 updateBanner (newBanner: ActorImage) {
89 this.banner = newBanner
91 this.updateComputedAttributes()
95 this.updateBanner(null)
98 updateComputedAttributes () {
99 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)