]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnInit } from '@angular/core' | |
2 | import { ServerService } from '@app/core' | |
3 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
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 | features: { label: string, value?: boolean }[] = [] | |
12 | quotaHelpIndication = '' | |
13 | ||
14 | constructor ( | |
15 | private i18n: I18n, | |
16 | private serverService: ServerService | |
17 | ) { | |
18 | } | |
19 | ||
20 | get initialUserVideoQuota () { | |
21 | return this.serverService.getConfig().user.videoQuota | |
22 | } | |
23 | ||
24 | get dailyUserVideoQuota () { | |
25 | return this.serverService.getConfig().user.videoQuotaDaily | |
26 | } | |
27 | ||
28 | ngOnInit () { | |
29 | this.serverService.configLoaded | |
30 | .subscribe(() => { | |
31 | this.buildFeatures() | |
32 | this.buildQuotaHelpIndication() | |
33 | }) | |
34 | } | |
35 | ||
36 | buildNSFWLabel () { | |
37 | const policy = this.serverService.getConfig().instance.defaultNSFWPolicy | |
38 | ||
39 | if (policy === 'do_not_list') return this.i18n('Hidden') | |
40 | if (policy === 'blur') return this.i18n('Blurred with confirmation request') | |
41 | if (policy === 'display') return this.i18n('Displayed') | |
42 | } | |
43 | ||
44 | private buildFeatures () { | |
45 | const config = this.serverService.getConfig() | |
46 | ||
47 | this.features = [ | |
48 | { | |
49 | label: this.i18n('User registration allowed'), | |
50 | value: config.signup.allowed | |
51 | }, | |
52 | { | |
53 | label: this.i18n('Video uploads require manual validation by moderators'), | |
54 | value: config.autoBlacklist.videos.ofUsers.enabled | |
55 | }, | |
56 | { | |
57 | label: this.i18n('Transcode your videos in multiple resolutions'), | |
58 | value: config.transcoding.enabledResolutions.length !== 0 | |
59 | }, | |
60 | { | |
61 | label: this.i18n('HTTP import (YouTube, Vimeo, direct URL...)'), | |
62 | value: config.import.videos.http.enabled | |
63 | }, | |
64 | { | |
65 | label: this.i18n('Torrent import'), | |
66 | value: config.import.videos.torrent.enabled | |
67 | }, | |
68 | { | |
69 | label: this.i18n('P2P enabled'), | |
70 | value: config.tracker.enabled | |
71 | } | |
72 | ] | |
73 | } | |
74 | ||
75 | private getApproximateTime (seconds: number) { | |
76 | const hours = Math.floor(seconds / 3600) | |
77 | let pluralSuffix = '' | |
78 | if (hours > 1) pluralSuffix = 's' | |
79 | if (hours > 0) return `~ ${hours} hour${pluralSuffix}` | |
80 | ||
81 | const minutes = Math.floor(seconds % 3600 / 60) | |
82 | ||
83 | return this.i18n('~ {{minutes}} {minutes, plural, =1 {minute} other {minutes}}', { minutes }) | |
84 | } | |
85 | ||
86 | private buildQuotaHelpIndication () { | |
87 | if (this.initialUserVideoQuota === -1) return | |
88 | ||
89 | const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8 | |
90 | ||
91 | // 1080p: ~ 6Mbps | |
92 | // 720p: ~ 4Mbps | |
93 | // 360p: ~ 1.5Mbps | |
94 | const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000) | |
95 | const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000) | |
96 | const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000) | |
97 | ||
98 | const lines = [ | |
99 | this.i18n('{{seconds}} of full HD videos', { seconds: this.getApproximateTime(fullHdSeconds) }), | |
100 | this.i18n('{{seconds}} of HD videos', { seconds: this.getApproximateTime(hdSeconds) }), | |
101 | this.i18n('{{seconds}} of average quality videos', { seconds: this.getApproximateTime(normalSeconds) }) | |
102 | ] | |
103 | ||
104 | this.quotaHelpIndication = lines.join('<br />') | |
105 | } | |
106 | } |