]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/shared/config.service.ts
Add ability to set a custom quota
[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 { SelectOptionsItem } from '../../../../types/select-options-item.model'
7 import { environment } from '../../../../environments/environment'
8
9 @Injectable()
10 export class ConfigService {
11 private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/config'
12
13 videoQuotaOptions: SelectOptionsItem[] = []
14 videoQuotaDailyOptions: SelectOptionsItem[] = []
15
16 constructor (
17 private authHttp: HttpClient,
18 private restExtractor: RestExtractor
19 ) {
20 this.videoQuotaOptions = [
21 { id: -1, label: $localize`Unlimited` },
22 { id: 0, label: $localize`None - no upload possible` },
23 { id: 100 * 1024 * 1024, label: $localize`100MB` },
24 { id: 500 * 1024 * 1024, label: $localize`500MB` },
25 { id: 1024 * 1024 * 1024, label: $localize`1GB` },
26 { id: 5 * 1024 * 1024 * 1024, label: $localize`5GB` },
27 { id: 20 * 1024 * 1024 * 1024, label: $localize`20GB` },
28 { id: 50 * 1024 * 1024 * 1024, label: $localize`50GB` },
29 { id: 100 * 1024 * 1024 * 1024, label: $localize`100GB` },
30 { id: 200 * 1024 * 1024 * 1024, label: $localize`200GB` },
31 { id: 500 * 1024 * 1024 * 1024, label: $localize`500GB` }
32 ]
33
34 this.videoQuotaDailyOptions = [
35 { id: -1, label: $localize`Unlimited` },
36 { id: 0, label: $localize`None - no upload possible` },
37 { id: 10 * 1024 * 1024, label: $localize`10MB` },
38 { id: 50 * 1024 * 1024, label: $localize`50MB` },
39 { id: 100 * 1024 * 1024, label: $localize`100MB` },
40 { id: 500 * 1024 * 1024, label: $localize`500MB` },
41 { id: 2 * 1024 * 1024 * 1024, label: $localize`2GB` },
42 { id: 5 * 1024 * 1024 * 1024, label: $localize`5GB` },
43 { id: 10 * 1024 * 1024 * 1024, label: $localize`10GB` },
44 { id: 20 * 1024 * 1024 * 1024, label: $localize`20GB` },
45 { id: 50 * 1024 * 1024 * 1024, label: $localize`50GB` }
46 ]
47 }
48
49 getCustomConfig () {
50 return this.authHttp.get<CustomConfig>(ConfigService.BASE_APPLICATION_URL + '/custom')
51 .pipe(catchError(res => this.restExtractor.handleError(res)))
52 }
53
54 updateCustomConfig (data: CustomConfig) {
55 return this.authHttp.put<CustomConfig>(ConfigService.BASE_APPLICATION_URL + '/custom', data)
56 .pipe(catchError(res => this.restExtractor.handleError(res)))
57 }
58 }