]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/shared/config.service.ts
Migrate to $localize
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / shared / config.service.ts
1 import { catchError } from 'rxjs/operators'
2 import { HttpClient } from '@angular/common/http'
3 import { Injectable } from '@angular/core'
4 import { RestExtractor } from '@app/core'
5 import { CustomConfig } from '@shared/models'
6 import { environment } from '../../../../environments/environment'
7
8 @Injectable()
9 export class ConfigService {
10 private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/config'
11
12 videoQuotaOptions: { value: number, label: string, disabled?: boolean }[] = []
13 videoQuotaDailyOptions: { value: number, label: string, disabled?: boolean }[] = []
14
15 constructor (
16 private authHttp: HttpClient,
17 private restExtractor: RestExtractor
18 ) {
19 this.videoQuotaOptions = [
20 { value: undefined, label: 'Default quota', disabled: true },
21 { value: -1, label: $localize`Unlimited` },
22 { value: undefined, label: '─────', disabled: true },
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` }
30 ]
31
32 this.videoQuotaDailyOptions = [
33 { value: undefined, label: 'Default daily upload limit', disabled: true },
34 { value: -1, label: $localize`Unlimited` },
35 { value: undefined, label: '─────', disabled: true },
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` }
43 ]
44 }
45
46 getCustomConfig () {
47 return this.authHttp.get<CustomConfig>(ConfigService.BASE_APPLICATION_URL + '/custom')
48 .pipe(catchError(res => this.restExtractor.handleError(res)))
49 }
50
51 updateCustomConfig (data: CustomConfig) {
52 return this.authHttp.put<CustomConfig>(ConfigService.BASE_APPLICATION_URL + '/custom', data)
53 .pipe(catchError(res => this.restExtractor.handleError(res)))
54 }
55 }