1 import { Component, OnInit } from '@angular/core'
2 import { ServerService } from '@app/core'
3 import { ServerConfig } from '@shared/models'
4 import { PeertubeModalService } from '../shared-main/peertube-modal/peertube-modal.service'
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,
17 private modalService: PeertubeModalService
20 get initialUserVideoQuota () {
21 return this.serverConfig.user.videoQuota
24 get dailyUserVideoQuota () {
25 return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
28 get maxInstanceLives () {
29 const value = this.serverConfig.live.maxInstanceLives
30 if (value === -1) return $localize`Unlimited`
36 const value = this.serverConfig.live.maxUserLives
37 if (value === -1) return $localize`Unlimited`
43 this.serverConfig = this.serverService.getTmpConfig()
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)
70 if (hours > 1) pluralSuffix = 's'
71 if (hours > 0) return `~ ${hours} hour${pluralSuffix}`
73 const minutes = Math.floor(seconds % 3600 / 60)
75 if (minutes === 1) return $localize`~ 1 minute`
77 return $localize`~ ${minutes} minutes`
80 private buildQuotaHelpIndication () {
81 if (this.initialUserVideoQuota === -1) return
83 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
88 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
89 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
90 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
93 $localize`${this.getApproximateTime(fullHdSeconds)} of full HD videos`,
94 $localize`${this.getApproximateTime(hdSeconds)} of HD videos`,
95 $localize`${this.getApproximateTime(normalSeconds)} of average quality videos`
98 this.quotaHelpIndication = lines.join('<br />')