]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-instance/instance-features-table.component.ts
Add max lives limit
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-instance / instance-features-table.component.ts
CommitLineData
41a676db
C
1import { Component, OnInit } from '@angular/core'
2import { ServerService } from '@app/core'
a00045a2 3import { ServerConfig } from '@shared/models'
41a676db
C
4
5@Component({
6 selector: 'my-instance-features-table',
7 templateUrl: './instance-features-table.component.html',
8 styleUrls: [ './instance-features-table.component.scss' ]
9})
10export class InstanceFeaturesTableComponent implements OnInit {
41a676db 11 quotaHelpIndication = ''
ba430d75 12 serverConfig: ServerConfig
41a676db 13
66357162 14 constructor (private serverService: ServerService) { }
41a676db
C
15
16 get initialUserVideoQuota () {
ba430d75 17 return this.serverConfig.user.videoQuota
41a676db
C
18 }
19
61318dd6 20 get dailyUserVideoQuota () {
ba430d75 21 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
61318dd6
RK
22 }
23
a056ca48
C
24 get maxInstanceLives () {
25 const value = this.serverConfig.live.maxInstanceLives
26 if (value === -1) return $localize`Unlimited`
27
28 return value
29 }
30
31 get maxUserLives () {
32 const value = this.serverConfig.live.maxUserLives
33 if (value === -1) return $localize`Unlimited`
34
35 return value
36 }
37
41a676db 38 ngOnInit () {
ba430d75
C
39 this.serverConfig = this.serverService.getTmpConfig()
40 this.serverService.getConfig()
41 .subscribe(config => {
42 this.serverConfig = config
41a676db
C
43 this.buildQuotaHelpIndication()
44 })
45 }
46
c8000975 47 buildNSFWLabel () {
ba430d75 48 const policy = this.serverConfig.instance.defaultNSFWPolicy
c8000975 49
66357162
C
50 if (policy === 'do_not_list') return $localize`Hidden`
51 if (policy === 'blur') return $localize`Blurred with confirmation request`
52 if (policy === 'display') return $localize`Displayed`
c8000975
C
53 }
54
ba430d75
C
55 getServerVersionAndCommit () {
56 return this.serverService.getServerVersionAndCommit()
57 }
58
41a676db
C
59 private getApproximateTime (seconds: number) {
60 const hours = Math.floor(seconds / 3600)
61 let pluralSuffix = ''
62 if (hours > 1) pluralSuffix = 's'
63 if (hours > 0) return `~ ${hours} hour${pluralSuffix}`
64
65 const minutes = Math.floor(seconds % 3600 / 60)
66
66357162
C
67 if (minutes === 1) return $localize`~ 1 minute`
68
69 return $localize`~ ${minutes} minutes`
41a676db
C
70 }
71
72 private buildQuotaHelpIndication () {
73 if (this.initialUserVideoQuota === -1) return
74
75 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
76
77 // 1080p: ~ 6Mbps
78 // 720p: ~ 4Mbps
79 // 360p: ~ 1.5Mbps
80 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
81 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
82 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
83
84 const lines = [
66357162
C
85 $localize`${this.getApproximateTime(fullHdSeconds)} of full HD videos`,
86 $localize`${this.getApproximateTime(hdSeconds)} of HD videos`,
87 $localize`${this.getApproximateTime(normalSeconds)} of average quality videos`
41a676db
C
88 ]
89
90 this.quotaHelpIndication = lines.join('<br />')
91 }
41a676db 92}