mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 17:59:37 +02:00
Reorganize client shared modules
This commit is contained in:
parent
0c4bacbff5
commit
67ed6552b8
510 changed files with 2321 additions and 2251 deletions
88
client/src/app/shared/shared-instance/instance.service.ts
Normal file
88
client/src/app/shared/shared-instance/instance.service.ts
Normal file
|
@ -0,0 +1,88 @@
|
|||
import { forkJoin } from 'rxjs'
|
||||
import { catchError, map } from 'rxjs/operators'
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { MarkdownService, RestExtractor, ServerService } from '@app/core'
|
||||
import { About, peertubeTranslate } from '@shared/models'
|
||||
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,
|
||||
private restExtractor: RestExtractor,
|
||||
private markdownService: MarkdownService,
|
||||
private serverService: ServerService
|
||||
) {
|
||||
}
|
||||
|
||||
getAbout () {
|
||||
return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about')
|
||||
.pipe(catchError(res => this.restExtractor.handleError(res)))
|
||||
}
|
||||
|
||||
contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
|
||||
const body = {
|
||||
fromEmail,
|
||||
fromName,
|
||||
subject,
|
||||
body: message
|
||||
}
|
||||
|
||||
return this.authHttp.post(InstanceService.BASE_SERVER_URL + '/contact', body)
|
||||
.pipe(catchError(res => this.restExtractor.handleError(res)))
|
||||
|
||||
}
|
||||
|
||||
async buildHtml (about: About) {
|
||||
const html = {
|
||||
description: '',
|
||||
terms: '',
|
||||
codeOfConduct: '',
|
||||
moderationInformation: '',
|
||||
administrator: '',
|
||||
hardwareInformation: ''
|
||||
}
|
||||
|
||||
for (const key of Object.keys(html)) {
|
||||
html[ key ] = await this.markdownService.textMarkdownToHTML(about.instance[ key ])
|
||||
}
|
||||
|
||||
return html
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
return peertubeTranslate(languageObj.label, translations)
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
return peertubeTranslate(categoryObj.label, translations)
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue