]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/server/server.service.ts
Add ability to update thumbnail and preview on client
[github/Chocobozzz/PeerTube.git] / client / src / app / core / server / server.service.ts
index 16e0595b6fefa8f4d8fcff47c6a69f79639afa8a..553ad8af6f8550cdf7dff72f643ffaf161b614ad 100644 (file)
@@ -2,13 +2,15 @@ import { HttpClient } from '@angular/common/http'
 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 = API_URL + '/api/v1/config/'
-  private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
+  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<boolean>(1)
   videoCategoriesLoaded = new ReplaySubject<boolean>(1)
@@ -16,11 +18,30 @@ export class ServerService {
   videoLanguagesLoaded = new ReplaySubject<boolean>(1)
 
   private config: ServerConfig = {
+    instance: {
+      name: 'PeerTube'
+    },
+    serverVersion: 'Unknown',
     signup: {
       allowed: false
     },
     transcoding: {
       enabledResolutions: []
+    },
+    avatar: {
+      file: {
+        size: { max: 0 },
+        extensions: []
+      }
+    },
+    video: {
+      image: {
+        size: { max: 0 },
+        extensions: []
+      },
+      file: {
+        extensions: []
+      }
     }
   }
   private videoCategories: Array<{ id: number, label: string }> = []
@@ -28,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<ServerConfig>(ServerService.BASE_CONFIG_URL)
-             .subscribe(data => this.config = data)
+      .do(this.saveConfigLocally)
+      .subscribe(data => this.config = data)
   }
 
   loadVideoCategories () {
@@ -71,6 +95,10 @@ export class ServerService {
     return this.videoPrivacies
   }
 
+  getAbout () {
+    return this.http.get<About>(ServerService.BASE_CONFIG_URL + '/about')
+  }
+
   private loadVideoAttributeEnum (
     attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
     hashToPopulate: { id: number, label: string }[],
@@ -89,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)
+      }
+    }
+  }
 }