1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

Add instance banner on login page

This commit is contained in:
Chocobozzz 2024-02-20 14:34:33 +01:00
parent cbfe10a43e
commit 93f9677463
No known key found for this signature in database
GPG key ID: 583A612D890159BE
12 changed files with 116 additions and 66 deletions

View file

@ -1,5 +1,5 @@
import { forkJoin } from 'rxjs'
import { catchError, map } from 'rxjs/operators'
import { forkJoin, of } from 'rxjs'
import { catchError, map, tap } from 'rxjs/operators'
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { MarkdownService, RestExtractor, ServerService } from '@app/core'
@ -18,6 +18,8 @@ export class InstanceService {
private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config'
private static BASE_SERVER_URL = environment.apiUrl + '/api/v1/server'
private instanceBannerUrl: string
constructor (
private authHttp: HttpClient,
private restExtractor: RestExtractor,
@ -28,9 +30,46 @@ export class InstanceService {
getAbout () {
return this.authHttp.get<About>(InstanceService.BASE_CONFIG_URL + '/about')
.pipe(catchError(res => this.restExtractor.handleError(res)))
.pipe(
tap(about => {
const banners = about.instance.banners
if (banners.length !== 0) this.instanceBannerUrl = banners[0].path
}),
catchError(res => this.restExtractor.handleError(res))
)
}
// ---------------------------------------------------------------------------
getInstanceBannerUrl () {
if (this.instanceBannerUrl || this.instanceBannerUrl === null) {
return of(this.instanceBannerUrl)
}
return this.getAbout()
.pipe(map(() => this.instanceBannerUrl))
}
updateInstanceBanner (formData: FormData) {
this.instanceBannerUrl = undefined
const url = InstanceService.BASE_CONFIG_URL + '/instance-banner/pick'
return this.authHttp.post(url, formData)
.pipe(catchError(err => this.restExtractor.handleError(err)))
}
deleteInstanceBanner () {
this.instanceBannerUrl = null
const url = InstanceService.BASE_CONFIG_URL + '/instance-banner'
return this.authHttp.delete(url)
.pipe(catchError(err => this.restExtractor.handleError(err)))
}
// ---------------------------------------------------------------------------
contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {
const body = {
fromEmail,