]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - 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
1 import { Component, OnInit } from '@angular/core'
2 import { ServerService } from '@app/core'
3 import { ServerConfig } from '@shared/models'
4
5 @Component({
6 selector: 'my-instance-features-table',
7 templateUrl: './instance-features-table.component.html',
8 styleUrls: [ './instance-features-table.component.scss' ]
9 })
10 export class InstanceFeaturesTableComponent implements OnInit {
11 quotaHelpIndication = ''
12 serverConfig: ServerConfig
13
14 constructor (private serverService: ServerService) { }
15
16 get initialUserVideoQuota () {
17 return this.serverConfig.user.videoQuota
18 }
19
20 get dailyUserVideoQuota () {
21 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
22 }
23
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
38 ngOnInit () {
39 this.serverConfig = this.serverService.getTmpConfig()
40 this.serverService.getConfig()
41 .subscribe(config => {
42 this.serverConfig = config
43 this.buildQuotaHelpIndication()
44 })
45 }
46
47 buildNSFWLabel () {
48 const policy = this.serverConfig.instance.defaultNSFWPolicy
49
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`
53 }
54
55 getServerVersionAndCommit () {
56 return this.serverService.getServerVersionAndCommit()
57 }
58
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
67 if (minutes === 1) return $localize`~ 1 minute`
68
69 return $localize`~ ${minutes} minutes`
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 = [
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`
88 ]
89
90 this.quotaHelpIndication = lines.join('<br />')
91 }
92 }