1 import { catchError } from 'rxjs/operators'
2 import { HttpClient } from '@angular/common/http'
3 import { Injectable } from '@angular/core'
4 import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model'
5 import { environment } from '../../../../environments/environment'
6 import { RestExtractor } from '../../../shared'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
10 export class ConfigService {
11 private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/config'
13 videoQuotaOptions: { value: number, label: string }[] = []
14 videoQuotaDailyOptions: { value: number, label: string }[] = []
17 private authHttp: HttpClient,
18 private restExtractor: RestExtractor,
21 this.videoQuotaOptions = [
22 { value: -1, label: this.i18n('Unlimited') },
23 { value: 0, label: '0' },
24 { value: 100 * 1024 * 1024, label: this.i18n('100MB') },
25 { value: 500 * 1024 * 1024, label: this.i18n('500MB') },
26 { value: 1024 * 1024 * 1024, label: this.i18n('1GB') },
27 { value: 5 * 1024 * 1024 * 1024, label: this.i18n('5GB') },
28 { value: 20 * 1024 * 1024 * 1024, label: this.i18n('20GB') },
29 { value: 50 * 1024 * 1024 * 1024, label: this.i18n('50GB') }
32 this.videoQuotaDailyOptions = [
33 { value: -1, label: this.i18n('Unlimited') },
34 { value: 0, label: '0' },
35 { value: 10 * 1024 * 1024, label: this.i18n('10MB') },
36 { value: 50 * 1024 * 1024, label: this.i18n('50MB') },
37 { value: 100 * 1024 * 1024, label: this.i18n('100MB') },
38 { value: 500 * 1024 * 1024, label: this.i18n('500MB') },
39 { value: 2 * 1024 * 1024 * 1024, label: this.i18n('2GB') },
40 { value: 5 * 1024 * 1024 * 1024, label: this.i18n('5GB') }
45 return this.authHttp.get<CustomConfig>(ConfigService.BASE_APPLICATION_URL + '/custom')
46 .pipe(catchError(res => this.restExtractor.handleError(res)))
49 updateCustomConfig (data: CustomConfig) {
50 return this.authHttp.put<CustomConfig>(ConfigService.BASE_APPLICATION_URL + '/custom', data)
51 .pipe(catchError(res => this.restExtractor.handleError(res)))