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/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 = ''
17 private serverService: ServerService
21 get initialUserVideoQuota () {
22 return this.serverService.getConfig().user.videoQuota
25 get dailyUserVideoQuota () {
26 return Math.min(this.initialUserVideoQuota, this.serverService.getConfig().user.videoQuotaDaily)
30 this.serverService.configLoaded
32 this.config = this.serverService.getConfig()
33 this.buildQuotaHelpIndication()
38 const policy = this.serverService.getConfig().instance.defaultNSFWPolicy
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')
45 private getApproximateTime (seconds: number) {
46 const hours = Math.floor(seconds / 3600)
48 if (hours > 1) pluralSuffix = 's'
49 if (hours > 0) return `~ ${hours} hour${pluralSuffix}`
51 const minutes = Math.floor(seconds % 3600 / 60)
53 return this.i18n('~ {{minutes}} {minutes, plural, =1 {minute} other {minutes}}', { minutes })
56 private buildQuotaHelpIndication () {
57 if (this.initialUserVideoQuota === -1) return
59 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
64 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
65 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
66 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
69 this.i18n('{{seconds}} of full HD videos', { seconds: this.getApproximateTime(fullHdSeconds) }),
70 this.i18n('{{seconds}} of HD videos', { seconds: this.getApproximateTime(hdSeconds) }),
71 this.i18n('{{seconds}} of average quality videos', { seconds: this.getApproximateTime(normalSeconds) })
74 this.quotaHelpIndication = lines.join('<br />')