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
15 // TODO: remove, deprecated in 4.2
22 updatedAt: Date | string
24 ownerAccount?: ServerAccount
29 viewsPerDay?: ViewsPerDate[]
31 static GET_ACTOR_AVATAR_URL (actor: { avatars: { width: number, url?: string, path: string }[] }, size: number) {
32 return Actor.GET_ACTOR_AVATAR_URL(actor, size)
35 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
36 if (!channel) return ''
38 const banner = channel.banners[0]
39 if (!banner) return ''
41 if (banner.url) return banner.url
42 return getAbsoluteAPIUrl() + banner.path
45 static GET_DEFAULT_AVATAR_URL (size: number) {
47 return `${window.location.origin}/client/assets/images/default-avatar-video-channel-48x48.png`
50 return `${window.location.origin}/client/assets/images/default-avatar-video-channel.png`
53 constructor (hash: Partial<ServerVideoChannel>) {
56 this.displayName = hash.displayName
57 this.description = hash.description
58 this.support = hash.support
60 this.banners = hash.banners
62 this.isLocal = hash.isLocal
64 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
65 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
67 this.videosCount = hash.videosCount
69 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
71 if (hash.viewsPerDay) {
72 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
75 if (hash.ownerAccount) {
76 this.ownerAccount = hash.ownerAccount
77 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
80 this.updateComputedAttributes()
83 updateAvatar (newAvatars: ActorImage[]) {
84 this.avatars = newAvatars
86 this.updateComputedAttributes()
93 updateBanner (newBanners: ActorImage[]) {
94 this.banners = newBanners
96 this.updateComputedAttributes()
100 this.updateBanner([])
103 updateComputedAttributes () {
104 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)