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'
10 export type AboutHTML = Pick<About['instance'],
11 'terms' | 'codeOfConduct' | 'moderationInformation' | 'administrator' | 'creationReason' |
12 'maintenanceLifetime' | 'businessModel' | 'hardwareInformation'
16 export class InstanceService {
17 private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config'
18 private static BASE_SERVER_URL = environment.apiUrl + '/api/v1/server'
21 private authHttp: HttpClient,
22 private restExtractor: RestExtractor,
23 private markdownService: MarkdownService,
24 private serverService: ServerService
29 return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about')
30 .pipe(catchError(res => this.restExtractor.handleError(res)))
33 contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
41 return this.authHttp.post(InstanceService.BASE_SERVER_URL + '/contact', body)
42 .pipe(catchError(res => this.restExtractor.handleError(res)))
46 async buildHtml (about: About) {
47 const html: AboutHTML = {
50 moderationInformation: '',
53 maintenanceLifetime: '',
55 hardwareInformation: ''
58 for (const key of Object.keys(html)) {
59 html[key] = await this.markdownService.enhancedMarkdownToHTML({ markdown: about.instance[key] })
65 buildTranslatedLanguages (about: About) {
67 this.serverService.getVideoLanguages(),
68 this.serverService.getServerLocale()
70 map(([ languagesArray, translations ]) => {
71 return about.instance.languages
73 const languageObj = languagesArray.find(la => la.id === l)
75 return peertubeTranslate(languageObj.label, translations)
81 buildTranslatedCategories (about: About) {
83 this.serverService.getVideoCategories(),
84 this.serverService.getServerLocale()
86 map(([ categoriesArray, translations ]) => {
87 return about.instance.categories
89 const categoryObj = categoriesArray.find(ca => ca.id === c)
91 return peertubeTranslate(categoryObj.label, translations)