]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/users/user-edit/user-edit.ts
Implement daily upload limit (#956)
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-edit.ts
1 import { ServerService } from '../../../core'
2 import { FormReactive } from '../../../shared'
3 import { USER_ROLE_LABELS, VideoResolution } from '../../../../../../shared'
4 import { EditCustomConfigComponent } from '../../../+admin/config/edit-custom-config/'
5
6 export abstract class UserEdit extends FormReactive {
7
8 // These are used by a HTML select, so convert key into strings
9 videoQuotaOptions = EditCustomConfigComponent.videoQuotaOptions
10 .map(q => ({ value: q.value.toString(), label: q.label }))
11 videoQuotaDailyOptions = EditCustomConfigComponent.videoQuotaDailyOptions
12 .map(q => ({ value: q.value.toString(), label: q.label }))
13
14 roles = Object.keys(USER_ROLE_LABELS).map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
15
16 protected abstract serverService: ServerService
17 abstract isCreation (): boolean
18 abstract getFormButtonTitle (): string
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 () {
28 const resolutions = this.serverService.getConfig().transcoding.enabledResolutions
29 const higherResolution = VideoResolution.H_1080P
30 let multiplier = 0
31
32 for (const resolution of resolutions) {
33 multiplier += resolution / higherResolution
34 }
35
36 return multiplier * parseInt(this.form.value['videoQuota'], 10)
37 }
38 }