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