]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/server/server.service.ts
Make some fields optional when uploading a video
[github/Chocobozzz/PeerTube.git] / client / src / app / core / server / server.service.ts
CommitLineData
db7af09b
C
1import { Injectable } from '@angular/core'
2import { HttpClient } from '@angular/common/http'
3
4import { ServerConfig } from '../../../../../shared'
5
6@Injectable()
7export 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
6a84aafd
C
14 },
15 transcoding: {
16 enabledResolutions: []
db7af09b
C
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 }> = []
fd45e8f4 22 private videoPrivacies: Array<{ id: number, label: string }> = []
db7af09b
C
23
24 constructor (private http: HttpClient) {}
25
26 loadConfig () {
27 this.http.get<ServerConfig>(ServerService.BASE_CONFIG_URL)
28 .subscribe(data => this.config = data)
29 }
30
31 loadVideoCategories () {
32 return this.loadVideoAttributeEnum('categories', this.videoCategories)
33 }
34
35 loadVideoLicences () {
36 return this.loadVideoAttributeEnum('licences', this.videoLicences)
37 }
38
39 loadVideoLanguages () {
40 return this.loadVideoAttributeEnum('languages', this.videoLanguages)
41 }
42
fd45e8f4
C
43 loadVideoPrivacies () {
44 return this.loadVideoAttributeEnum('privacies', this.videoPrivacies)
45 }
46
db7af09b
C
47 getConfig () {
48 return this.config
49 }
50
51 getVideoCategories () {
52 return this.videoCategories
53 }
54
55 getVideoLicences () {
56 return this.videoLicences
57 }
58
59 getVideoLanguages () {
60 return this.videoLanguages
61 }
62
fd45e8f4
C
63 getVideoPrivacies () {
64 return this.videoPrivacies
65 }
66
67 private loadVideoAttributeEnum (
68 attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
69 hashToPopulate: { id: number, label: string }[]
70 ) {
db7af09b
C
71 return this.http.get(ServerService.BASE_VIDEO_URL + attributeName)
72 .subscribe(data => {
73 Object.keys(data)
74 .forEach(dataKey => {
75 hashToPopulate.push({
76 id: parseInt(dataKey, 10),
77 label: data[dataKey]
78 })
79 })
80 })
81 }
82}