1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { Account as ServerAccount, ActorImage, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models'
3 import { Actor } from '../account/actor.model'
5 export class VideoChannel extends Actor implements ServerVideoChannel {
13 nameWithHostForced: string
18 updatedAt: Date | string
20 ownerAccount?: ServerAccount
25 viewsPerDay?: ViewsPerDate[]
27 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
28 return Actor.GET_ACTOR_AVATAR_URL(actor)
31 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
32 if (channel?.banner?.url) return channel.banner.url
34 if (channel?.banner) {
35 const absoluteAPIUrl = getAbsoluteAPIUrl()
37 return absoluteAPIUrl + channel.banner.path
43 static GET_DEFAULT_AVATAR_URL () {
44 return `${window.location.origin}/client/assets/images/default-avatar-video-channel.png`
47 constructor (hash: Partial<ServerVideoChannel>) {
50 this.displayName = hash.displayName
51 this.description = hash.description
52 this.support = hash.support
54 this.banner = hash.banner
56 this.isLocal = hash.isLocal
58 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
59 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
61 this.videosCount = hash.videosCount
63 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
65 if (hash.viewsPerDay) {
66 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
69 if (hash.ownerAccount) {
70 this.ownerAccount = hash.ownerAccount
71 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
74 this.updateComputedAttributes()
77 updateAvatar (newAvatar: ActorImage) {
78 this.avatar = newAvatar
80 this.updateComputedAttributes()
84 this.updateAvatar(null)
87 updateBanner (newBanner: ActorImage) {
88 this.banner = newBanner
90 this.updateComputedAttributes()
94 this.updateBanner(null)
97 updateComputedAttributes () {
98 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)