1 import { HttpClient } from '@angular/common/http'
2 import { Injectable } from '@angular/core'
3 import 'rxjs/add/operator/do'
4 import { ReplaySubject } from 'rxjs/ReplaySubject'
6 import { ServerConfig } from '../../../../../shared'
9 export class ServerService {
10 private static BASE_CONFIG_URL = API_URL + '/api/v1/config/'
11 private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
13 videoPrivaciesLoaded = new ReplaySubject<boolean>(1)
14 videoCategoriesLoaded = new ReplaySubject<boolean>(1)
15 videoLicencesLoaded = new ReplaySubject<boolean>(1)
16 videoLanguagesLoaded = new ReplaySubject<boolean>(1)
18 private config: ServerConfig = {
23 enabledResolutions: []
26 private videoCategories: Array<{ id: number, label: string }> = []
27 private videoLicences: Array<{ id: number, label: string }> = []
28 private videoLanguages: Array<{ id: number, label: string }> = []
29 private videoPrivacies: Array<{ id: number, label: string }> = []
31 constructor (private http: HttpClient) {}
34 this.http.get<ServerConfig>(ServerService.BASE_CONFIG_URL)
35 .subscribe(data => this.config = data)
38 loadVideoCategories () {
39 return this.loadVideoAttributeEnum('categories', this.videoCategories, this.videoCategoriesLoaded)
42 loadVideoLicences () {
43 return this.loadVideoAttributeEnum('licences', this.videoLicences, this.videoLicencesLoaded)
46 loadVideoLanguages () {
47 return this.loadVideoAttributeEnum('languages', this.videoLanguages, this.videoLanguagesLoaded)
50 loadVideoPrivacies () {
51 return this.loadVideoAttributeEnum('privacies', this.videoPrivacies, this.videoPrivaciesLoaded)
58 getVideoCategories () {
59 return this.videoCategories
63 return this.videoLicences
66 getVideoLanguages () {
67 return this.videoLanguages
70 getVideoPrivacies () {
71 return this.videoPrivacies
74 private loadVideoAttributeEnum (
75 attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
76 hashToPopulate: { id: number, label: string }[],
77 notifier: ReplaySubject<boolean>
79 return this.http.get(ServerService.BASE_VIDEO_URL + attributeName)
84 id: parseInt(dataKey, 10),