2019-01-10 05:12:41 -05:00
|
|
|
import { catchError } from 'rxjs/operators'
|
|
|
|
import { HttpClient } from '@angular/common/http'
|
|
|
|
import { Injectable } from '@angular/core'
|
|
|
|
import { environment } from '../../../environments/environment'
|
|
|
|
import { RestExtractor, RestService } from '../rest'
|
|
|
|
import { About } from '../../../../../shared/models/server'
|
2019-08-27 11:09:43 -04:00
|
|
|
import { MarkdownService } from '@app/shared/renderer'
|
|
|
|
import { peertubeTranslate } from '@shared/models'
|
|
|
|
import { ServerService } from '@app/core'
|
2019-01-10 05:12:41 -05:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class InstanceService {
|
|
|
|
private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config'
|
|
|
|
private static BASE_SERVER_URL = environment.apiUrl + '/api/v1/server'
|
|
|
|
|
|
|
|
constructor (
|
|
|
|
private authHttp: HttpClient,
|
|
|
|
private restService: RestService,
|
2019-08-27 11:09:43 -04:00
|
|
|
private restExtractor: RestExtractor,
|
|
|
|
private markdownService: MarkdownService,
|
|
|
|
private serverService: ServerService
|
2019-01-10 05:12:41 -05:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
getAbout () {
|
|
|
|
return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about')
|
|
|
|
.pipe(catchError(res => this.restExtractor.handleError(res)))
|
|
|
|
}
|
|
|
|
|
2019-06-21 02:49:35 -04:00
|
|
|
contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
|
2019-01-10 05:12:41 -05:00
|
|
|
const body = {
|
|
|
|
fromEmail,
|
|
|
|
fromName,
|
2019-06-21 02:49:35 -04:00
|
|
|
subject,
|
2019-01-10 05:12:41 -05:00
|
|
|
body: message
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.authHttp.post(InstanceService.BASE_SERVER_URL + '/contact', body)
|
|
|
|
.pipe(catchError(res => this.restExtractor.handleError(res)))
|
|
|
|
|
|
|
|
}
|
2019-08-27 11:09:43 -04:00
|
|
|
|
|
|
|
async buildHtml (about: About) {
|
|
|
|
const html = {
|
|
|
|
description: '',
|
|
|
|
terms: '',
|
|
|
|
codeOfConduct: '',
|
|
|
|
moderationInformation: '',
|
2019-09-05 03:43:35 -04:00
|
|
|
administrator: '',
|
|
|
|
hardwareInformation: ''
|
2019-08-27 11:09:43 -04:00
|
|
|
}
|
|
|
|
|
2019-09-05 03:43:35 -04:00
|
|
|
for (const key of Object.keys(html)) {
|
2019-08-27 11:09:43 -04:00
|
|
|
html[ key ] = await this.markdownService.textMarkdownToHTML(about.instance[ key ])
|
|
|
|
}
|
|
|
|
|
|
|
|
return html
|
|
|
|
}
|
|
|
|
|
|
|
|
buildTranslatedLanguages (about: About, translations: any) {
|
|
|
|
const languagesArray = this.serverService.getVideoLanguages()
|
|
|
|
|
|
|
|
return about.instance.languages
|
|
|
|
.map(l => {
|
|
|
|
const languageObj = languagesArray.find(la => la.id === l)
|
|
|
|
|
|
|
|
return peertubeTranslate(languageObj.label, translations)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
buildTranslatedCategories (about: About, translations: any) {
|
|
|
|
const categoriesArray = this.serverService.getVideoCategories()
|
|
|
|
|
|
|
|
return about.instance.categories
|
|
|
|
.map(c => {
|
|
|
|
const categoryObj = categoriesArray.find(ca => ca.id === c)
|
|
|
|
|
|
|
|
return peertubeTranslate(categoryObj.label, translations)
|
|
|
|
})
|
|
|
|
}
|
2019-01-10 05:12:41 -05:00
|
|
|
}
|