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