]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/server/server.service.ts
Take in account transcoding for video quota
[github/Chocobozzz/PeerTube.git] / client / src / app / core / server / server.service.ts
1 import { Injectable } from '@angular/core'
2 import { HttpClient } from '@angular/common/http'
3
4 import { ServerConfig } from '../../../../../shared'
5
6 @Injectable()
7 export class ServerService {
8 private static BASE_CONFIG_URL = API_URL + '/api/v1/config/'
9 private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
10
11 private config: ServerConfig = {
12 signup: {
13 allowed: false
14 },
15 transcoding: {
16 enabledResolutions: []
17 }
18 }
19 private videoCategories: Array<{ id: number, label: string }> = []
20 private videoLicences: Array<{ id: number, label: string }> = []
21 private videoLanguages: Array<{ id: number, label: string }> = []
22
23 constructor (private http: HttpClient) {}
24
25 loadConfig () {
26 this.http.get<ServerConfig>(ServerService.BASE_CONFIG_URL)
27 .subscribe(data => this.config = data)
28 }
29
30 loadVideoCategories () {
31 return this.loadVideoAttributeEnum('categories', this.videoCategories)
32 }
33
34 loadVideoLicences () {
35 return this.loadVideoAttributeEnum('licences', this.videoLicences)
36 }
37
38 loadVideoLanguages () {
39 return this.loadVideoAttributeEnum('languages', this.videoLanguages)
40 }
41
42 getConfig () {
43 return this.config
44 }
45
46 getVideoCategories () {
47 return this.videoCategories
48 }
49
50 getVideoLicences () {
51 return this.videoLicences
52 }
53
54 getVideoLanguages () {
55 return this.videoLanguages
56 }
57
58 private loadVideoAttributeEnum (attributeName: 'categories' | 'licences' | 'languages', hashToPopulate: { id: number, label: string }[]) {
59 return this.http.get(ServerService.BASE_VIDEO_URL + attributeName)
60 .subscribe(data => {
61 Object.keys(data)
62 .forEach(dataKey => {
63 hashToPopulate.push({
64 id: parseInt(dataKey, 10),
65 label: data[dataKey]
66 })
67 })
68 })
69 }
70 }