1 import { catchError, map } from 'rxjs/operators'
2 import { HttpClient } from '@angular/common/http'
3 import { Injectable } from '@angular/core'
4 import { environment } from '../../../environments/environment'
5 import { RestExtractor, RestService } from '../rest'
6 import { About } from '../../../../../shared/models/server'
7 import { MarkdownService } from '@app/shared/renderer'
8 import { peertubeTranslate } from '@shared/models'
9 import { ServerService } from '@app/core'
10 import { forkJoin } from 'rxjs'
13 export class InstanceService {
14 private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config'
15 private static BASE_SERVER_URL = environment.apiUrl + '/api/v1/server'
18 private authHttp: HttpClient,
19 private restService: RestService,
20 private restExtractor: RestExtractor,
21 private markdownService: MarkdownService,
22 private serverService: ServerService
27 return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about')
28 .pipe(catchError(res => this.restExtractor.handleError(res)))
31 contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
39 return this.authHttp.post(InstanceService.BASE_SERVER_URL + '/contact', body)
40 .pipe(catchError(res => this.restExtractor.handleError(res)))
44 async buildHtml (about: About) {
49 moderationInformation: '',
51 hardwareInformation: ''
54 for (const key of Object.keys(html)) {
55 html[ key ] = await this.markdownService.textMarkdownToHTML(about.instance[ key ])
61 buildTranslatedLanguages (about: About) {
63 this.serverService.getVideoLanguages(),
64 this.serverService.getServerLocale()
66 map(([ languagesArray, translations ]) => {
67 return about.instance.languages
69 const languageObj = languagesArray.find(la => la.id === l)
71 return peertubeTranslate(languageObj.label, translations)
77 buildTranslatedCategories (about: About) {
79 this.serverService.getVideoCategories(),
80 this.serverService.getServerLocale()
82 map(([ categoriesArray, translations ]) => {
83 return about.instance.categories
85 const categoryObj = categoriesArray.find(ca => ca.id === c)
87 return peertubeTranslate(categoryObj.label, translations)