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 { peertubeTranslate } from '@shared/core-utils/i18n'
7 import { About } from '@shared/models'
8 import { environment } from '../../../environments/environment'
11 export class InstanceService {
12 private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config'
13 private static BASE_SERVER_URL = environment.apiUrl + '/api/v1/server'
16 private authHttp: HttpClient,
17 private restExtractor: RestExtractor,
18 private markdownService: MarkdownService,
19 private serverService: ServerService
24 return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about')
25 .pipe(catchError(res => this.restExtractor.handleError(res)))
28 contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
36 return this.authHttp.post(InstanceService.BASE_SERVER_URL + '/contact', body)
37 .pipe(catchError(res => this.restExtractor.handleError(res)))
41 async buildHtml (about: About) {
46 moderationInformation: '',
48 hardwareInformation: ''
51 for (const key of Object.keys(html)) {
52 html[ key ] = await this.markdownService.textMarkdownToHTML(about.instance[ key ])
58 buildTranslatedLanguages (about: About) {
60 this.serverService.getVideoLanguages(),
61 this.serverService.getServerLocale()
63 map(([ languagesArray, translations ]) => {
64 return about.instance.languages
66 const languageObj = languagesArray.find(la => la.id === l)
68 return peertubeTranslate(languageObj.label, translations)
74 buildTranslatedCategories (about: About) {
76 this.serverService.getVideoCategories(),
77 this.serverService.getServerLocale()
79 map(([ categoriesArray, translations ]) => {
80 return about.instance.categories
82 const categoryObj = categoriesArray.find(ca => ca.id === c)
84 return peertubeTranslate(categoryObj.label, translations)