]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-instance/instance-features-table.component.ts
Bumped to version v5.2.1
[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 { prepareIcu } from '@app/helpers'
4 import { ServerConfig } from '@shared/models'
5
6 @Component({
7 selector: 'my-instance-features-table',
8 templateUrl: './instance-features-table.component.html',
9 styleUrls: [ './instance-features-table.component.scss' ]
10 })
11 export class InstanceFeaturesTableComponent implements OnInit {
12 quotaHelpIndication = ''
13 serverConfig: ServerConfig
14
15 constructor (
16 private serverService: ServerService
17 ) { }
18
19 get initialUserVideoQuota () {
20 return this.serverConfig.user.videoQuota
21 }
22
23 get dailyUserVideoQuota () {
24 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
25 }
26
27 get maxInstanceLives () {
28 const value = this.serverConfig.live.maxInstanceLives
29 if (value === -1) return $localize`Unlimited`
30
31 return value
32 }
33
34 get maxUserLives () {
35 const value = this.serverConfig.live.maxUserLives
36 if (value === -1) return $localize`Unlimited`
37
38 return value
39 }
40
41 ngOnInit () {
42 this.serverService.getConfig()
43 .subscribe(config => {
44 this.serverConfig = config
45 this.buildQuotaHelpIndication()
46 })
47 }
48
49 buildNSFWLabel () {
50 const policy = this.serverConfig.instance.defaultNSFWPolicy
51
52 if (policy === 'do_not_list') return $localize`Hidden`
53 if (policy === 'blur') return $localize`Blurred with confirmation request`
54 if (policy === 'display') return $localize`Displayed`
55 }
56
57 buildRegistrationLabel () {
58 const config = this.serverConfig.signup
59
60 if (config.allowed !== true) return $localize`Disabled`
61 if (config.requiresApproval === true) return $localize`Requires approval by moderators`
62
63 return $localize`Enabled`
64 }
65
66 getServerVersionAndCommit () {
67 return this.serverService.getServerVersionAndCommit()
68 }
69
70 private getApproximateTime (seconds: number) {
71 const hours = Math.floor(seconds / 3600)
72
73 if (hours !== 0) {
74 return prepareIcu($localize`~ {hours, plural, =1 {1 hour} other {{hours} hours}}`)(
75 { hours },
76 $localize`~ ${hours} hours`
77 )
78 }
79
80 const minutes = Math.floor(seconds % 3600 / 60)
81
82 return prepareIcu($localize`~ {minutes, plural, =1 {1 minute} other {{minutes} minutes}}`)(
83 { minutes },
84 $localize`~ ${minutes} minutes`
85 )
86 }
87
88 private buildQuotaHelpIndication () {
89 if (this.initialUserVideoQuota === -1) return
90
91 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
92
93 // 1080p: ~ 6Mbps
94 // 720p: ~ 4Mbps
95 // 360p: ~ 1.5Mbps
96 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
97 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
98 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
99
100 const lines = [
101 $localize`${this.getApproximateTime(fullHdSeconds)} of full HD videos`,
102 $localize`${this.getApproximateTime(hdSeconds)} of HD videos`,
103 $localize`${this.getApproximateTime(normalSeconds)} of average quality videos`
104 ]
105
106 this.quotaHelpIndication = lines.join('<br />')
107 }
108 }