]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/follows/shared/follow.service.ts
Basic video redundancy implementation
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / shared / follow.service.ts
CommitLineData
db400f44 1import { catchError, map } from 'rxjs/operators'
8a02bd04 2import { HttpClient, HttpParams } from '@angular/common/http'
63c4db6d
C
3import { Injectable } from '@angular/core'
4import { SortMeta } from 'primeng/primeng'
db400f44 5import { Observable } from 'rxjs'
c48e82b5 6import { ActorFollow, ResultList } from '../../../../../../shared'
63c4db6d
C
7import { environment } from '../../../../environments/environment'
8import { RestExtractor, RestPagination, RestService } from '../../../shared'
e2f555ca
C
9
10@Injectable()
51548b31 11export class FollowService {
63c4db6d 12 private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/server'
e2f555ca
C
13
14 constructor (
d592e0a9 15 private authHttp: HttpClient,
8a02bd04 16 private restService: RestService,
de59c48f 17 private restExtractor: RestExtractor
db400f44
C
18 ) {
19 }
e2f555ca 20
c48e82b5 21 getFollowing (pagination: RestPagination, sort: SortMeta): Observable<ResultList<ActorFollow>> {
8a02bd04
C
22 let params = new HttpParams()
23 params = this.restService.addRestGetParams(params, pagination, sort)
24
c48e82b5 25 return this.authHttp.get<ResultList<ActorFollow>>(FollowService.BASE_APPLICATION_URL + '/following', { params })
db400f44
C
26 .pipe(
27 map(res => this.restExtractor.convertResultListDateToHuman(res)),
28 catchError(res => this.restExtractor.handleError(res))
29 )
e2f555ca
C
30 }
31
c48e82b5 32 getFollowers (pagination: RestPagination, sort: SortMeta): Observable<ResultList<ActorFollow>> {
51548b31
C
33 let params = new HttpParams()
34 params = this.restService.addRestGetParams(params, pagination, sort)
35
c48e82b5 36 return this.authHttp.get<ResultList<ActorFollow>>(FollowService.BASE_APPLICATION_URL + '/followers', { params })
db400f44
C
37 .pipe(
38 map(res => this.restExtractor.convertResultListDateToHuman(res)),
39 catchError(res => this.restExtractor.handleError(res))
40 )
51548b31
C
41 }
42
7e9334c3 43 follow (notEmptyHosts: string[]) {
e105c19c 44 const body = {
49abbbbe 45 hosts: notEmptyHosts
df98563e 46 }
e105c19c 47
9a27cdc2 48 return this.authHttp.post(FollowService.BASE_APPLICATION_URL + '/following', body)
db400f44
C
49 .pipe(
50 map(this.restExtractor.extractDataBool),
51 catchError(res => this.restExtractor.handleError(res))
52 )
d5f5a670 53 }
7e9334c3 54
c48e82b5 55 unfollow (follow: ActorFollow) {
39fdb3c0 56 return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.host)
db400f44
C
57 .pipe(
58 map(this.restExtractor.extractDataBool),
59 catchError(res => this.restExtractor.handleError(res))
60 )
7e9334c3 61 }
e2f555ca 62}