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 ownerAccount?: ServerAccount
24 viewsPerDay?: ViewsPerDate[]
26 static GET_ACTOR_AVATAR_URL (actor: object) {
27 return Actor.GET_ACTOR_AVATAR_URL(actor)
30 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
31 if (channel?.banner?.url) return channel.banner.url
33 if (channel && channel.banner) {
34 const absoluteAPIUrl = getAbsoluteAPIUrl()
36 return absoluteAPIUrl + channel.banner.path
42 static GET_DEFAULT_AVATAR_URL () {
43 return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
46 constructor (hash: Partial<ServerVideoChannel>) {
49 this.displayName = hash.displayName
50 this.description = hash.description
51 this.support = hash.support
53 this.banner = hash.banner
55 this.isLocal = hash.isLocal
57 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
58 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
60 this.videosCount = hash.videosCount
62 if (hash.viewsPerDay) {
63 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
66 if (hash.ownerAccount) {
67 this.ownerAccount = hash.ownerAccount
68 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
71 this.updateComputedAttributes()
74 updateAvatar (newAvatar: ActorImage) {
75 this.avatar = newAvatar
77 this.updateComputedAttributes()
81 this.updateAvatar(null)
84 updateBanner (newBanner: ActorImage) {
85 this.banner = newBanner
87 this.updateComputedAttributes()
91 this.updateBanner(null)
94 updateComputedAttributes () {
95 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)