]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/shared/config.service.ts
Bumped to version v5.2.1
[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 transcodingThreadOptions: SelectOptionsItem[] = []
16
17 constructor (
18 private authHttp: HttpClient,
19 private restExtractor: RestExtractor
20 ) {
21 this.videoQuotaOptions = [
22 { id: -1, label: $localize`Unlimited` },
23 { id: 0, label: $localize`None - no upload possible` },
24 { id: 100 * 1024 * 1024, label: $localize`100MB` },
25 { id: 500 * 1024 * 1024, label: $localize`500MB` },
26 { id: 1024 * 1024 * 1024, label: $localize`1GB` },
27 { id: 5 * 1024 * 1024 * 1024, label: $localize`5GB` },
28 { id: 20 * 1024 * 1024 * 1024, label: $localize`20GB` },
29 { id: 50 * 1024 * 1024 * 1024, label: $localize`50GB` },
30 { id: 100 * 1024 * 1024 * 1024, label: $localize`100GB` },
31 { id: 200 * 1024 * 1024 * 1024, label: $localize`200GB` },
32 { id: 500 * 1024 * 1024 * 1024, label: $localize`500GB` }
33 ]
34
35 this.videoQuotaDailyOptions = [
36 { id: -1, label: $localize`Unlimited` },
37 { id: 0, label: $localize`None - no upload possible` },
38 { id: 10 * 1024 * 1024, label: $localize`10MB` },
39 { id: 50 * 1024 * 1024, label: $localize`50MB` },
40 { id: 100 * 1024 * 1024, label: $localize`100MB` },
41 { id: 500 * 1024 * 1024, label: $localize`500MB` },
42 { id: 2 * 1024 * 1024 * 1024, label: $localize`2GB` },
43 { id: 5 * 1024 * 1024 * 1024, label: $localize`5GB` },
44 { id: 10 * 1024 * 1024 * 1024, label: $localize`10GB` },
45 { id: 20 * 1024 * 1024 * 1024, label: $localize`20GB` },
46 { id: 50 * 1024 * 1024 * 1024, label: $localize`50GB` }
47 ]
48
49 this.transcodingThreadOptions = [
50 { id: 0, label: $localize`Auto (via ffmpeg)` },
51 { id: 1, label: '1' },
52 { id: 2, label: '2' },
53 { id: 4, label: '4' },
54 { id: 8, label: '8' },
55 { id: 12, label: '12' },
56 { id: 16, label: '16' },
57 { id: 32, label: '32' }
58 ]
59 }
60
61 getCustomConfig () {
62 return this.authHttp.get<CustomConfig>(ConfigService.BASE_APPLICATION_URL + '/custom')
63 .pipe(catchError(res => this.restExtractor.handleError(res)))
64 }
65
66 updateCustomConfig (data: CustomConfig) {
67 return this.authHttp.put<CustomConfig>(ConfigService.BASE_APPLICATION_URL + '/custom', data)
68 .pipe(catchError(res => this.restExtractor.handleError(res)))
69 }
70 }