2021-05-27 15:59:55 +02:00
|
|
|
import { of } from 'rxjs'
|
2022-01-18 11:37:29 +01:00
|
|
|
import { catchError } from 'rxjs/operators'
|
2021-05-27 15:59:55 +02:00
|
|
|
import { HttpClient } from '@angular/common/http'
|
|
|
|
import { Injectable } from '@angular/core'
|
|
|
|
import { RestExtractor } from '@app/core'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { CustomPage } from '@peertube/peertube-models'
|
2021-05-27 15:59:55 +02:00
|
|
|
import { environment } from '../../../../environments/environment'
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class CustomPageService {
|
|
|
|
static BASE_INSTANCE_HOMEPAGE_URL = environment.apiUrl + '/api/v1/custom-pages/homepage/instance'
|
|
|
|
|
|
|
|
constructor (
|
|
|
|
private authHttp: HttpClient,
|
|
|
|
private restExtractor: RestExtractor
|
|
|
|
) { }
|
|
|
|
|
|
|
|
getInstanceHomepage () {
|
|
|
|
return this.authHttp.get<CustomPage>(CustomPageService.BASE_INSTANCE_HOMEPAGE_URL)
|
|
|
|
.pipe(
|
|
|
|
catchError(err => {
|
|
|
|
if (err.status === 404) {
|
|
|
|
return of({ content: '' })
|
|
|
|
}
|
|
|
|
|
|
|
|
this.restExtractor.handleError(err)
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
updateInstanceHomepage (content: string) {
|
|
|
|
return this.authHttp.put(CustomPageService.BASE_INSTANCE_HOMEPAGE_URL, { content })
|
2022-01-18 11:37:29 +01:00
|
|
|
.pipe(catchError(err => this.restExtractor.handleError(err)))
|
2021-05-27 15:59:55 +02:00
|
|
|
}
|
|
|
|
}
|