aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src
diff options
context:
space:
mode:
authorKimsible <kimsible@users.noreply.github.com>2021-05-03 19:03:08 +0200
committerKimsible <kimsible@users.noreply.github.com>2021-05-05 11:48:25 +0200
commit030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2 (patch)
tree447ad863f826f964bcaf9405a5002b45b538c27d /client/src
parent718873964490d1aa31b0e99852002165637e4b9e (diff)
downloadPeerTube-030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2.tar.gz
PeerTube-030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2.tar.zst
PeerTube-030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2.zip
Use userId key to distinct Account or VideoChannel actor
Diffstat (limited to 'client/src')
-rw-r--r--client/src/app/root.component.ts14
-rw-r--r--client/src/app/shared/shared-main/account/actor.service.ts22
2 files changed, 17 insertions, 19 deletions
diff --git a/client/src/app/root.component.ts b/client/src/app/root.component.ts
index ae999e058..5a09e50d1 100644
--- a/client/src/app/root.component.ts
+++ b/client/src/app/root.component.ts
@@ -23,19 +23,21 @@ export class RootComponent implements OnInit {
23 .pipe( 23 .pipe(
24 map(params => params[ 'actorName' ]), 24 map(params => params[ 'actorName' ]),
25 distinctUntilChanged(), 25 distinctUntilChanged(),
26 switchMap(actorName => this.actorService.getActor(actorName)), 26 switchMap(actorName => this.actorService.getActorType(actorName)),
27 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, 'other', [ 27 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, 'other', [
28 HttpStatusCode.BAD_REQUEST_400, 28 HttpStatusCode.BAD_REQUEST_400,
29 HttpStatusCode.NOT_FOUND_404 29 HttpStatusCode.NOT_FOUND_404
30 ])) 30 ]))
31 ) 31 )
32 .subscribe(actor => { 32 .subscribe(actorType => {
33 if (/\/accounts\//.test(actor.url)) { 33 const actorName = this.route.snapshot.params[ 'actorName' ]
34 this.router.navigate([ `/a/${actor.name}` ], { state: { type: 'others', obj: { status: 200 } }, skipLocationChange: true }) 34
35 if (actorType === 'Account') {
36 this.router.navigate([ `/a/${actorName}` ], { state: { type: 'others', obj: { status: 200 } }, skipLocationChange: true })
35 } 37 }
36 38
37 if (/\/video-channels\//.test(actor.url)) { 39 if (actorType === 'VideoChannel') {
38 this.router.navigate([ `/c/${actor.name}` ], { state: { type: 'others', obj: { status: 200 } }, skipLocationChange: true }) 40 this.router.navigate([ `/c/${actorName}` ], { state: { type: 'others', obj: { status: 200 } }, skipLocationChange: true })
39 } 41 }
40 }) 42 })
41 } 43 }
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'
5import { RestExtractor } from '@app/core' 5import { RestExtractor } from '@app/core'
6import { Account as ServerAccount, VideoChannel as ServerVideoChannel } from '@shared/models' 6import { Account as ServerAccount, VideoChannel as ServerVideoChannel } from '@shared/models'
7import { environment } from '../../../../environments/environment' 7import { environment } from '../../../../environments/environment'
8import { Account } from './account.model' 8
9import { VideoChannel } from '../video-channel/video-channel.model' 9type KeysOfUnion<T> = T extends T ? keyof T: never
10type ServerActor = KeysOfUnion<ServerAccount | ServerVideoChannel>
10 11
11@Injectable() 12@Injectable()
12export class ActorService { 13export class ActorService {
13 static BASE_ACTOR_API_URL = environment.apiUrl + '/api/v1/actors/' 14 static BASE_ACTOR_API_URL = environment.apiUrl + '/api/v1/actors/'
14 15
15 actorLoaded = new ReplaySubject<Account | VideoChannel>(1) 16 actorLoaded = new ReplaySubject<string>(1)
16 17
17 constructor ( 18 constructor (
18 private authHttp: HttpClient, 19 private authHttp: HttpClient,
19 private restExtractor: RestExtractor 20 private restExtractor: RestExtractor
20 ) {} 21 ) {}
21 22
22 getActor (actorName: string): Observable<Account | VideoChannel> { 23 getActorType (actorName: string): Observable<string> {
23 return this.authHttp.get<ServerAccount | ServerVideoChannel>(ActorService.BASE_ACTOR_API_URL + actorName) 24 return this.authHttp.get<ServerActor>(ActorService.BASE_ACTOR_API_URL + actorName)
24 .pipe( 25 .pipe(
25 map(actorHash => { 26 map(actorHash => {
26 const isAccount = /\/accounts\/.+/.test(actorHash.url) 27 if (actorHash[ 'userId' ]) {
27 const isVideoChannel = /\/video-channels\/.+/.test(actorHash.url) 28 return 'Account'
28
29 if (isAccount) {
30 return new Account(actorHash)
31 } 29 }
32 30
33 if (isVideoChannel) { 31 return 'VideoChannel'
34 return new VideoChannel(actorHash)
35 }
36 }), 32 }),
37 tap(actor => this.actorLoaded.next(actor)), 33 tap(actor => this.actorLoaded.next(actor)),
38 catchError(res => this.restExtractor.handleError(res)) 34 catchError(res => this.restExtractor.handleError(res))