X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-main%2Faccount%2Factor.service.ts;h=464ed45195507e412e207426a6a761d2bfd31133;hb=8f608a4cb22ab232cfab20665050764b38bac9c7;hp=a789b6f5b363f0eb81115814c0ab3d128e191a49;hpb=69e076ddb0deda9e4120bab095d3369bb19fbd1e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-main/account/actor.service.ts b/client/src/app/shared/shared-main/account/actor.service.ts index a789b6f5b..464ed4519 100644 --- a/client/src/app/shared/shared-main/account/actor.service.ts +++ b/client/src/app/shared/shared-main/account/actor.service.ts @@ -5,34 +5,30 @@ import { Injectable } from '@angular/core' import { RestExtractor } from '@app/core' import { Account as ServerAccount, VideoChannel as ServerVideoChannel } from '@shared/models' import { environment } from '../../../../environments/environment' -import { Account } from './account.model' -import { VideoChannel } from '../video-channel/video-channel.model' + +type KeysOfUnion = T extends T ? keyof T: never +type ServerActor = KeysOfUnion @Injectable() export class ActorService { static BASE_ACTOR_API_URL = environment.apiUrl + '/api/v1/actors/' - actorLoaded = new ReplaySubject(1) + actorLoaded = new ReplaySubject(1) constructor ( private authHttp: HttpClient, private restExtractor: RestExtractor ) {} - getActor (actorName: string): Observable { - return this.authHttp.get(ActorService.BASE_ACTOR_API_URL + actorName) + getActorType (actorName: string): Observable { + return this.authHttp.get(ActorService.BASE_ACTOR_API_URL + actorName) .pipe( map(actorHash => { - const isAccount = /\/accounts\/.+/.test(actorHash.url) - const isVideoChannel = /\/video-channels\/.+/.test(actorHash.url) - - if (isAccount) { - return new Account(actorHash) + if (actorHash[ 'userId' ]) { + return 'Account' } - if (isVideoChannel) { - return new VideoChannel(actorHash) - } + return 'VideoChannel' }), tap(actor => this.actorLoaded.next(actor)), catchError(res => this.restExtractor.handleError(res))