]>
Commit | Line | Data |
---|---|---|
41a676db C |
1 | import { Component, OnInit } from '@angular/core' |
2 | import { ServerService } from '@app/core' | |
a00045a2 | 3 | import { ServerConfig } from '@shared/models' |
43a3d281 | 4 | import { PeertubeModalService } from '../shared-main/peertube-modal/peertube-modal.service' |
41a676db C |
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 { | |
41a676db | 12 | quotaHelpIndication = '' |
ba430d75 | 13 | serverConfig: ServerConfig |
41a676db | 14 | |
43a3d281 | 15 | constructor ( |
16 | private serverService: ServerService, | |
17 | private modalService: PeertubeModalService | |
18 | ) { } | |
41a676db C |
19 | |
20 | get initialUserVideoQuota () { | |
ba430d75 | 21 | return this.serverConfig.user.videoQuota |
41a676db C |
22 | } |
23 | ||
61318dd6 | 24 | get dailyUserVideoQuota () { |
ba430d75 | 25 | return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily) |
61318dd6 RK |
26 | } |
27 | ||
a056ca48 C |
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 | ||
41a676db | 42 | ngOnInit () { |
ba430d75 C |
43 | this.serverConfig = this.serverService.getTmpConfig() |
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) | |
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 | ||
66357162 C |
75 | if (minutes === 1) return $localize`~ 1 minute` |
76 | ||
77 | return $localize`~ ${minutes} minutes` | |
41a676db C |
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 = [ | |
66357162 C |
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` | |
41a676db C |
96 | ] |
97 | ||
98 | this.quotaHelpIndication = lines.join('<br />') | |
99 | } | |
41a676db | 100 | } |