aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main/custom-page/custom-page.service.ts
blob: 6a2d3a1f5ff2afb1f746fd7839ef7a52d20b5b80 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { of } from 'rxjs'
import { catchError } from 'rxjs/operators'
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { RestExtractor } from '@app/core'
import { CustomPage } from '@peertube/peertube-models'
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 })
      .pipe(catchError(err => this.restExtractor.handleError(err)))
  }
}