]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/video-channel/video-channel.model.ts
Migrate client to eslint
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video-channel / video-channel.model.ts
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'
4
5 export class VideoChannel extends Actor implements ServerVideoChannel {
6 displayName: string
7 description: string
8 support: string
9
10 isLocal: boolean
11
12 nameWithHost: string
13 nameWithHostForced: string
14
15 banner: ActorImage
16 bannerUrl: string
17
18 updatedAt: Date | string
19
20 ownerAccount?: ServerAccount
21 ownerBy?: string
22
23 videosCount?: number
24
25 viewsPerDay?: ViewsPerDate[]
26
27 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
28 return Actor.GET_ACTOR_AVATAR_URL(actor)
29 }
30
31 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
32 if (channel?.banner?.url) return channel.banner.url
33
34 if (channel?.banner) {
35 const absoluteAPIUrl = getAbsoluteAPIUrl()
36
37 return absoluteAPIUrl + channel.banner.path
38 }
39
40 return ''
41 }
42
43 static GET_DEFAULT_AVATAR_URL () {
44 return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
45 }
46
47 constructor (hash: Partial<ServerVideoChannel>) {
48 super(hash)
49
50 this.displayName = hash.displayName
51 this.description = hash.description
52 this.support = hash.support
53
54 this.banner = hash.banner
55
56 this.isLocal = hash.isLocal
57
58 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
59 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
60
61 this.videosCount = hash.videosCount
62
63 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
64
65 if (hash.viewsPerDay) {
66 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
67 }
68
69 if (hash.ownerAccount) {
70 this.ownerAccount = hash.ownerAccount
71 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
72 }
73
74 this.updateComputedAttributes()
75 }
76
77 updateAvatar (newAvatar: ActorImage) {
78 this.avatar = newAvatar
79
80 this.updateComputedAttributes()
81 }
82
83 resetAvatar () {
84 this.updateAvatar(null)
85 }
86
87 updateBanner (newBanner: ActorImage) {
88 this.banner = newBanner
89
90 this.updateComputedAttributes()
91 }
92
93 resetBanner () {
94 this.updateBanner(null)
95 }
96
97 updateComputedAttributes () {
98 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)
99 }
100 }