]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/video-channel/video-channel.model.ts
Set channel banner/avatar in creation form
[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 { Account } from '../account/account.model'
4 import { Actor } from '../account/actor.model'
5
6 export class VideoChannel extends Actor implements ServerVideoChannel {
7 displayName: string
8 description: string
9 support: string
10
11 isLocal: boolean
12
13 nameWithHost: string
14 nameWithHostForced: string
15
16 banner: ActorImage
17 bannerUrl: string
18
19 ownerAccount?: ServerAccount
20 ownerBy?: string
21 ownerAvatarUrl?: string
22
23 videosCount?: number
24
25 viewsPerDay?: ViewsPerDate[]
26
27 static GET_ACTOR_AVATAR_URL (actor: object) {
28 return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL()
29 }
30
31 static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) {
32 if (channel?.banner?.url) return channel.banner.url
33
34 if (channel && 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.viewsPerDay) {
64 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
65 }
66
67 if (hash.ownerAccount) {
68 this.ownerAccount = hash.ownerAccount
69 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
70 this.ownerAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.ownerAccount)
71 }
72
73 this.updateComputedAttributes()
74 }
75
76 updateAvatar (newAvatar: ActorImage) {
77 this.avatar = newAvatar
78
79 this.updateComputedAttributes()
80 }
81
82 resetAvatar () {
83 this.updateAvatar(null)
84 }
85
86 updateBanner (newBanner: ActorImage) {
87 this.banner = newBanner
88
89 this.updateComputedAttributes()
90 }
91
92 resetBanner () {
93 this.updateBanner(null)
94 }
95
96 updateComputedAttributes () {
97 this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this)
98 this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this)
99 }
100 }