diff options
Diffstat (limited to 'client/src/app/shared/shared-main')
-rw-r--r-- | client/src/app/shared/shared-main/account/actor.service.ts | 41 | ||||
-rw-r--r-- | client/src/app/shared/shared-main/account/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/shared/shared-main/shared-main.module.ts | 3 |
3 files changed, 44 insertions, 1 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 @@ | |||
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' | ||
10 | |||
11 | @Injectable() | ||
12 | export 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 @@ | |||
1 | export * from './account.model' | 1 | export * from './account.model' |
2 | export * from './account.service' | 2 | export * from './account.service' |
3 | export * from './actor.model' | 3 | export * from './actor.model' |
4 | export * from './actor.service' | ||
diff --git a/client/src/app/shared/shared-main/shared-main.module.ts b/client/src/app/shared/shared-main/shared-main.module.ts index 772198cb2..05a5d77c7 100644 --- a/client/src/app/shared/shared-main/shared-main.module.ts +++ b/client/src/app/shared/shared-main/shared-main.module.ts | |||
@@ -17,7 +17,7 @@ import { | |||
17 | import { LoadingBarModule } from '@ngx-loading-bar/core' | 17 | import { LoadingBarModule } from '@ngx-loading-bar/core' |
18 | import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client' | 18 | import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client' |
19 | import { SharedGlobalIconModule } from '../shared-icons' | 19 | import { SharedGlobalIconModule } from '../shared-icons' |
20 | import { AccountService } from './account' | 20 | import { AccountService, ActorService } from './account' |
21 | import { | 21 | import { |
22 | AutofocusDirective, | 22 | AutofocusDirective, |
23 | BytesPipe, | 23 | BytesPipe, |
@@ -160,6 +160,7 @@ import { VideoChannelService } from './video-channel' | |||
160 | AUTH_INTERCEPTOR_PROVIDER, | 160 | AUTH_INTERCEPTOR_PROVIDER, |
161 | 161 | ||
162 | AccountService, | 162 | AccountService, |
163 | ActorService, | ||
163 | 164 | ||
164 | UserHistoryService, | 165 | UserHistoryService, |
165 | UserNotificationService, | 166 | UserNotificationService, |