]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-instance/instance-features-table.component.ts
Merge branch 'release/4.2.0' 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
ba430d75
C
59 getServerVersionAndCommit () {
60 return this.serverService.getServerVersionAndCommit()
61 }
62
43a3d281 63 openQuickSettingsHighlight () {
64 this.modalService.openQuickSettingsSubject.next()
65 }
66
41a676db
C
67 private getApproximateTime (seconds: number) {
68 const hours = Math.floor(seconds / 3600)
41a676db 69
eaa52952
C
70 if (hours !== 0) {
71 return prepareIcu($localize`~ {hours, plural, =1 {1 hour} other {{hours} hours}}`)(
72 { hours },
73 $localize`~ ${hours} hours`
74 )
75 }
41a676db 76
eaa52952 77 const minutes = Math.floor(seconds % 3600 / 60)
66357162 78
eaa52952
C
79 return prepareIcu($localize`~ {minutes, plural, =1 {1 minute} other {{minutes} minutes}}`)(
80 { minutes },
81 $localize`~ ${minutes} minutes`
82 )
41a676db
C
83 }
84
85 private buildQuotaHelpIndication () {
86 if (this.initialUserVideoQuota === -1) return
87
88 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
89
90 // 1080p: ~ 6Mbps
91 // 720p: ~ 4Mbps
92 // 360p: ~ 1.5Mbps
93 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
94 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
95 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
96
97 const lines = [
66357162
C
98 $localize`${this.getApproximateTime(fullHdSeconds)} of full HD videos`,
99 $localize`${this.getApproximateTime(hdSeconds)} of HD videos`,
100 $localize`${this.getApproximateTime(normalSeconds)} of average quality videos`
41a676db
C
101 ]
102
103 this.quotaHelpIndication = lines.join('<br />')
104 }
41a676db 105}