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[]
32 static GET_ACTOR_AVATAR_URL (actor: { avatars: { width: number, url?: string, path: string }[] }, size: number) {
33 return Actor.GET_ACTOR_AVATAR_URL(actor, size)
36 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
37 if (!channel || channel.banners.length === 0) {
41 const banner = channel.banners[0]
42 if (!banner) return ''
44 if (banner.url) return banner.url
45 return getAbsoluteAPIUrl() + banner.path
48 static GET_DEFAULT_AVATAR_URL (size: number) {
50 return `${window.location.origin}/client/assets/images/default-avatar-video-channel-48x48.png`
53 return `${window.location.origin}/client/assets/images/default-avatar-video-channel.png`
56 constructor (hash: Partial<ServerVideoChannel>) {
59 this.displayName = hash.displayName
60 this.description = hash.description
61 this.support = hash.support
63 this.banners = hash.banners || []
65 this.isLocal = hash.isLocal
67 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
68 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
70 this.videosCount = hash.videosCount
72 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
74 if (hash.viewsPerDay) {
75 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
78 if (hash.totalViews !== null && hash.totalViews !== undefined) {
79 this.totalViews = hash.totalViews
82 if (hash.ownerAccount) {
83 this.ownerAccount = hash.ownerAccount
84 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
87 this.updateComputedAttributes()
90 updateAvatar (newAvatars: ActorImage[]) {
91 this.avatars = newAvatars
93 this.updateComputedAttributes()
100 updateBanner (newBanners: ActorImage[]) {
101 this.banners = newBanners
103 this.updateComputedAttributes()
107 this.updateBanner([])
110 updateComputedAttributes () {
111 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)