]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-instance/instance-features-table.component.ts
Migrate to $localize
[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 { ServerConfig } from '@shared/models'
4
5 @Component({
6 selector: 'my-instance-features-table',
7 templateUrl: './instance-features-table.component.html',
8 styleUrls: [ './instance-features-table.component.scss' ]
9 })
10 export class InstanceFeaturesTableComponent implements OnInit {
11 quotaHelpIndication = ''
12 serverConfig: ServerConfig
13
14 constructor (private serverService: ServerService) { }
15
16 get initialUserVideoQuota () {
17 return this.serverConfig.user.videoQuota
18 }
19
20 get dailyUserVideoQuota () {
21 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
22 }
23
24 ngOnInit () {
25 this.serverConfig = this.serverService.getTmpConfig()
26 this.serverService.getConfig()
27 .subscribe(config => {
28 this.serverConfig = config
29 this.buildQuotaHelpIndication()
30 })
31 }
32
33 buildNSFWLabel () {
34 const policy = this.serverConfig.instance.defaultNSFWPolicy
35
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`
39 }
40
41 getServerVersionAndCommit () {
42 return this.serverService.getServerVersionAndCommit()
43 }
44
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
53 if (minutes === 1) return $localize`~ 1 minute`
54
55 return $localize`~ ${minutes} minutes`
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 = [
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`
74 ]
75
76 this.quotaHelpIndication = lines.join('<br />')
77 }
78 }