aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main/router
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-05-28 10:21:39 +0200
committerChocobozzz <me@florianbigard.com>2021-05-28 10:22:50 +0200
commit012580d98f489e599d44a9a2a0bdc892b9455a90 (patch)
treecd6d4abdbf43f4cd1c051ac49682b97c7b6dca92 /client/src/app/shared/shared-main/router
parentd6d96bed80700830063c6055969d2d2ff46c63c6 (diff)
downloadPeerTube-012580d98f489e599d44a9a2a0bdc892b9455a90.tar.gz
PeerTube-012580d98f489e599d44a9a2a0bdc892b9455a90.tar.zst
PeerTube-012580d98f489e599d44a9a2a0bdc892b9455a90.zip
Cleanup
We must not expose private actor objects to clients Just make 2 GET requests on channel/accounts instead
Diffstat (limited to 'client/src/app/shared/shared-main/router')
-rw-r--r--client/src/app/shared/shared-main/router/actor-redirect-guard.service.ts46
-rw-r--r--client/src/app/shared/shared-main/router/index.ts1
2 files changed, 47 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-main/router/actor-redirect-guard.service.ts b/client/src/app/shared/shared-main/router/actor-redirect-guard.service.ts
new file mode 100644
index 000000000..49d61f945
--- /dev/null
+++ b/client/src/app/shared/shared-main/router/actor-redirect-guard.service.ts
@@ -0,0 +1,46 @@
1import { forkJoin, of } from 'rxjs'
2import { catchError, map } from 'rxjs/operators'
3import { Injectable } from '@angular/core'
4import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router'
5import { AccountService } from '../account'
6import { VideoChannelService } from '../video-channel'
7
8@Injectable()
9export class ActorRedirectGuard implements CanActivate {
10
11 constructor (
12 private router: Router,
13 private accountService: AccountService,
14 private channelService: VideoChannelService
15 ) {}
16
17 canActivate (route: ActivatedRouteSnapshot) {
18 const actorName = route.params.actorName
19
20 return forkJoin([
21 this.accountService.getAccount(actorName).pipe(this.orUndefined()),
22 this.channelService.getVideoChannel(actorName).pipe(this.orUndefined())
23 ]).pipe(
24 map(([ account, channel ]) => {
25 if (!account && !channel) {
26 this.router.navigate([ '/404' ])
27 return false
28 }
29
30 if (account) {
31 this.router.navigate([ `/a/${actorName}` ], { skipLocationChange: true })
32 }
33
34 if (channel) {
35 this.router.navigate([ `/c/${actorName}` ], { skipLocationChange: true })
36 }
37
38 return true
39 })
40 )
41 }
42
43 private orUndefined () {
44 return catchError(() => of(undefined))
45 }
46}
diff --git a/client/src/app/shared/shared-main/router/index.ts b/client/src/app/shared/shared-main/router/index.ts
new file mode 100644
index 000000000..f4000b674
--- /dev/null
+++ b/client/src/app/shared/shared-main/router/index.ts
@@ -0,0 +1 @@
export * from './actor-redirect-guard.service'