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