]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-instance/instance-features-table.component.ts
Minimal PeertubeModalService to open settings from "can be redefined..." (#3923)
[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 import { PeertubeModalService } from '../shared-main/peertube-modal/peertube-modal.service'
5
6 @Component({
7 selector: 'my-instance-features-table',
8 templateUrl: './instance-features-table.component.html',
9 styleUrls: [ './instance-features-table.component.scss' ]
10 })
11 export class InstanceFeaturesTableComponent implements OnInit {
12 quotaHelpIndication = ''
13 serverConfig: ServerConfig
14
15 constructor (
16 private serverService: ServerService,
17 private modalService: PeertubeModalService
18 ) { }
19
20 get initialUserVideoQuota () {
21 return this.serverConfig.user.videoQuota
22 }
23
24 get dailyUserVideoQuota () {
25 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
26 }
27
28 get maxInstanceLives () {
29 const value = this.serverConfig.live.maxInstanceLives
30 if (value === -1) return $localize`Unlimited`
31
32 return value
33 }
34
35 get maxUserLives () {
36 const value = this.serverConfig.live.maxUserLives
37 if (value === -1) return $localize`Unlimited`
38
39 return value
40 }
41
42 ngOnInit () {
43 this.serverConfig = this.serverService.getTmpConfig()
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 getServerVersionAndCommit () {
60 return this.serverService.getServerVersionAndCommit()
61 }
62
63 openQuickSettingsHighlight () {
64 this.modalService.openQuickSettingsSubject.next()
65 }
66
67 private getApproximateTime (seconds: number) {
68 const hours = Math.floor(seconds / 3600)
69 let pluralSuffix = ''
70 if (hours > 1) pluralSuffix = 's'
71 if (hours > 0) return `~ ${hours} hour${pluralSuffix}`
72
73 const minutes = Math.floor(seconds % 3600 / 60)
74
75 if (minutes === 1) return $localize`~ 1 minute`
76
77 return $localize`~ ${minutes} minutes`
78 }
79
80 private buildQuotaHelpIndication () {
81 if (this.initialUserVideoQuota === -1) return
82
83 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
84
85 // 1080p: ~ 6Mbps
86 // 720p: ~ 4Mbps
87 // 360p: ~ 1.5Mbps
88 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
89 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
90 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
91
92 const lines = [
93 $localize`${this.getApproximateTime(fullHdSeconds)} of full HD videos`,
94 $localize`${this.getApproximateTime(hdSeconds)} of HD videos`,
95 $localize`${this.getApproximateTime(normalSeconds)} of average quality videos`
96 ]
97
98 this.quotaHelpIndication = lines.join('<br />')
99 }
100 }