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