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 || channel.banners.length === 0) {
40 const banner = channel.banners[0]
41 if (!banner) return ''
43 if (banner.url) return banner.url
44 return getAbsoluteAPIUrl() + banner.path
47 static GET_DEFAULT_AVATAR_URL (size: number) {
49 return `${window.location.origin}/client/assets/images/default-avatar-video-channel-48x48.png`
52 return `${window.location.origin}/client/assets/images/default-avatar-video-channel.png`
55 constructor (hash: Partial<ServerVideoChannel>) {
58 this.displayName = hash.displayName
59 this.description = hash.description
60 this.support = hash.support
62 this.banners = hash.banners || []
64 this.isLocal = hash.isLocal
66 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
67 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
69 this.videosCount = hash.videosCount
71 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
73 if (hash.viewsPerDay) {
74 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
77 if (hash.ownerAccount) {
78 this.ownerAccount = hash.ownerAccount
79 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
82 this.updateComputedAttributes()
85 updateAvatar (newAvatars: ActorImage[]) {
86 this.avatars = newAvatars
88 this.updateComputedAttributes()
95 updateBanner (newBanners: ActorImage[]) {
96 this.banners = newBanners
98 this.updateComputedAttributes()
102 this.updateBanner([])
105 updateComputedAttributes () {
106 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)