]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/instance/instance-features-table.component.ts
Add peertube version 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'
a00045a2 4import { ServerConfig } from '@shared/models'
41a676db
C
5
6@Component({
7 selector: 'my-instance-features-table',
8 templateUrl: './instance-features-table.component.html',
9 styleUrls: [ './instance-features-table.component.scss' ]
10})
11export class InstanceFeaturesTableComponent implements OnInit {
41a676db 12 quotaHelpIndication = ''
a00045a2 13 config: ServerConfig
41a676db
C
14
15 constructor (
16 private i18n: I18n,
17 private serverService: ServerService
18 ) {
19 }
20
21 get initialUserVideoQuota () {
22 return this.serverService.getConfig().user.videoQuota
23 }
24
61318dd6 25 get dailyUserVideoQuota () {
34dd7cb4 26 return Math.min(this.initialUserVideoQuota, this.serverService.getConfig().user.videoQuotaDaily)
61318dd6
RK
27 }
28
41a676db
C
29 ngOnInit () {
30 this.serverService.configLoaded
31 .subscribe(() => {
a00045a2 32 this.config = this.serverService.getConfig()
41a676db
C
33 this.buildQuotaHelpIndication()
34 })
35 }
36
c8000975
C
37 buildNSFWLabel () {
38 const policy = this.serverService.getConfig().instance.defaultNSFWPolicy
39
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')
43 }
44
41a676db
C
45 private getApproximateTime (seconds: number) {
46 const hours = Math.floor(seconds / 3600)
47 let pluralSuffix = ''
48 if (hours > 1) pluralSuffix = 's'
49 if (hours > 0) return `~ ${hours} hour${pluralSuffix}`
50
51 const minutes = Math.floor(seconds % 3600 / 60)
52
53 return this.i18n('~ {{minutes}} {minutes, plural, =1 {minute} other {minutes}}', { minutes })
54 }
55
dbdf2d51
C
56 getServerVersionAndCommit () {
57 return this.serverService.getServerVersionAndCommit()
58 }
59
41a676db
C
60 private buildQuotaHelpIndication () {
61 if (this.initialUserVideoQuota === -1) return
62
63 const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
64
65 // 1080p: ~ 6Mbps
66 // 720p: ~ 4Mbps
67 // 360p: ~ 1.5Mbps
68 const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
69 const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
70 const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
71
72 const lines = [
73 this.i18n('{{seconds}} of full HD videos', { seconds: this.getApproximateTime(fullHdSeconds) }),
74 this.i18n('{{seconds}} of HD videos', { seconds: this.getApproximateTime(hdSeconds) }),
75 this.i18n('{{seconds}} of average quality videos', { seconds: this.getApproximateTime(normalSeconds) })
76 ]
77
78 this.quotaHelpIndication = lines.join('<br />')
79 }
41a676db 80}