1 import { Observable, ReplaySubject } from 'rxjs'
2 import { catchError, map, tap } from 'rxjs/operators'
3 import { HttpClient } from '@angular/common/http'
4 import { Injectable } from '@angular/core'
5 import { RestExtractor } from '@app/core'
6 import { Account as ServerAccount, VideoChannel as ServerVideoChannel } from '@shared/models'
7 import { environment } from '../../../../environments/environment'
8 import { Account } from './account.model'
9 import { VideoChannel } from '../video-channel/video-channel.model'
12 export class ActorService {
13 static BASE_ACTOR_API_URL = environment.apiUrl + '/api/v1/actors/'
15 actorLoaded = new ReplaySubject<Account | VideoChannel>(1)
18 private authHttp: HttpClient,
19 private restExtractor: RestExtractor
22 getActor (actorName: string): Observable<Account | VideoChannel> {
23 return this.authHttp.get<ServerAccount | ServerVideoChannel>(ActorService.BASE_ACTOR_API_URL + actorName)
26 const isAccount = /\/accounts\/.+/.test(actorHash.url)
27 const isVideoChannel = /\/video-channels\/.+/.test(actorHash.url)
30 return new Account(actorHash)
34 return new VideoChannel(actorHash)
37 tap(actor => this.actorLoaded.next(actor)),
38 catchError(res => this.restExtractor.handleError(res))