]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { forkJoin } from 'rxjs' |
ba430d75 | 2 | import { catchError, map } from 'rxjs/operators' |
d3e56c0c C |
3 | import { HttpClient } from '@angular/common/http' |
4 | import { Injectable } from '@angular/core' | |
67ed6552 | 5 | import { MarkdownService, RestExtractor, ServerService } from '@app/core' |
bd45d503 C |
6 | import { peertubeTranslate } from '@shared/core-utils/i18n' |
7 | import { About } from '@shared/models' | |
d3e56c0c | 8 | import { environment } from '../../../environments/environment' |
d3e56c0c C |
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, | |
421d935d C |
17 | private restExtractor: RestExtractor, |
18 | private markdownService: MarkdownService, | |
19 | private serverService: ServerService | |
d3e56c0c C |
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 | ||
4e9fa5b7 | 28 | contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) { |
d3e56c0c C |
29 | const body = { |
30 | fromEmail, | |
31 | fromName, | |
4e9fa5b7 | 32 | subject, |
d3e56c0c C |
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 | } | |
421d935d C |
40 | |
41 | async buildHtml (about: About) { | |
42 | const html = { | |
43 | description: '', | |
44 | terms: '', | |
45 | codeOfConduct: '', | |
46 | moderationInformation: '', | |
be04c6fd | 47 | administrator: '', |
f45c7cc7 FC |
48 | creationReason: '', |
49 | maintenanceLifetime: '', | |
50 | businessModel: '', | |
be04c6fd | 51 | hardwareInformation: '' |
421d935d C |
52 | } |
53 | ||
be04c6fd | 54 | for (const key of Object.keys(html)) { |
421d935d C |
55 | html[ key ] = await this.markdownService.textMarkdownToHTML(about.instance[ key ]) |
56 | } | |
57 | ||
58 | return html | |
59 | } | |
60 | ||
ba430d75 C |
61 | buildTranslatedLanguages (about: About) { |
62 | return forkJoin([ | |
63 | this.serverService.getVideoLanguages(), | |
64 | this.serverService.getServerLocale() | |
65 | ]).pipe( | |
66 | map(([ languagesArray, translations ]) => { | |
67 | return about.instance.languages | |
68 | .map(l => { | |
69 | const languageObj = languagesArray.find(la => la.id === l) | |
421d935d | 70 | |
ba430d75 C |
71 | return peertubeTranslate(languageObj.label, translations) |
72 | }) | |
73 | }) | |
74 | ) | |
421d935d C |
75 | } |
76 | ||
ba430d75 C |
77 | buildTranslatedCategories (about: About) { |
78 | return forkJoin([ | |
79 | this.serverService.getVideoCategories(), | |
80 | this.serverService.getServerLocale() | |
81 | ]).pipe( | |
82 | map(([ categoriesArray, translations ]) => { | |
83 | return about.instance.categories | |
84 | .map(c => { | |
85 | const categoryObj = categoriesArray.find(ca => ca.id === c) | |
421d935d | 86 | |
ba430d75 C |
87 | return peertubeTranslate(categoryObj.label, translations) |
88 | }) | |
89 | }) | |
90 | ) | |
421d935d | 91 | } |
d3e56c0c | 92 | } |