]>
Commit | Line | Data |
---|---|---|
a95a4cc8 | 1 | import { AuthService, ServerService } from '../../../core' |
8094a898 | 2 | import { FormReactive } from '../../../shared' |
ba430d75 | 3 | import { ServerConfig, USER_ROLE_LABELS, UserRole, VideoResolution } from '../../../../../../shared' |
3827c3b3 | 4 | import { ConfigService } from '@app/+admin/config/shared/config.service' |
1eddc9a7 | 5 | import { UserAdminFlag } from '@shared/models/users/user-flag.model' |
ba430d75 | 6 | import { OnInit } from '@angular/core' |
8094a898 | 7 | |
ba430d75 | 8 | export abstract class UserEdit extends FormReactive implements OnInit { |
3827c3b3 C |
9 | videoQuotaOptions: { value: string, label: string }[] = [] |
10 | videoQuotaDailyOptions: { value: string, label: string }[] = [] | |
2fbe7f19 | 11 | username: string |
b426edd4 | 12 | userId: number |
954605a8 | 13 | |
ba430d75 C |
14 | protected serverConfig: ServerConfig |
15 | ||
6a84aafd | 16 | protected abstract serverService: ServerService |
3827c3b3 | 17 | protected abstract configService: ConfigService |
a95a4cc8 | 18 | protected abstract auth: AuthService |
8094a898 C |
19 | abstract isCreation (): boolean |
20 | abstract getFormButtonTitle (): string | |
6a84aafd | 21 | |
ba430d75 C |
22 | ngOnInit (): void { |
23 | this.serverConfig = this.serverService.getTmpConfig() | |
24 | this.serverService.getConfig() | |
25 | .subscribe(config => this.serverConfig = config) | |
26 | } | |
27 | ||
a95a4cc8 C |
28 | getRoles () { |
29 | const authUser = this.auth.getUser() | |
30 | ||
31 | if (authUser.role === UserRole.ADMINISTRATOR) { | |
32 | return Object.keys(USER_ROLE_LABELS) | |
33 | .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] })) | |
34 | } | |
35 | ||
36 | return [ | |
37 | { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] } | |
38 | ] | |
39 | } | |
40 | ||
6a84aafd C |
41 | isTranscodingInformationDisplayed () { |
42 | const formVideoQuota = parseInt(this.form.value['videoQuota'], 10) | |
43 | ||
ba430d75 | 44 | return this.serverConfig.transcoding.enabledResolutions.length !== 0 && |
6a84aafd C |
45 | formVideoQuota > 0 |
46 | } | |
47 | ||
48 | computeQuotaWithTranscoding () { | |
ba430d75 | 49 | const transcodingConfig = this.serverConfig.transcoding |
09209296 C |
50 | |
51 | const resolutions = transcodingConfig.enabledResolutions | |
ad3405d0 | 52 | const higherResolution = VideoResolution.H_4K |
6a84aafd C |
53 | let multiplier = 0 |
54 | ||
55 | for (const resolution of resolutions) { | |
56 | multiplier += resolution / higherResolution | |
57 | } | |
58 | ||
09209296 C |
59 | if (transcodingConfig.hls.enabled) multiplier *= 2 |
60 | ||
6a84aafd C |
61 | return multiplier * parseInt(this.form.value['videoQuota'], 10) |
62 | } | |
3827c3b3 | 63 | |
b426edd4 C |
64 | resetPassword () { |
65 | return | |
66 | } | |
67 | ||
1eddc9a7 C |
68 | protected buildAdminFlags (formValue: any) { |
69 | return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE | |
70 | } | |
71 | ||
3827c3b3 C |
72 | protected buildQuotaOptions () { |
73 | // These are used by a HTML select, so convert key into strings | |
74 | this.videoQuotaOptions = this.configService | |
75 | .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label })) | |
76 | ||
77 | this.videoQuotaDailyOptions = this.configService | |
78 | .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label })) | |
79 | } | |
8094a898 | 80 | } |