1 import { Component, OnInit } from '@angular/core'
2 import { ServerService } from '@app/core'
3 import { prepareIcu } from '@app/helpers'
4 import { ServerConfig } from '@shared/models'
7 selector: 'my-instance-features-table',
8 templateUrl: './instance-features-table.component.html',
9 styleUrls: [ './instance-features-table.component.scss' ]
11 export class InstanceFeaturesTableComponent implements OnInit {
12 quotaHelpIndication = ''
13 serverConfig: ServerConfig
16 private serverService: ServerService
19 get initialUserVideoQuota () {
20 return this.serverConfig.user.videoQuota
23 get dailyUserVideoQuota () {
24 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
27 get maxInstanceLives () {
28 const value = this.serverConfig.live.maxInstanceLives
29 if (value === -1) return $localize`Unlimited`
35 const value = this.serverConfig.live.maxUserLives
36 if (value === -1) return $localize`Unlimited`
42 this.serverService.getConfig()
43 .subscribe(config => {
44 this.serverConfig = config
45 this.buildQuotaHelpIndication()
50 const policy = this.serverConfig.instance.defaultNSFWPolicy
52 if (policy === 'do_not_list') return $localize`Hidden`
53 if (policy === 'blur') return $localize`Blurred with confirmation request`
54 if (policy === 'display') return $localize`Displayed`
57 buildRegistrationLabel () {
58 const config = this.serverConfig.signup
60 if (config.allowed !== true) return $localize`Disabled`
61 if (config.requiresApproval === true) return $localize`Requires approval by moderators`
63 return $localize`Enabled`
66 getServerVersionAndCommit () {
67 return this.serverService.getServerVersionAndCommit()
70 private getApproximateTime (seconds: number) {
71 const hours = Math.floor(seconds / 3600)
74 return prepareIcu($localize`~ {hours, plural, =1 {1 hour} other {{hours} hours}}`)(
76 $localize`~ ${hours} hours`
80 const minutes = Math.floor(seconds % 3600 / 60)
82 return prepareIcu($localize`~ {minutes, plural, =1 {1 minute} other {{minutes} minutes}}`)(
84 $localize`~ ${minutes} minutes`
88 private buildQuotaHelpIndication () {
89 if (this.initialUserVideoQuota === -1) return
91 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
96 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
97 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
98 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
101 $localize`${this.getApproximateTime(fullHdSeconds)} of full HD videos`,
102 $localize`${this.getApproximateTime(hdSeconds)} of HD videos`,
103 $localize`${this.getApproximateTime(normalSeconds)} of average quality videos`
106 this.quotaHelpIndication = lines.join('<br />')