aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main/account
diff options
context:
space:
mode:
authorKimsible <kimsible@users.noreply.github.com>2021-04-28 22:17:02 +0200
committerKimsible <kimsible@users.noreply.github.com>2021-05-05 11:47:03 +0200
commit69e076ddb0deda9e4120bab095d3369bb19fbd1e (patch)
tree6576a6293b9e76ce385813f62376e15a7e05001f /client/src/app/shared/shared-main/account
parent08ac081b37cd6115634e8951608116fe0f13032b (diff)
downloadPeerTube-69e076ddb0deda9e4120bab095d3369bb19fbd1e.tar.gz
PeerTube-69e076ddb0deda9e4120bab095d3369bb19fbd1e.tar.zst
PeerTube-69e076ddb0deda9e4120bab095d3369bb19fbd1e.zip
Refactor client @actorName matcher with new API route
Diffstat (limited to 'client/src/app/shared/shared-main/account')
-rw-r--r--client/src/app/shared/shared-main/account/actor.service.ts41
-rw-r--r--client/src/app/shared/shared-main/account/index.ts1
2 files changed, 42 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-main/account/actor.service.ts b/client/src/app/shared/shared-main/account/actor.service.ts
new file mode 100644
index 000000000..a789b6f5b
--- /dev/null
+++ b/client/src/app/shared/shared-main/account/actor.service.ts
@@ -0,0 +1,41 @@
1import { Observable, ReplaySubject } from 'rxjs'
2import { catchError, map, tap } from 'rxjs/operators'
3import { HttpClient } from '@angular/common/http'
4import { Injectable } from '@angular/core'
5import { RestExtractor } from '@app/core'
6import { Account as ServerAccount, VideoChannel as ServerVideoChannel } from '@shared/models'
7import { environment } from '../../../../environments/environment'
8import { Account } from './account.model'
9import { VideoChannel } from '../video-channel/video-channel.model'
10
11@Injectable()
12export class ActorService {
13 static BASE_ACTOR_API_URL = environment.apiUrl + '/api/v1/actors/'
14
15 actorLoaded = new ReplaySubject<Account | VideoChannel>(1)
16
17 constructor (
18 private authHttp: HttpClient,
19 private restExtractor: RestExtractor
20 ) {}
21
22 getActor (actorName: string): Observable<Account | VideoChannel> {
23 return this.authHttp.get<ServerAccount | ServerVideoChannel>(ActorService.BASE_ACTOR_API_URL + actorName)
24 .pipe(
25 map(actorHash => {
26 const isAccount = /\/accounts\/.+/.test(actorHash.url)
27 const isVideoChannel = /\/video-channels\/.+/.test(actorHash.url)
28
29 if (isAccount) {
30 return new Account(actorHash)
31 }
32
33 if (isVideoChannel) {
34 return new VideoChannel(actorHash)
35 }
36 }),
37 tap(actor => this.actorLoaded.next(actor)),
38 catchError(res => this.restExtractor.handleError(res))
39 )
40 }
41}
diff --git a/client/src/app/shared/shared-main/account/index.ts b/client/src/app/shared/shared-main/account/index.ts
index b80ddb9f5..c6cdcd574 100644
--- a/client/src/app/shared/shared-main/account/index.ts
+++ b/client/src/app/shared/shared-main/account/index.ts
@@ -1,3 +1,4 @@
1export * from './account.model' 1export * from './account.model'
2export * from './account.service' 2export * from './account.service'
3export * from './actor.model' 3export * from './actor.model'
4export * from './actor.service'