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