]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/config/shared/config.service.ts
Support custom value in ng-select
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / shared / config.service.ts
CommitLineData
db400f44 1import { catchError } from 'rxjs/operators'
fd206f0b
C
2import { HttpClient } from '@angular/common/http'
3import { Injectable } from '@angular/core'
67ed6552 4import { RestExtractor } from '@app/core'
67ed6552
C
5import { CustomConfig } from '@shared/models'
6import { environment } from '../../../../environments/environment'
fd206f0b
C
7
8@Injectable()
9export class ConfigService {
10 private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/config'
11
2bc9bd08
RK
12 videoQuotaOptions: { value: number, label: string, disabled?: boolean }[] = []
13 videoQuotaDailyOptions: { value: number, label: string, disabled?: boolean }[] = []
3827c3b3 14
fd206f0b
C
15 constructor (
16 private authHttp: HttpClient,
66357162
C
17 private restExtractor: RestExtractor
18 ) {
3827c3b3 19 this.videoQuotaOptions = [
2bc9bd08 20 { value: undefined, label: 'Default quota', disabled: true },
66357162 21 { value: -1, label: $localize`Unlimited` },
2bc9bd08 22 { value: undefined, label: '─────', disabled: true },
66357162
C
23 { value: 0, label: $localize`None - no upload possible` },
24 { value: 100 * 1024 * 1024, label: $localize`100MB` },
25 { value: 500 * 1024 * 1024, label: $localize`500MB` },
26 { value: 1024 * 1024 * 1024, label: $localize`1GB` },
27 { value: 5 * 1024 * 1024 * 1024, label: $localize`5GB` },
28 { value: 20 * 1024 * 1024 * 1024, label: $localize`20GB` },
29 { value: 50 * 1024 * 1024 * 1024, label: $localize`50GB` }
3827c3b3
C
30 ]
31
32 this.videoQuotaDailyOptions = [
2bc9bd08 33 { value: undefined, label: 'Default daily upload limit', disabled: true },
66357162 34 { value: -1, label: $localize`Unlimited` },
2bc9bd08 35 { value: undefined, label: '─────', disabled: true },
66357162
C
36 { value: 0, label: $localize`None - no upload possible` },
37 { value: 10 * 1024 * 1024, label: $localize`10MB` },
38 { value: 50 * 1024 * 1024, label: $localize`50MB` },
39 { value: 100 * 1024 * 1024, label: $localize`100MB` },
40 { value: 500 * 1024 * 1024, label: $localize`500MB` },
41 { value: 2 * 1024 * 1024 * 1024, label: $localize`2GB` },
42 { value: 5 * 1024 * 1024 * 1024, label: $localize`5GB` }
3827c3b3
C
43 ]
44 }
fd206f0b
C
45
46 getCustomConfig () {
47 return this.authHttp.get<CustomConfig>(ConfigService.BASE_APPLICATION_URL + '/custom')
db400f44 48 .pipe(catchError(res => this.restExtractor.handleError(res)))
fd206f0b
C
49 }
50
51 updateCustomConfig (data: CustomConfig) {
52 return this.authHttp.put<CustomConfig>(ConfigService.BASE_APPLICATION_URL + '/custom', data)
db400f44 53 .pipe(catchError(res => this.restExtractor.handleError(res)))
fd206f0b
C
54 }
55}