1 import { Directive, 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 { USER_ROLE_LABELS } from '@shared/core-utils/users'
6 import { ServerConfig, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'
9 // tslint:disable-next-line: directive-class-suffix
10 export abstract class UserEdit extends FormReactive implements OnInit {
11 videoQuotaOptions: { value: string, label: string, disabled?: boolean }[] = []
12 videoQuotaDailyOptions: { value: string, label: string, disabled?: boolean }[] = []
16 roles: { value: string, label: string }[] = []
18 protected serverConfig: ServerConfig
20 protected abstract serverService: ServerService
21 protected abstract configService: ConfigService
22 protected abstract screenService: ScreenService
23 protected abstract auth: AuthService
24 abstract isCreation (): boolean
25 abstract getFormButtonTitle (): string
28 this.serverConfig = this.serverService.getTmpConfig()
29 this.serverService.getConfig()
30 .subscribe(config => this.serverConfig = config)
35 get subscribersCount () {
36 const forAccount = this.user
37 ? this.user.account.followersCount
39 const forChannels = this.user
40 ? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0)
42 return forAccount + forChannels
46 return this.serverConfig.plugin.registeredIdAndPassAuths.map(p => p.npmName)
47 .concat(this.serverConfig.plugin.registeredExternalAuths.map(p => p.npmName))
51 return this.screenService.getWindowInnerWidth() > 1600
55 const authUser = this.auth.getUser()
57 if (authUser.role === UserRole.ADMINISTRATOR) {
58 this.roles = Object.keys(USER_ROLE_LABELS)
59 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
64 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
68 isTranscodingInformationDisplayed () {
69 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
71 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
75 computeQuotaWithTranscoding () {
76 const transcodingConfig = this.serverConfig.transcoding
78 const resolutions = transcodingConfig.enabledResolutions
79 const higherResolution = VideoResolution.H_4K
82 for (const resolution of resolutions) {
83 multiplier += resolution / higherResolution
86 if (transcodingConfig.hls.enabled) multiplier *= 2
88 return multiplier * parseInt(this.form.value['videoQuota'], 10)
95 protected buildAdminFlags (formValue: any) {
96 return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
99 protected buildQuotaOptions () {
100 // These are used by a HTML select, so convert key into strings
101 this.videoQuotaOptions = this.configService
102 .videoQuotaOptions.map(q => ({
103 value: q.value?.toString(),
108 this.videoQuotaDailyOptions = this.configService
109 .videoQuotaDailyOptions.map(q => ({
110 value: q.value?.toString(),