]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/instance/instance-features-table.component.ts
Move user registration info in features table
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / instance / instance-features-table.component.ts
CommitLineData
41a676db
C
1import { Component, OnInit } from '@angular/core'
2import { ServerService } from '@app/core'
3import { 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})
10export 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
61318dd6
RK
24 get dailyUserVideoQuota () {
25 return this.serverService.getConfig().user.videoQuotaDaily
26 }
27
41a676db
C
28 ngOnInit () {
29 this.serverService.configLoaded
30 .subscribe(() => {
31 this.buildFeatures()
32 this.buildQuotaHelpIndication()
33 })
34 }
35
36 private buildFeatures () {
37 const config = this.serverService.getConfig()
38
39 this.features = [
c0e04e46
C
40 {
41 label: this.i18n('User registration allowed'),
42 value: config.signup.allowed
43 },
41a676db
C
44 {
45 label: this.i18n('Transcode your videos in multiple resolutions'),
46 value: config.transcoding.enabledResolutions.length !== 0
47 },
48 {
49 label: this.i18n('HTTP import (YouTube, Vimeo, direct URL...)'),
50 value: config.import.videos.http.enabled
51 },
52 {
53 label: this.i18n('Torrent import'),
54 value: config.import.videos.torrent.enabled
55 }
56 ]
41a676db
C
57 }
58
59 private getApproximateTime (seconds: number) {
60 const hours = Math.floor(seconds / 3600)
61 let pluralSuffix = ''
62 if (hours > 1) pluralSuffix = 's'
63 if (hours > 0) return `~ ${hours} hour${pluralSuffix}`
64
65 const minutes = Math.floor(seconds % 3600 / 60)
66
67 return this.i18n('~ {{minutes}} {minutes, plural, =1 {minute} other {minutes}}', { minutes })
68 }
69
70 private buildQuotaHelpIndication () {
71 if (this.initialUserVideoQuota === -1) return
72
73 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
74
75 // 1080p: ~ 6Mbps
76 // 720p: ~ 4Mbps
77 // 360p: ~ 1.5Mbps
78 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
79 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
80 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
81
82 const lines = [
83 this.i18n('{{seconds}} of full HD videos', { seconds: this.getApproximateTime(fullHdSeconds) }),
84 this.i18n('{{seconds}} of HD videos', { seconds: this.getApproximateTime(hdSeconds) }),
85 this.i18n('{{seconds}} of average quality videos', { seconds: this.getApproximateTime(normalSeconds) })
86 ]
87
88 this.quotaHelpIndication = lines.join('<br />')
89 }
90
91}