]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
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'
43a3d281 5import { PeertubeModalService } from '../shared-main/peertube-modal/peertube-modal.service'
41a676db
C
6
7@Component({
8 selector: 'my-instance-features-table',
9 templateUrl: './instance-features-table.component.html',
10 styleUrls: [ './instance-features-table.component.scss' ]
11})
12export class InstanceFeaturesTableComponent implements OnInit {
41a676db 13 quotaHelpIndication = ''
ba430d75 14 serverConfig: ServerConfig
41a676db 15
43a3d281 16 constructor (
17 private serverService: ServerService,
18 private modalService: PeertubeModalService
19 ) { }
41a676db
C
20
21 get initialUserVideoQuota () {
ba430d75 22 return this.serverConfig.user.videoQuota
41a676db
C
23 }
24
61318dd6 25 get dailyUserVideoQuota () {
ba430d75 26 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
61318dd6
RK
27 }
28
a056ca48
C
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
41a676db 43 ngOnInit () {
ba430d75
C
44 this.serverService.getConfig()
45 .subscribe(config => {
46 this.serverConfig = config
41a676db
C
47 this.buildQuotaHelpIndication()
48 })
49 }
50
c8000975 51 buildNSFWLabel () {
ba430d75 52 const policy = this.serverConfig.instance.defaultNSFWPolicy
c8000975 53
66357162
C
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`
c8000975
C
57 }
58
ff71e06a
C
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
ba430d75
C
68 getServerVersionAndCommit () {
69 return this.serverService.getServerVersionAndCommit()
70 }
71
43a3d281 72 openQuickSettingsHighlight () {
73 this.modalService.openQuickSettingsSubject.next()
74 }
75
41a676db
C
76 private getApproximateTime (seconds: number) {
77 const hours = Math.floor(seconds / 3600)
41a676db 78
eaa52952
C
79 if (hours !== 0) {
80 return prepareIcu($localize`~ {hours, plural, =1 {1 hour} other {{hours} hours}}`)(
81 { hours },
82 $localize`~ ${hours} hours`
83 )
84 }
41a676db 85
eaa52952 86 const minutes = Math.floor(seconds % 3600 / 60)
66357162 87
eaa52952
C
88 return prepareIcu($localize`~ {minutes, plural, =1 {1 minute} other {{minutes} minutes}}`)(
89 { minutes },
90 $localize`~ ${minutes} minutes`
91 )
41a676db
C
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 = [
66357162
C
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`
41a676db
C
110 ]
111
112 this.quotaHelpIndication = lines.join('<br />')
113 }
41a676db 114}