]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/instance/instance.service.ts
add channel avatar to watch view
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / instance / instance.service.ts
CommitLineData
d3e56c0c
C
1import { catchError } from 'rxjs/operators'
2import { HttpClient } from '@angular/common/http'
3import { Injectable } from '@angular/core'
4import { environment } from '../../../environments/environment'
5import { RestExtractor, RestService } from '../rest'
6import { About } from '../../../../../shared/models/server'
421d935d
C
7import { MarkdownService } from '@app/shared/renderer'
8import { peertubeTranslate } from '@shared/models'
9import { ServerService } from '@app/core'
d3e56c0c
C
10
11@Injectable()
12export 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,
421d935d
C
19 private restExtractor: RestExtractor,
20 private markdownService: MarkdownService,
21 private serverService: ServerService
d3e56c0c
C
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
4e9fa5b7 30 contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
d3e56c0c
C
31 const body = {
32 fromEmail,
33 fromName,
4e9fa5b7 34 subject,
d3e56c0c
C
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 }
421d935d
C
42
43 async buildHtml (about: About) {
44 const html = {
45 description: '',
46 terms: '',
47 codeOfConduct: '',
48 moderationInformation: '',
be04c6fd
C
49 administrator: '',
50 hardwareInformation: ''
421d935d
C
51 }
52
be04c6fd 53 for (const key of Object.keys(html)) {
421d935d
C
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 }
d3e56c0c 81}