]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-edit.ts
Improve 4K video quality after transcoding
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-edit.ts
CommitLineData
6a84aafd 1import { ServerService } from '../../../core'
8094a898 2import { FormReactive } from '../../../shared'
954605a8 3import { USER_ROLE_LABELS, VideoResolution } from '../../../../../../shared'
3827c3b3 4import { ConfigService } from '@app/+admin/config/shared/config.service'
1eddc9a7 5import { UserAdminFlag } from '@shared/models/users/user-flag.model'
8094a898
C
6
7export abstract class UserEdit extends FormReactive {
3827c3b3
C
8 videoQuotaOptions: { value: string, label: string }[] = []
9 videoQuotaDailyOptions: { value: string, label: string }[] = []
ad3405d0
C
10 roles = Object.keys(USER_ROLE_LABELS)
11 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
2fbe7f19 12 username: string
b426edd4 13 userId: number
954605a8 14
6a84aafd 15 protected abstract serverService: ServerService
3827c3b3 16 protected abstract configService: ConfigService
8094a898
C
17 abstract isCreation (): boolean
18 abstract getFormButtonTitle (): string
6a84aafd
C
19
20 isTranscodingInformationDisplayed () {
21 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
22
23 return this.serverService.getConfig().transcoding.enabledResolutions.length !== 0 &&
24 formVideoQuota > 0
25 }
26
27 computeQuotaWithTranscoding () {
09209296
C
28 const transcodingConfig = this.serverService.getConfig().transcoding
29
30 const resolutions = transcodingConfig.enabledResolutions
ad3405d0 31 const higherResolution = VideoResolution.H_4K
6a84aafd
C
32 let multiplier = 0
33
34 for (const resolution of resolutions) {
35 multiplier += resolution / higherResolution
36 }
37
09209296
C
38 if (transcodingConfig.hls.enabled) multiplier *= 2
39
6a84aafd
C
40 return multiplier * parseInt(this.form.value['videoQuota'], 10)
41 }
3827c3b3 42
b426edd4
C
43 resetPassword () {
44 return
45 }
46
1eddc9a7
C
47 protected buildAdminFlags (formValue: any) {
48 return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
49 }
50
3827c3b3
C
51 protected buildQuotaOptions () {
52 // These are used by a HTML select, so convert key into strings
53 this.videoQuotaOptions = this.configService
54 .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
55
56 this.videoQuotaDailyOptions = this.configService
57 .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))
58 }
8094a898 59}