X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Fserver%2Fserver.service.ts;h=553ad8af6f8550cdf7dff72f643ffaf161b614ad;hb=6de36768980ef6063b8fcd730b59fa685dd2b99c;hp=45f68b4340731abd2918ee0c7efaee36ca6fd5bf;hpb=01de67b9a4fcdf01102ccc3cb7dc24beebf6c7ea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index 45f68b434..553ad8af6 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' import 'rxjs/add/operator/do' import { ReplaySubject } from 'rxjs/ReplaySubject' import { ServerConfig } from '../../../../../shared' +import { About } from '../../../../../shared/models/config/about.model' import { environment } from '../../../environments/environment' @Injectable() export class ServerService { private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config/' private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' + private static CONFIG_LOCAL_STORAGE_KEY = 'server-config' videoPrivaciesLoaded = new ReplaySubject(1) videoCategoriesLoaded = new ReplaySubject(1) @@ -16,6 +18,10 @@ export class ServerService { videoLanguagesLoaded = new ReplaySubject(1) private config: ServerConfig = { + instance: { + name: 'PeerTube' + }, + serverVersion: 'Unknown', signup: { allowed: false }, @@ -29,6 +35,10 @@ export class ServerService { } }, video: { + image: { + size: { max: 0 }, + extensions: [] + }, file: { extensions: [] } @@ -39,11 +49,14 @@ export class ServerService { private videoLanguages: Array<{ id: number, label: string }> = [] private videoPrivacies: Array<{ id: number, label: string }> = [] - constructor (private http: HttpClient) {} + constructor (private http: HttpClient) { + this.loadConfigLocally() + } loadConfig () { this.http.get(ServerService.BASE_CONFIG_URL) - .subscribe(data => this.config = data) + .do(this.saveConfigLocally) + .subscribe(data => this.config = data) } loadVideoCategories () { @@ -82,6 +95,10 @@ export class ServerService { return this.videoPrivacies } + getAbout () { + return this.http.get(ServerService.BASE_CONFIG_URL + '/about') + } + private loadVideoAttributeEnum ( attributeName: 'categories' | 'licences' | 'languages' | 'privacies', hashToPopulate: { id: number, label: string }[], @@ -100,4 +117,21 @@ export class ServerService { notifier.next(true) }) } + + private saveConfigLocally (config: ServerConfig) { + localStorage.setItem(ServerService.CONFIG_LOCAL_STORAGE_KEY, JSON.stringify(config)) + } + + private loadConfigLocally () { + const configString = localStorage.getItem(ServerService.CONFIG_LOCAL_STORAGE_KEY) + + if (configString) { + try { + const parsed = JSON.parse(configString) + Object.assign(this.config, parsed) + } catch (err) { + console.error('Cannot parse config saved in local storage.', err) + } + } + } }