]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-instance/instance.service.ts
Fix HTML in account/channel description
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-instance / instance.service.ts
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'
9
10 @Injectable()
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'
14
15 constructor (
16 private authHttp: HttpClient,
17 private restExtractor: RestExtractor,
18 private markdownService: MarkdownService,
19 private serverService: ServerService
20 ) {
21 }
22
23 getAbout () {
24 return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about')
25 .pipe(catchError(res => this.restExtractor.handleError(res)))
26 }
27
28 contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
29 const body = {
30 fromEmail,
31 fromName,
32 subject,
33 body: message
34 }
35
36 return this.authHttp.post(InstanceService.BASE_SERVER_URL + '/contact', body)
37 .pipe(catchError(res => this.restExtractor.handleError(res)))
38
39 }
40
41 async buildHtml (about: About) {
42 const html = {
43 terms: '',
44 codeOfConduct: '',
45 moderationInformation: '',
46 administrator: '',
47 creationReason: '',
48 maintenanceLifetime: '',
49 businessModel: '',
50 hardwareInformation: ''
51 }
52
53 for (const key of Object.keys(html)) {
54 html[key] = await this.markdownService.textMarkdownToHTML({ markdown: about.instance[key] })
55 }
56
57 return html
58 }
59
60 buildTranslatedLanguages (about: About) {
61 return forkJoin([
62 this.serverService.getVideoLanguages(),
63 this.serverService.getServerLocale()
64 ]).pipe(
65 map(([ languagesArray, translations ]) => {
66 return about.instance.languages
67 .map(l => {
68 const languageObj = languagesArray.find(la => la.id === l)
69
70 return peertubeTranslate(languageObj.label, translations)
71 })
72 })
73 )
74 }
75
76 buildTranslatedCategories (about: About) {
77 return forkJoin([
78 this.serverService.getVideoCategories(),
79 this.serverService.getServerLocale()
80 ]).pipe(
81 map(([ categoriesArray, translations ]) => {
82 return about.instance.categories
83 .map(c => {
84 const categoryObj = categoriesArray.find(ca => ca.id === c)
85
86 return peertubeTranslate(categoryObj.label, translations)
87 })
88 })
89 )
90 }
91 }