diff options
Diffstat (limited to 'client/src/app/core/server/server.service.ts')
-rw-r--r-- | client/src/app/core/server/server.service.ts | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index 6df449018..65714fd05 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts | |||
@@ -3,12 +3,14 @@ import { Injectable } from '@angular/core' | |||
3 | import 'rxjs/add/operator/do' | 3 | import 'rxjs/add/operator/do' |
4 | import { ReplaySubject } from 'rxjs/ReplaySubject' | 4 | import { ReplaySubject } from 'rxjs/ReplaySubject' |
5 | import { ServerConfig } from '../../../../../shared' | 5 | import { ServerConfig } from '../../../../../shared' |
6 | import { About } from '../../../../../shared/models/config/about.model' | ||
6 | import { environment } from '../../../environments/environment' | 7 | import { environment } from '../../../environments/environment' |
7 | 8 | ||
8 | @Injectable() | 9 | @Injectable() |
9 | export class ServerService { | 10 | export class ServerService { |
10 | private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config/' | 11 | private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config/' |
11 | private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' | 12 | private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' |
13 | private static CONFIG_LOCAL_STORAGE_KEY = 'server-config' | ||
12 | 14 | ||
13 | videoPrivaciesLoaded = new ReplaySubject<boolean>(1) | 15 | videoPrivaciesLoaded = new ReplaySubject<boolean>(1) |
14 | videoCategoriesLoaded = new ReplaySubject<boolean>(1) | 16 | videoCategoriesLoaded = new ReplaySubject<boolean>(1) |
@@ -16,6 +18,9 @@ export class ServerService { | |||
16 | videoLanguagesLoaded = new ReplaySubject<boolean>(1) | 18 | videoLanguagesLoaded = new ReplaySubject<boolean>(1) |
17 | 19 | ||
18 | private config: ServerConfig = { | 20 | private config: ServerConfig = { |
21 | instance: { | ||
22 | name: 'PeerTube' | ||
23 | }, | ||
19 | serverVersion: 'Unknown', | 24 | serverVersion: 'Unknown', |
20 | signup: { | 25 | signup: { |
21 | allowed: false | 26 | allowed: false |
@@ -40,11 +45,14 @@ export class ServerService { | |||
40 | private videoLanguages: Array<{ id: number, label: string }> = [] | 45 | private videoLanguages: Array<{ id: number, label: string }> = [] |
41 | private videoPrivacies: Array<{ id: number, label: string }> = [] | 46 | private videoPrivacies: Array<{ id: number, label: string }> = [] |
42 | 47 | ||
43 | constructor (private http: HttpClient) {} | 48 | constructor (private http: HttpClient) { |
49 | this.loadConfigLocally() | ||
50 | } | ||
44 | 51 | ||
45 | loadConfig () { | 52 | loadConfig () { |
46 | this.http.get<ServerConfig>(ServerService.BASE_CONFIG_URL) | 53 | this.http.get<ServerConfig>(ServerService.BASE_CONFIG_URL) |
47 | .subscribe(data => this.config = data) | 54 | .do(this.saveConfigLocally) |
55 | .subscribe(data => this.config = data) | ||
48 | } | 56 | } |
49 | 57 | ||
50 | loadVideoCategories () { | 58 | loadVideoCategories () { |
@@ -83,6 +91,10 @@ export class ServerService { | |||
83 | return this.videoPrivacies | 91 | return this.videoPrivacies |
84 | } | 92 | } |
85 | 93 | ||
94 | getAbout () { | ||
95 | return this.http.get<About>(ServerService.BASE_CONFIG_URL + '/about') | ||
96 | } | ||
97 | |||
86 | private loadVideoAttributeEnum ( | 98 | private loadVideoAttributeEnum ( |
87 | attributeName: 'categories' | 'licences' | 'languages' | 'privacies', | 99 | attributeName: 'categories' | 'licences' | 'languages' | 'privacies', |
88 | hashToPopulate: { id: number, label: string }[], | 100 | hashToPopulate: { id: number, label: string }[], |
@@ -101,4 +113,21 @@ export class ServerService { | |||
101 | notifier.next(true) | 113 | notifier.next(true) |
102 | }) | 114 | }) |
103 | } | 115 | } |
116 | |||
117 | private saveConfigLocally (config: ServerConfig) { | ||
118 | localStorage.setItem(ServerService.CONFIG_LOCAL_STORAGE_KEY, JSON.stringify(config)) | ||
119 | } | ||
120 | |||
121 | private loadConfigLocally () { | ||
122 | const configString = localStorage.getItem(ServerService.CONFIG_LOCAL_STORAGE_KEY) | ||
123 | |||
124 | if (configString) { | ||
125 | try { | ||
126 | const parsed = JSON.parse(configString) | ||
127 | Object.assign(this.config, parsed) | ||
128 | } catch (err) { | ||
129 | console.error('Cannot parse config saved in local storage.', err) | ||
130 | } | ||
131 | } | ||
132 | } | ||
104 | } | 133 | } |