2020-06-23 08:10:17 -04:00
|
|
|
import { forkJoin } from 'rxjs'
|
2019-12-18 09:31:54 -05:00
|
|
|
import { catchError, map } from 'rxjs/operators'
|
2019-01-10 05:12:41 -05:00
|
|
|
import { HttpClient } from '@angular/common/http'
|
|
|
|
import { Injectable } from '@angular/core'
|
2020-06-23 08:10:17 -04:00
|
|
|
import { MarkdownService, RestExtractor, ServerService } from '@app/core'
|
2020-08-06 08:58:01 -04:00
|
|
|
import { peertubeTranslate } from '@shared/core-utils/i18n'
|
|
|
|
import { About } from '@shared/models'
|
2019-01-10 05:12:41 -05:00
|
|
|
import { environment } from '../../../environments/environment'
|
|
|
|
|
2023-01-19 08:52:27 -05:00
|
|
|
export type AboutHTML = Pick<About['instance'],
|
|
|
|
'terms' | 'codeOfConduct' | 'moderationInformation' | 'administrator' | 'creationReason' |
|
|
|
|
'maintenanceLifetime' | 'businessModel' | 'hardwareInformation'
|
|
|
|
>
|
|
|
|
|
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,
|
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) {
|
2023-01-19 08:52:27 -05:00
|
|
|
const html: AboutHTML = {
|
2019-08-27 11:09:43 -04:00
|
|
|
terms: '',
|
|
|
|
codeOfConduct: '',
|
|
|
|
moderationInformation: '',
|
2019-09-05 03:43:35 -04:00
|
|
|
administrator: '',
|
2020-11-30 09:05:57 -05:00
|
|
|
creationReason: '',
|
|
|
|
maintenanceLifetime: '',
|
|
|
|
businessModel: '',
|
2019-09-05 03:43:35 -04:00
|
|
|
hardwareInformation: ''
|
2019-08-27 11:09:43 -04:00
|
|
|
}
|
|
|
|
|
2019-09-05 03:43:35 -04:00
|
|
|
for (const key of Object.keys(html)) {
|
2022-11-14 04:47:39 -05:00
|
|
|
html[key] = await this.markdownService.textMarkdownToHTML({ markdown: about.instance[key] })
|
2019-08-27 11:09:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return html
|
|
|
|
}
|
|
|
|
|
2019-12-18 09:31:54 -05: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 11:09:43 -04:00
|
|
|
|
2019-12-18 09:31:54 -05:00
|
|
|
return peertubeTranslate(languageObj.label, translations)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)
|
2019-08-27 11:09:43 -04:00
|
|
|
}
|
|
|
|
|
2019-12-18 09:31:54 -05: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 11:09:43 -04:00
|
|
|
|
2019-12-18 09:31:54 -05:00
|
|
|
return peertubeTranslate(categoryObj.label, translations)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)
|
2019-08-27 11:09:43 -04:00
|
|
|
}
|
2019-01-10 05:12:41 -05:00
|
|
|
}
|