]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/router/actor-redirect-guard.service.ts
Update angular
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / router / actor-redirect-guard.service.ts
CommitLineData
012580d9
C
1import { forkJoin, of } from 'rxjs'
2import { catchError, map } from 'rxjs/operators'
3import { Injectable } from '@angular/core'
52798aa5 4import { ActivatedRouteSnapshot, Router } from '@angular/router'
012580d9
C
5import { AccountService } from '../account'
6import { VideoChannelService } from '../video-channel'
7
8@Injectable()
52798aa5 9export class ActorRedirectGuard {
012580d9
C
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 ]) => {
012580d9 25 if (account) {
698a8c65 26 return this.router.parseUrl(`/a/${actorName}`)
012580d9
C
27 }
28
29 if (channel) {
698a8c65 30 return this.router.parseUrl(`/c/${actorName}`)
012580d9
C
31 }
32
698a8c65 33 return this.router.parseUrl('/404')
012580d9
C
34 })
35 )
36 }
37
38 private orUndefined () {
39 return catchError(() => of(undefined))
40 }
41}