diff options
author | Kimsible <kimsible@users.noreply.github.com> | 2021-04-24 01:51:11 +0200 |
---|---|---|
committer | Kimsible <kimsible@users.noreply.github.com> | 2021-05-05 11:47:03 +0200 |
commit | ff8c5ccf09cfe6a469777d4789625f8fdb004408 (patch) | |
tree | 9cf2ecf8b648afb354c20548b72d3e73927896d3 /client/src/app | |
parent | 9a911038d9ac38bf590e9199b3b7477ebf91de19 (diff) | |
download | PeerTube-ff8c5ccf09cfe6a469777d4789625f8fdb004408.tar.gz PeerTube-ff8c5ccf09cfe6a469777d4789625f8fdb004408.tar.zst PeerTube-ff8c5ccf09cfe6a469777d4789625f8fdb004408.zip |
Add shorter URLs for accounts and channels client-side
Diffstat (limited to 'client/src/app')
-rw-r--r-- | client/src/app/+actors/actors.component.ts | 41 | ||||
-rw-r--r-- | client/src/app/app-routing.module.ts | 13 |
2 files changed, 54 insertions, 0 deletions
diff --git a/client/src/app/+actors/actors.component.ts b/client/src/app/+actors/actors.component.ts new file mode 100644 index 000000000..74fbe7dea --- /dev/null +++ b/client/src/app/+actors/actors.component.ts | |||
@@ -0,0 +1,41 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { empty } from 'rxjs' | ||
3 | import { catchError } from 'rxjs/operators' | ||
4 | import { RestExtractor } from '@app/core' | ||
5 | |||
6 | import { ActivatedRoute, Router } from '@angular/router' | ||
7 | import { AccountService } from '@app/shared/shared-main/account' | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-actor', | ||
11 | template: '' | ||
12 | }) | ||
13 | export class ActorsComponent implements OnInit { | ||
14 | constructor ( | ||
15 | private accountService: AccountService, | ||
16 | private route: ActivatedRoute, | ||
17 | private restExtractor: RestExtractor, | ||
18 | private router: Router | ||
19 | ) { | ||
20 | } | ||
21 | |||
22 | ngOnInit () { | ||
23 | const accountOrChannelName = this.route.snapshot.params['actorName'].replace('@', '') | ||
24 | |||
25 | this.accountService | ||
26 | .getAccount(accountOrChannelName) | ||
27 | .pipe( | ||
28 | catchError(res => { | ||
29 | if (res.status === 404 && res.message === 'Account not found') { | ||
30 | this.router.navigateByUrl(`/video-channels/${accountOrChannelName}`) | ||
31 | return empty() | ||
32 | } | ||
33 | |||
34 | return this.restExtractor.handleError(res) | ||
35 | }) | ||
36 | ) | ||
37 | .subscribe(() => { | ||
38 | this.router.navigateByUrl(`/accounts/${accountOrChannelName}`) | ||
39 | }) | ||
40 | } | ||
41 | } | ||
diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts index 3ea5b7e5e..c0a2d29e4 100644 --- a/client/src/app/app-routing.module.ts +++ b/client/src/app/app-routing.module.ts | |||
@@ -5,6 +5,7 @@ import { MenuGuards } from '@app/core/routing/menu-guard.service' | |||
5 | import { POSSIBLE_LOCALES } from '@shared/core-utils/i18n' | 5 | import { POSSIBLE_LOCALES } from '@shared/core-utils/i18n' |
6 | import { PreloadSelectedModulesList } from './core' | 6 | import { PreloadSelectedModulesList } from './core' |
7 | import { EmptyComponent } from './empty.component' | 7 | import { EmptyComponent } from './empty.component' |
8 | import { ActorsComponent } from './+actors/actors.component' | ||
8 | 9 | ||
9 | const routes: Routes = [ | 10 | const routes: Routes = [ |
10 | { | 11 | { |
@@ -66,6 +67,18 @@ const routes: Routes = [ | |||
66 | redirectTo: 'videos/watch/playlist' | 67 | redirectTo: 'videos/watch/playlist' |
67 | }, | 68 | }, |
68 | { | 69 | { |
70 | path: 'a', | ||
71 | redirectTo: 'accounts' | ||
72 | }, | ||
73 | { | ||
74 | path: 'c', | ||
75 | redirectTo: 'video-channels' | ||
76 | }, | ||
77 | { | ||
78 | path: ':actorName', | ||
79 | component: ActorsComponent | ||
80 | }, | ||
81 | { | ||
69 | path: '', | 82 | path: '', |
70 | component: EmptyComponent // Avoid 404, app component will redirect dynamically | 83 | component: EmptyComponent // Avoid 404, app component will redirect dynamically |
71 | } | 84 | } |