1 import { catchError } 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'
12 export class InstanceService {
13 private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config'
14 private static BASE_SERVER_URL = environment.apiUrl + '/api/v1/server'
17 private authHttp: HttpClient,
18 private restService: RestService,
19 private restExtractor: RestExtractor,
20 private markdownService: MarkdownService,
21 private serverService: ServerService
26 return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about')
27 .pipe(catchError(res => this.restExtractor.handleError(res)))
30 contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
38 return this.authHttp.post(InstanceService.BASE_SERVER_URL + '/contact', body)
39 .pipe(catchError(res => this.restExtractor.handleError(res)))
43 async buildHtml (about: About) {
48 moderationInformation: '',
50 hardwareInformation: ''
53 for (const key of Object.keys(html)) {
54 html[ key ] = await this.markdownService.textMarkdownToHTML(about.instance[ key ])
60 buildTranslatedLanguages (about: About, translations: any) {
61 const languagesArray = this.serverService.getVideoLanguages()
63 return about.instance.languages
65 const languageObj = languagesArray.find(la => la.id === l)
67 return peertubeTranslate(languageObj.label, translations)
71 buildTranslatedCategories (about: About, translations: any) {
72 const categoriesArray = this.serverService.getVideoCategories()
74 return about.instance.categories
76 const categoryObj = categoriesArray.find(ca => ca.id === c)
78 return peertubeTranslate(categoryObj.label, translations)