]>
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.serverService.getConfig() |
44 | .subscribe(config => { | |
45 | this.serverConfig = config | |
41a676db C |
46 | this.buildQuotaHelpIndication() |
47 | }) | |
48 | } | |
49 | ||
c8000975 | 50 | buildNSFWLabel () { |
ba430d75 | 51 | const policy = this.serverConfig.instance.defaultNSFWPolicy |
c8000975 | 52 | |
66357162 C |
53 | if (policy === 'do_not_list') return $localize`Hidden` |
54 | if (policy === 'blur') return $localize`Blurred with confirmation request` | |
55 | if (policy === 'display') return $localize`Displayed` | |
c8000975 C |
56 | } |
57 | ||
ba430d75 C |
58 | getServerVersionAndCommit () { |
59 | return this.serverService.getServerVersionAndCommit() | |
60 | } | |
61 | ||
43a3d281 | 62 | openQuickSettingsHighlight () { |
63 | this.modalService.openQuickSettingsSubject.next() | |
64 | } | |
65 | ||
41a676db C |
66 | private getApproximateTime (seconds: number) { |
67 | const hours = Math.floor(seconds / 3600) | |
68 | let pluralSuffix = '' | |
69 | if (hours > 1) pluralSuffix = 's' | |
70 | if (hours > 0) return `~ ${hours} hour${pluralSuffix}` | |
71 | ||
72 | const minutes = Math.floor(seconds % 3600 / 60) | |
73 | ||
66357162 C |
74 | if (minutes === 1) return $localize`~ 1 minute` |
75 | ||
76 | return $localize`~ ${minutes} minutes` | |
41a676db C |
77 | } |
78 | ||
79 | private buildQuotaHelpIndication () { | |
80 | if (this.initialUserVideoQuota === -1) return | |
81 | ||
82 | const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8 | |
83 | ||
84 | // 1080p: ~ 6Mbps | |
85 | // 720p: ~ 4Mbps | |
86 | // 360p: ~ 1.5Mbps | |
87 | const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000) | |
88 | const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000) | |
89 | const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000) | |
90 | ||
91 | const lines = [ | |
66357162 C |
92 | $localize`${this.getApproximateTime(fullHdSeconds)} of full HD videos`, |
93 | $localize`${this.getApproximateTime(hdSeconds)} of HD videos`, | |
94 | $localize`${this.getApproximateTime(normalSeconds)} of average quality videos` | |
41a676db C |
95 | ] |
96 | ||
97 | this.quotaHelpIndication = lines.join('<br />') | |
98 | } | |
41a676db | 99 | } |