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'
5 import { PeertubeModalService } from '../shared-main/peertube-modal/peertube-modal.service'
8 selector: 'my-instance-features-table',
9 templateUrl: './instance-features-table.component.html',
10 styleUrls: [ './instance-features-table.component.scss' ]
12 export class InstanceFeaturesTableComponent implements OnInit {
13 quotaHelpIndication = ''
14 serverConfig: ServerConfig
17 private serverService: ServerService,
18 private modalService: PeertubeModalService
21 get initialUserVideoQuota () {
22 return this.serverConfig.user.videoQuota
25 get dailyUserVideoQuota () {
26 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
29 get maxInstanceLives () {
30 const value = this.serverConfig.live.maxInstanceLives
31 if (value === -1) return $localize`Unlimited`
37 const value = this.serverConfig.live.maxUserLives
38 if (value === -1) return $localize`Unlimited`
44 this.serverService.getConfig()
45 .subscribe(config => {
46 this.serverConfig = config
47 this.buildQuotaHelpIndication()
52 const policy = this.serverConfig.instance.defaultNSFWPolicy
54 if (policy === 'do_not_list') return $localize`Hidden`
55 if (policy === 'blur') return $localize`Blurred with confirmation request`
56 if (policy === 'display') return $localize`Displayed`
59 getServerVersionAndCommit () {
60 return this.serverService.getServerVersionAndCommit()
63 openQuickSettingsHighlight () {
64 this.modalService.openQuickSettingsSubject.next()
67 private getApproximateTime (seconds: number) {
68 const hours = Math.floor(seconds / 3600)
71 return prepareIcu($localize`~ {hours, plural, =1 {1 hour} other {{hours} hours}}`)(
73 $localize`~ ${hours} hours`
77 const minutes = Math.floor(seconds % 3600 / 60)
79 return prepareIcu($localize`~ {minutes, plural, =1 {1 minute} other {{minutes} minutes}}`)(
81 $localize`~ ${minutes} minutes`
85 private buildQuotaHelpIndication () {
86 if (this.initialUserVideoQuota === -1) return
88 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
93 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
94 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
95 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
98 $localize`${this.getApproximateTime(fullHdSeconds)} of full HD videos`,
99 $localize`${this.getApproximateTime(hdSeconds)} of HD videos`,
100 $localize`${this.getApproximateTime(normalSeconds)} of average quality videos`
103 this.quotaHelpIndication = lines.join('<br />')