1 import { forkJoin, of } from 'rxjs'
2 import { catchError, map } from 'rxjs/operators'
3 import { Injectable } from '@angular/core'
4 import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router'
5 import { AccountService } from '../account'
6 import { VideoChannelService } from '../video-channel'
9 export class ActorRedirectGuard implements CanActivate {
12 private router: Router,
13 private accountService: AccountService,
14 private channelService: VideoChannelService
17 canActivate (route: ActivatedRouteSnapshot) {
18 const actorName = route.params.actorName
21 this.accountService.getAccount(actorName).pipe(this.orUndefined()),
22 this.channelService.getVideoChannel(actorName).pipe(this.orUndefined())
24 map(([ account, channel ]) => {
26 return this.router.parseUrl(`/a/${actorName}`)
30 return this.router.parseUrl(`/c/${actorName}`)
33 return this.router.parseUrl('/404')
38 private orUndefined () {
39 return catchError(() => of(undefined))