1 import { OnInit } 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'
7 export abstract class UserEdit extends FormReactive implements OnInit {
8 videoQuotaOptions: { value: string, label: string, disabled?: boolean }[] = []
9 videoQuotaDailyOptions: { value: string, label: string, disabled?: boolean }[] = []
13 roles: { value: string, label: string }[] = []
15 protected serverConfig: ServerConfig
17 protected abstract serverService: ServerService
18 protected abstract configService: ConfigService
19 protected abstract screenService: ScreenService
20 protected abstract auth: AuthService
21 abstract isCreation (): boolean
22 abstract getFormButtonTitle (): string
25 this.serverConfig = this.serverService.getTmpConfig()
26 this.serverService.getConfig()
27 .subscribe(config => this.serverConfig = config)
32 get subscribersCount () {
33 const forAccount = this.user
34 ? this.user.account.followersCount
36 const forChannels = this.user
37 ? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0)
39 return forAccount + forChannels
43 return this.screenService.getWindowInnerWidth() > 1600
47 const authUser = this.auth.getUser()
49 if (authUser.role === UserRole.ADMINISTRATOR) {
50 this.roles = Object.keys(USER_ROLE_LABELS)
51 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
56 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
60 isTranscodingInformationDisplayed () {
61 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
63 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
67 computeQuotaWithTranscoding () {
68 const transcodingConfig = this.serverConfig.transcoding
70 const resolutions = transcodingConfig.enabledResolutions
71 const higherResolution = VideoResolution.H_4K
74 for (const resolution of resolutions) {
75 multiplier += resolution / higherResolution
78 if (transcodingConfig.hls.enabled) multiplier *= 2
80 return multiplier * parseInt(this.form.value['videoQuota'], 10)
87 protected buildAdminFlags (formValue: any) {
88 return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
91 protected buildQuotaOptions () {
92 // These are used by a HTML select, so convert key into strings
93 this.videoQuotaOptions = this.configService
94 .videoQuotaOptions.map(q => ({
95 value: q.value?.toString(),
100 this.videoQuotaDailyOptions = this.configService
101 .videoQuotaDailyOptions.map(q => ({
102 value: q.value?.toString(),
108 this.videoQuotaOptions,
109 this.videoQuotaDailyOptions