]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
41a676db
C
1import { Component, OnInit } from '@angular/core'
2import { ServerService } from '@app/core'
eaa52952 3import { prepareIcu } from '@app/helpers'
a00045a2 4import { ServerConfig } from '@shared/models'
41a676db
C
5
6@Component({
7 selector: 'my-instance-features-table',
8 templateUrl: './instance-features-table.component.html',
9 styleUrls: [ './instance-features-table.component.scss' ]
10})
11export class InstanceFeaturesTableComponent implements OnInit {
41a676db 12 quotaHelpIndication = ''
ba430d75 13 serverConfig: ServerConfig
41a676db 14
43a3d281 15 constructor (
d0fbc9fd 16 private serverService: ServerService
43a3d281 17 ) { }
41a676db
C
18
19 get initialUserVideoQuota () {
ba430d75 20 return this.serverConfig.user.videoQuota
41a676db
C
21 }
22
61318dd6 23 get dailyUserVideoQuota () {
ba430d75 24 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
61318dd6
RK
25 }
26
a056ca48
C
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
41a676db 41 ngOnInit () {
ba430d75
C
42 this.serverService.getConfig()
43 .subscribe(config => {
44 this.serverConfig = config
41a676db
C
45 this.buildQuotaHelpIndication()
46 })
47 }
48
c8000975 49 buildNSFWLabel () {
ba430d75 50 const policy = this.serverConfig.instance.defaultNSFWPolicy
c8000975 51
66357162
C
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`
c8000975
C
55 }
56
ff71e06a
C
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
ba430d75
C
66 getServerVersionAndCommit () {
67 return this.serverService.getServerVersionAndCommit()
68 }
69
41a676db
C
70 private getApproximateTime (seconds: number) {
71 const hours = Math.floor(seconds / 3600)
41a676db 72
eaa52952
C
73 if (hours !== 0) {
74 return prepareIcu($localize`~ {hours, plural, =1 {1 hour} other {{hours} hours}}`)(
75 { hours },
76 $localize`~ ${hours} hours`
77 )
78 }
41a676db 79
eaa52952 80 const minutes = Math.floor(seconds % 3600 / 60)
66357162 81
eaa52952
C
82 return prepareIcu($localize`~ {minutes, plural, =1 {1 minute} other {{minutes} minutes}}`)(
83 { minutes },
84 $localize`~ ${minutes} minutes`
85 )
41a676db
C
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 = [
66357162
C
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`
41a676db
C
104 ]
105
106 this.quotaHelpIndication = lines.join('<br />')
107 }
41a676db 108}