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 { objectKeysTyped } from '@shared/core-utils'
7 import { peertubeTranslate } from '@shared/core-utils/i18n'
8 import { About } from '@shared/models'
9 import { environment } from '../../../environments/environment'
11 export type AboutHTML = Pick<About['instance'],
12 'terms' | 'codeOfConduct' | 'moderationInformation' | 'administrator' | 'creationReason' |
13 'maintenanceLifetime' | 'businessModel' | 'hardwareInformation'
17 export class InstanceService {
18 private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config'
19 private static BASE_SERVER_URL = environment.apiUrl + '/api/v1/server'
22 private authHttp: HttpClient,
23 private restExtractor: RestExtractor,
24 private markdownService: MarkdownService,
25 private serverService: ServerService
30 return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about')
31 .pipe(catchError(res => this.restExtractor.handleError(res)))
34 contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
42 return this.authHttp.post(InstanceService.BASE_SERVER_URL + '/contact', body)
43 .pipe(catchError(res => this.restExtractor.handleError(res)))
47 async buildHtml (about: About) {
48 const html: AboutHTML = {
51 moderationInformation: '',
54 maintenanceLifetime: '',
56 hardwareInformation: ''
59 for (const key of objectKeysTyped(html)) {
60 html[key] = await this.markdownService.enhancedMarkdownToHTML({ markdown: about.instance[key] })
66 buildTranslatedLanguages (about: About) {
68 this.serverService.getVideoLanguages(),
69 this.serverService.getServerLocale()
71 map(([ languagesArray, translations ]) => {
72 return about.instance.languages
74 const languageObj = languagesArray.find(la => la.id === l)
76 return peertubeTranslate(languageObj.label, translations)
82 buildTranslatedCategories (about: About) {
84 this.serverService.getVideoCategories(),
85 this.serverService.getServerLocale()
87 map(([ categoriesArray, translations ]) => {
88 return about.instance.categories
90 const categoryObj = categoriesArray.find(ca => ca.id === c)
92 return peertubeTranslate(categoryObj.label, translations)