1 import { Component, OnInit } from '@angular/core'
2 import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
3 import { ActivatedRoute, Router } from '@angular/router'
4 import { RestExtractor } from '@app/core'
5 import { ActorService } from '@app/shared/shared-main/account'
6 import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
12 export class RootComponent implements OnInit {
14 private actorService: ActorService,
15 private route: ActivatedRoute,
16 private restExtractor: RestExtractor,
17 private router: Router
24 map(params => params[ 'actorName' ]),
25 distinctUntilChanged(),
26 switchMap(actorName => this.actorService.getActor(actorName)),
27 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, 'other', [
28 HttpStatusCode.BAD_REQUEST_400,
29 HttpStatusCode.NOT_FOUND_404
33 if (/\/accounts\//.test(actor.url)) {
34 this.router.navigate([ `/a/${actor.name}` ], { state: { type: 'others', obj: { status: 200 } }, skipLocationChange: true })
37 if (/\/video-channels\//.test(actor.url)) {
38 this.router.navigate([ `/c/${actor.name}` ], { state: { type: 'others', obj: { status: 200 } }, skipLocationChange: true })