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 import { UserAdminFlag } from '@shared/models/users/user-flag.model'
7 export abstract class UserEdit extends FormReactive {
8 videoQuotaOptions: { value: string, label: string }[] = []
9 videoQuotaDailyOptions: { value: string, label: string }[] = []
10 roles = Object.keys(USER_ROLE_LABELS)
11 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
15 protected abstract serverService: ServerService
16 protected abstract configService: ConfigService
17 abstract isCreation (): boolean
18 abstract getFormButtonTitle (): string
20 isTranscodingInformationDisplayed () {
21 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
23 return this.serverService.getConfig().transcoding.enabledResolutions.length !== 0 &&
27 computeQuotaWithTranscoding () {
28 const transcodingConfig = this.serverService.getConfig().transcoding
30 const resolutions = transcodingConfig.enabledResolutions
31 const higherResolution = VideoResolution.H_4K
34 for (const resolution of resolutions) {
35 multiplier += resolution / higherResolution
38 if (transcodingConfig.hls.enabled) multiplier *= 2
40 return multiplier * parseInt(this.form.value['videoQuota'], 10)
47 protected buildAdminFlags (formValue: any) {
48 return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
51 protected buildQuotaOptions () {
52 // These are used by a HTML select, so convert key into strings
53 this.videoQuotaOptions = this.configService
54 .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
56 this.videoQuotaDailyOptions = this.configService
57 .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))