]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-instance/instance-features-table.component.ts
Add modal to display live information
[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'
a00045a2 3import { ServerConfig } from '@shared/models'
41a676db
C
4
5@Component({
6 selector: 'my-instance-features-table',
7 templateUrl: './instance-features-table.component.html',
8 styleUrls: [ './instance-features-table.component.scss' ]
9})
10export class InstanceFeaturesTableComponent implements OnInit {
41a676db 11 quotaHelpIndication = ''
ba430d75 12 serverConfig: ServerConfig
41a676db 13
66357162 14 constructor (private serverService: ServerService) { }
41a676db
C
15
16 get initialUserVideoQuota () {
ba430d75 17 return this.serverConfig.user.videoQuota
41a676db
C
18 }
19
61318dd6 20 get dailyUserVideoQuota () {
ba430d75 21 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
61318dd6
RK
22 }
23
41a676db 24 ngOnInit () {
ba430d75
C
25 this.serverConfig = this.serverService.getTmpConfig()
26 this.serverService.getConfig()
27 .subscribe(config => {
28 this.serverConfig = config
41a676db
C
29 this.buildQuotaHelpIndication()
30 })
31 }
32
c8000975 33 buildNSFWLabel () {
ba430d75 34 const policy = this.serverConfig.instance.defaultNSFWPolicy
c8000975 35
66357162
C
36 if (policy === 'do_not_list') return $localize`Hidden`
37 if (policy === 'blur') return $localize`Blurred with confirmation request`
38 if (policy === 'display') return $localize`Displayed`
c8000975
C
39 }
40
ba430d75
C
41 getServerVersionAndCommit () {
42 return this.serverService.getServerVersionAndCommit()
43 }
44
41a676db
C
45 private getApproximateTime (seconds: number) {
46 const hours = Math.floor(seconds / 3600)
47 let pluralSuffix = ''
48 if (hours > 1) pluralSuffix = 's'
49 if (hours > 0) return `~ ${hours} hour${pluralSuffix}`
50
51 const minutes = Math.floor(seconds % 3600 / 60)
52
66357162
C
53 if (minutes === 1) return $localize`~ 1 minute`
54
55 return $localize`~ ${minutes} minutes`
41a676db
C
56 }
57
58 private buildQuotaHelpIndication () {
59 if (this.initialUserVideoQuota === -1) return
60
61 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
62
63 // 1080p: ~ 6Mbps
64 // 720p: ~ 4Mbps
65 // 360p: ~ 1.5Mbps
66 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
67 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
68 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
69
70 const lines = [
66357162
C
71 $localize`${this.getApproximateTime(fullHdSeconds)} of full HD videos`,
72 $localize`${this.getApproximateTime(hdSeconds)} of HD videos`,
73 $localize`${this.getApproximateTime(normalSeconds)} of average quality videos`
41a676db
C
74 ]
75
76 this.quotaHelpIndication = lines.join('<br />')
77 }
41a676db 78}