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