1 import { OnInit, Directive } from '@angular/core'
2 import { ConfigService } from '@app/+admin/config/shared/config.service'
3 import { AuthService, ScreenService, ServerService, User } from '@app/core'
4 import { FormReactive } from '@app/shared/shared-forms'
5 import { ServerConfig, USER_ROLE_LABELS, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'
8 export abstract class UserEdit extends FormReactive implements OnInit {
9 videoQuotaOptions: { value: string, label: string, disabled?: boolean }[] = []
10 videoQuotaDailyOptions: { value: string, label: string, disabled?: boolean }[] = []
14 roles: { value: string, label: string }[] = []
16 protected serverConfig: ServerConfig
18 protected abstract serverService: ServerService
19 protected abstract configService: ConfigService
20 protected abstract screenService: ScreenService
21 protected abstract auth: AuthService
22 abstract isCreation (): boolean
23 abstract getFormButtonTitle (): string
26 this.serverConfig = this.serverService.getTmpConfig()
27 this.serverService.getConfig()
28 .subscribe(config => this.serverConfig = config)
33 get subscribersCount () {
34 const forAccount = this.user
35 ? this.user.account.followersCount
37 const forChannels = this.user
38 ? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0)
40 return forAccount + forChannels
44 return this.screenService.getWindowInnerWidth() > 1600
48 const authUser = this.auth.getUser()
50 if (authUser.role === UserRole.ADMINISTRATOR) {
51 this.roles = Object.keys(USER_ROLE_LABELS)
52 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
57 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
61 isTranscodingInformationDisplayed () {
62 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
64 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
68 computeQuotaWithTranscoding () {
69 const transcodingConfig = this.serverConfig.transcoding
71 const resolutions = transcodingConfig.enabledResolutions
72 const higherResolution = VideoResolution.H_4K
75 for (const resolution of resolutions) {
76 multiplier += resolution / higherResolution
79 if (transcodingConfig.hls.enabled) multiplier *= 2
81 return multiplier * parseInt(this.form.value['videoQuota'], 10)
88 protected buildAdminFlags (formValue: any) {
89 return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
92 protected buildQuotaOptions () {
93 // These are used by a HTML select, so convert key into strings
94 this.videoQuotaOptions = this.configService
95 .videoQuotaOptions.map(q => ({
96 value: q.value?.toString(),
101 this.videoQuotaDailyOptions = this.configService
102 .videoQuotaDailyOptions.map(q => ({
103 value: q.value?.toString(),
109 this.videoQuotaOptions,
110 this.videoQuotaDailyOptions