]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/users/user-edit/user-edit.ts
021b1feb4ed11aff3b492f4887bee1b8116bbde0
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-edit.ts
1 import { ServerService } from '../../../core'
2 import { FormReactive } from '../../../shared'
3 import { USER_ROLE_LABELS, VideoResolution } from '../../../../../../shared'
4 import { ConfigService } from '@app/+admin/config/shared/config.service'
5
6 export abstract class UserEdit extends FormReactive {
7 videoQuotaOptions: { value: string, label: string }[] = []
8 videoQuotaDailyOptions: { value: string, label: string }[] = []
9 roles = Object.keys(USER_ROLE_LABELS).map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
10 username: string
11
12 protected abstract serverService: ServerService
13 protected abstract configService: ConfigService
14 abstract isCreation (): boolean
15 abstract getFormButtonTitle (): string
16
17 isTranscodingInformationDisplayed () {
18 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
19
20 return this.serverService.getConfig().transcoding.enabledResolutions.length !== 0 &&
21 formVideoQuota > 0
22 }
23
24 computeQuotaWithTranscoding () {
25 const transcodingConfig = this.serverService.getConfig().transcoding
26
27 const resolutions = transcodingConfig.enabledResolutions
28 const higherResolution = VideoResolution.H_1080P
29 let multiplier = 0
30
31 for (const resolution of resolutions) {
32 multiplier += resolution / higherResolution
33 }
34
35 if (transcodingConfig.hls.enabled) multiplier *= 2
36
37 return multiplier * parseInt(this.form.value['videoQuota'], 10)
38 }
39
40 protected buildQuotaOptions () {
41 // These are used by a HTML select, so convert key into strings
42 this.videoQuotaOptions = this.configService
43 .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
44
45 this.videoQuotaDailyOptions = this.configService
46 .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))
47 }
48 }