1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Add about page

This commit is contained in:
Chocobozzz 2018-01-31 17:47:36 +01:00
parent 66b16cafb3
commit 36f9424ff1
No known key found for this signature in database
GPG key ID: 583A612D890159BE
20 changed files with 250 additions and 16 deletions

View file

@ -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<boolean>(1)
videoCategoriesLoaded = new ReplaySubject<boolean>(1)
@ -16,6 +18,9 @@ export class ServerService {
videoLanguagesLoaded = new ReplaySubject<boolean>(1)
private config: ServerConfig = {
instance: {
name: 'PeerTube'
},
serverVersion: 'Unknown',
signup: {
allowed: false
@ -40,11 +45,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 () {
@ -83,6 +91,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 }[],
@ -101,4 +113,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)
}
}
}
}