1 import { forkJoin } from 'rxjs'
2 import { catchError, map } from 'rxjs/operators'
3 import { HttpClient } from '@angular/common/http'
4 import { Injectable } from '@angular/core'
5 import { MarkdownService, RestExtractor, ServerService } from '@app/core'
6 import { About, peertubeTranslate } from '@shared/models'
7 import { environment } from '../../../environments/environment'
10 export class InstanceService {
11 private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config'
12 private static BASE_SERVER_URL = environment.apiUrl + '/api/v1/server'
15 private authHttp: HttpClient,
16 private restExtractor: RestExtractor,
17 private markdownService: MarkdownService,
18 private serverService: ServerService
23 return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about')
24 .pipe(catchError(res => this.restExtractor.handleError(res)))
27 contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
35 return this.authHttp.post(InstanceService.BASE_SERVER_URL + '/contact', body)
36 .pipe(catchError(res => this.restExtractor.handleError(res)))
40 async buildHtml (about: About) {
45 moderationInformation: '',
47 hardwareInformation: ''
50 for (const key of Object.keys(html)) {
51 html[ key ] = await this.markdownService.textMarkdownToHTML(about.instance[ key ])
57 buildTranslatedLanguages (about: About) {
59 this.serverService.getVideoLanguages(),
60 this.serverService.getServerLocale()
62 map(([ languagesArray, translations ]) => {
63 return about.instance.languages
65 const languageObj = languagesArray.find(la => la.id === l)
67 return peertubeTranslate(languageObj.label, translations)
73 buildTranslatedCategories (about: About) {
75 this.serverService.getVideoCategories(),
76 this.serverService.getServerLocale()
78 map(([ categoriesArray, translations ]) => {
79 return about.instance.categories
81 const categoryObj = categoriesArray.find(ca => ca.id === c)
83 return peertubeTranslate(categoryObj.label, translations)