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