]>
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 C |
5 | import { MarkdownService, RestExtractor, ServerService } from '@app/core' |
6 | import { About, peertubeTranslate } from '@shared/models' | |
d3e56c0c | 7 | import { environment } from '../../../environments/environment' |
d3e56c0c C |
8 | |
9 | @Injectable() | |
10 | export class InstanceService { | |
11 | private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config' | |
12 | private static BASE_SERVER_URL = environment.apiUrl + '/api/v1/server' | |
13 | ||
14 | constructor ( | |
15 | private authHttp: HttpClient, | |
421d935d C |
16 | private restExtractor: RestExtractor, |
17 | private markdownService: MarkdownService, | |
18 | private serverService: ServerService | |
d3e56c0c C |
19 | ) { |
20 | } | |
21 | ||
22 | getAbout () { | |
23 | return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about') | |
24 | .pipe(catchError(res => this.restExtractor.handleError(res))) | |
25 | } | |
26 | ||
4e9fa5b7 | 27 | contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) { |
d3e56c0c C |
28 | const body = { |
29 | fromEmail, | |
30 | fromName, | |
4e9fa5b7 | 31 | subject, |
d3e56c0c C |
32 | body: message |
33 | } | |
34 | ||
35 | return this.authHttp.post(InstanceService.BASE_SERVER_URL + '/contact', body) | |
36 | .pipe(catchError(res => this.restExtractor.handleError(res))) | |
37 | ||
38 | } | |
421d935d C |
39 | |
40 | async buildHtml (about: About) { | |
41 | const html = { | |
42 | description: '', | |
43 | terms: '', | |
44 | codeOfConduct: '', | |
45 | moderationInformation: '', | |
be04c6fd C |
46 | administrator: '', |
47 | hardwareInformation: '' | |
421d935d C |
48 | } |
49 | ||
be04c6fd | 50 | for (const key of Object.keys(html)) { |
421d935d C |
51 | html[ key ] = await this.markdownService.textMarkdownToHTML(about.instance[ key ]) |
52 | } | |
53 | ||
54 | return html | |
55 | } | |
56 | ||
ba430d75 C |
57 | buildTranslatedLanguages (about: About) { |
58 | return forkJoin([ | |
59 | this.serverService.getVideoLanguages(), | |
60 | this.serverService.getServerLocale() | |
61 | ]).pipe( | |
62 | map(([ languagesArray, translations ]) => { | |
63 | return about.instance.languages | |
64 | .map(l => { | |
65 | const languageObj = languagesArray.find(la => la.id === l) | |
421d935d | 66 | |
ba430d75 C |
67 | return peertubeTranslate(languageObj.label, translations) |
68 | }) | |
69 | }) | |
70 | ) | |
421d935d C |
71 | } |
72 | ||
ba430d75 C |
73 | buildTranslatedCategories (about: About) { |
74 | return forkJoin([ | |
75 | this.serverService.getVideoCategories(), | |
76 | this.serverService.getServerLocale() | |
77 | ]).pipe( | |
78 | map(([ categoriesArray, translations ]) => { | |
79 | return about.instance.categories | |
80 | .map(c => { | |
81 | const categoryObj = categoriesArray.find(ca => ca.id === c) | |
421d935d | 82 | |
ba430d75 C |
83 | return peertubeTranslate(categoryObj.label, translations) |
84 | }) | |
85 | }) | |
86 | ) | |
421d935d | 87 | } |
d3e56c0c | 88 | } |