]>
Commit | Line | Data |
---|---|---|
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.serverService.getConfig() | |
44 | .subscribe(config => { | |
45 | this.serverConfig = config | |
46 | this.buildQuotaHelpIndication() | |
47 | }) | |
48 | } | |
49 | ||
50 | buildNSFWLabel () { | |
51 | const policy = this.serverConfig.instance.defaultNSFWPolicy | |
52 | ||
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` | |
56 | } | |
57 | ||
58 | getServerVersionAndCommit () { | |
59 | return this.serverService.getServerVersionAndCommit() | |
60 | } | |
61 | ||
62 | openQuickSettingsHighlight () { | |
63 | this.modalService.openQuickSettingsSubject.next() | |
64 | } | |
65 | ||
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 | ||
74 | if (minutes === 1) return $localize`~ 1 minute` | |
75 | ||
76 | return $localize`~ ${minutes} minutes` | |
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 = [ | |
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` | |
95 | ] | |
96 | ||
97 | this.quotaHelpIndication = lines.join('<br />') | |
98 | } | |
99 | } |