2020-06-23 12:10:17 +00:00
|
|
|
import { forkJoin } from 'rxjs'
|
2019-12-18 14:31:54 +00:00
|
|
|
import { catchError, map } from 'rxjs/operators'
|
2019-01-10 10:12:41 +00:00
|
|
|
import { HttpClient } from '@angular/common/http'
|
|
|
|
import { Injectable } from '@angular/core'
|
2020-06-23 12:10:17 +00:00
|
|
|
import { MarkdownService, RestExtractor, ServerService } from '@app/core'
|
2020-08-06 12:58:01 +00:00
|
|
|
import { peertubeTranslate } from '@shared/core-utils/i18n'
|
|
|
|
import { About } from '@shared/models'
|
2019-01-10 10:12:41 +00:00
|
|
|
import { environment } from '../../../environments/environment'
|
|
|
|
|
|
|
|
@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,
|
2019-08-27 15:09:43 +00:00
|
|
|
private restExtractor: RestExtractor,
|
|
|
|
private markdownService: MarkdownService,
|
|
|
|
private serverService: ServerService
|
2019-01-10 10:12:41 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
getAbout () {
|
|
|
|
return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about')
|
|
|
|
.pipe(catchError(res => this.restExtractor.handleError(res)))
|
|
|
|
}
|
|
|
|
|
2019-06-21 06:49:35 +00:00
|
|
|
contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
|
2019-01-10 10:12:41 +00:00
|
|
|
const body = {
|
|
|
|
fromEmail,
|
|
|
|
fromName,
|
2019-06-21 06:49:35 +00:00
|
|
|
subject,
|
2019-01-10 10:12:41 +00:00
|
|
|
body: message
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.authHttp.post(InstanceService.BASE_SERVER_URL + '/contact', body)
|
|
|
|
.pipe(catchError(res => this.restExtractor.handleError(res)))
|
|
|
|
|
|
|
|
}
|
2019-08-27 15:09:43 +00:00
|
|
|
|
|
|
|
async buildHtml (about: About) {
|
|
|
|
const html = {
|
|
|
|
terms: '',
|
|
|
|
codeOfConduct: '',
|
|
|
|
moderationInformation: '',
|
2019-09-05 07:43:35 +00:00
|
|
|
administrator: '',
|
2020-11-30 14:05:57 +00:00
|
|
|
creationReason: '',
|
|
|
|
maintenanceLifetime: '',
|
|
|
|
businessModel: '',
|
2019-09-05 07:43:35 +00:00
|
|
|
hardwareInformation: ''
|
2019-08-27 15:09:43 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 07:43:35 +00:00
|
|
|
for (const key of Object.keys(html)) {
|
2022-11-14 09:47:39 +00:00
|
|
|
html[key] = await this.markdownService.textMarkdownToHTML({ markdown: about.instance[key] })
|
2019-08-27 15:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return html
|
|
|
|
}
|
|
|
|
|
2019-12-18 14:31:54 +00:00
|
|
|
buildTranslatedLanguages (about: About) {
|
|
|
|
return forkJoin([
|
|
|
|
this.serverService.getVideoLanguages(),
|
|
|
|
this.serverService.getServerLocale()
|
|
|
|
]).pipe(
|
|
|
|
map(([ languagesArray, translations ]) => {
|
|
|
|
return about.instance.languages
|
|
|
|
.map(l => {
|
|
|
|
const languageObj = languagesArray.find(la => la.id === l)
|
2019-08-27 15:09:43 +00:00
|
|
|
|
2019-12-18 14:31:54 +00:00
|
|
|
return peertubeTranslate(languageObj.label, translations)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)
|
2019-08-27 15:09:43 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 14:31:54 +00:00
|
|
|
buildTranslatedCategories (about: About) {
|
|
|
|
return forkJoin([
|
|
|
|
this.serverService.getVideoCategories(),
|
|
|
|
this.serverService.getServerLocale()
|
|
|
|
]).pipe(
|
|
|
|
map(([ categoriesArray, translations ]) => {
|
|
|
|
return about.instance.categories
|
|
|
|
.map(c => {
|
|
|
|
const categoryObj = categoriesArray.find(ca => ca.id === c)
|
2019-08-27 15:09:43 +00:00
|
|
|
|
2019-12-18 14:31:54 +00:00
|
|
|
return peertubeTranslate(categoryObj.label, translations)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)
|
2019-08-27 15:09:43 +00:00
|
|
|
}
|
2019-01-10 10:12:41 +00:00
|
|
|
}
|