diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2021-01-27 17:15:21 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-01-28 15:55:34 +0100 |
commit | ba5d4a849c7d7ba05f093480ae12286c4af61556 (patch) | |
tree | 704a80b96d3b437ad12feacaaaf58a96b97282a1 /client/src/app/core/routing | |
parent | 3da68f0a781ebd893521e2e6fa200280c92ae815 (diff) | |
download | PeerTube-ba5d4a849c7d7ba05f093480ae12286c4af61556.tar.gz PeerTube-ba5d4a849c7d7ba05f093480ae12286c4af61556.tar.zst PeerTube-ba5d4a849c7d7ba05f093480ae12286c4af61556.zip |
move from trending routes to alg param
Diffstat (limited to 'client/src/app/core/routing')
-rw-r--r-- | client/src/app/core/routing/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/routing/redirect.service.ts | 34 | ||||
-rw-r--r-- | client/src/app/core/routing/trending-guard.service.ts | 14 |
3 files changed, 11 insertions, 38 deletions
diff --git a/client/src/app/core/routing/index.ts b/client/src/app/core/routing/index.ts index b3985d870..239c27caf 100644 --- a/client/src/app/core/routing/index.ts +++ b/client/src/app/core/routing/index.ts | |||
@@ -8,4 +8,3 @@ export * from './redirect.service' | |||
8 | export * from './server-config-resolver.service' | 8 | export * from './server-config-resolver.service' |
9 | export * from './unlogged-guard.service' | 9 | export * from './unlogged-guard.service' |
10 | export * from './user-right-guard.service' | 10 | export * from './user-right-guard.service' |
11 | export * from './trending-guard.service' | ||
diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts index 76e28e461..6d26fb504 100644 --- a/client/src/app/core/routing/redirect.service.ts +++ b/client/src/app/core/routing/redirect.service.ts | |||
@@ -7,14 +7,13 @@ export class RedirectService { | |||
7 | // Default route could change according to the instance configuration | 7 | // Default route could change according to the instance configuration |
8 | static INIT_DEFAULT_ROUTE = '/videos/trending' | 8 | static INIT_DEFAULT_ROUTE = '/videos/trending' |
9 | static DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE | 9 | static DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE |
10 | static INIT_DEFAULT_TRENDING_ROUTE = '/videos/most-viewed' | 10 | static INIT_DEFAULT_TRENDING_ALGORITHM = 'most-viewed' |
11 | static DEFAULT_TRENDING_ROUTE = RedirectService.INIT_DEFAULT_TRENDING_ROUTE | 11 | static DEFAULT_TRENDING_ALGORITHM = RedirectService.INIT_DEFAULT_TRENDING_ALGORITHM |
12 | 12 | ||
13 | private previousUrl: string | 13 | private previousUrl: string |
14 | private currentUrl: string | 14 | private currentUrl: string |
15 | 15 | ||
16 | private redirectingToHomepage = false | 16 | private redirectingToHomepage = false |
17 | private redirectingToTrending = false | ||
18 | 17 | ||
19 | constructor ( | 18 | constructor ( |
20 | private router: Router, | 19 | private router: Router, |
@@ -22,27 +21,25 @@ export class RedirectService { | |||
22 | ) { | 21 | ) { |
23 | // The config is first loaded from the cache so try to get the default route | 22 | // The config is first loaded from the cache so try to get the default route |
24 | const tmpConfig = this.serverService.getTmpConfig() | 23 | const tmpConfig = this.serverService.getTmpConfig() |
25 | if (tmpConfig && tmpConfig.instance) { | 24 | if (tmpConfig?.instance?.defaultClientRoute) { |
26 | if (tmpConfig.instance.defaultClientRoute) { | 25 | RedirectService.DEFAULT_ROUTE = tmpConfig.instance.defaultClientRoute |
27 | RedirectService.DEFAULT_ROUTE = tmpConfig.instance.defaultClientRoute | 26 | } |
28 | } | 27 | if (tmpConfig?.trending?.videos?.algorithms?.default) { |
29 | if (tmpConfig.instance.defaultTrendingRoute) { | 28 | RedirectService.DEFAULT_TRENDING_ALGORITHM = tmpConfig.trending.videos.algorithms.default |
30 | RedirectService.DEFAULT_TRENDING_ROUTE = tmpConfig.instance.defaultTrendingRoute | ||
31 | } | ||
32 | } | 29 | } |
33 | 30 | ||
34 | // Load default route | 31 | // Load default route |
35 | this.serverService.getConfig() | 32 | this.serverService.getConfig() |
36 | .subscribe(config => { | 33 | .subscribe(config => { |
37 | const defaultRouteConfig = config.instance.defaultClientRoute | 34 | const defaultRouteConfig = config.instance.defaultClientRoute |
38 | const defaultTrendingConfig = config.instance.defaultTrendingRoute | 35 | const defaultTrendingConfig = config.trending.videos.algorithms.default |
39 | 36 | ||
40 | if (defaultRouteConfig) { | 37 | if (defaultRouteConfig) { |
41 | RedirectService.DEFAULT_ROUTE = defaultRouteConfig | 38 | RedirectService.DEFAULT_ROUTE = defaultRouteConfig |
42 | } | 39 | } |
43 | 40 | ||
44 | if (defaultTrendingConfig) { | 41 | if (defaultTrendingConfig) { |
45 | RedirectService.DEFAULT_TRENDING_ROUTE = defaultTrendingConfig | 42 | RedirectService.DEFAULT_TRENDING_ALGORITHM = defaultTrendingConfig |
46 | } | 43 | } |
47 | }) | 44 | }) |
48 | 45 | ||
@@ -70,15 +67,6 @@ export class RedirectService { | |||
70 | return this.redirectToHomepage() | 67 | return this.redirectToHomepage() |
71 | } | 68 | } |
72 | 69 | ||
73 | redirectToTrending () { | ||
74 | if (this.redirectingToTrending) return | ||
75 | |||
76 | this.redirectingToTrending = true | ||
77 | |||
78 | this.router.navigate([ RedirectService.DEFAULT_TRENDING_ROUTE ]) | ||
79 | .then(() => this.redirectingToTrending = false) | ||
80 | } | ||
81 | |||
82 | redirectToHomepage (skipLocationChange = false) { | 70 | redirectToHomepage (skipLocationChange = false) { |
83 | if (this.redirectingToHomepage) return | 71 | if (this.redirectingToHomepage) return |
84 | 72 | ||
@@ -86,7 +74,7 @@ export class RedirectService { | |||
86 | 74 | ||
87 | console.log('Redirecting to %s...', RedirectService.DEFAULT_ROUTE) | 75 | console.log('Redirecting to %s...', RedirectService.DEFAULT_ROUTE) |
88 | 76 | ||
89 | this.router.navigate([ RedirectService.DEFAULT_ROUTE ], { skipLocationChange }) | 77 | this.router.navigateByUrl(RedirectService.DEFAULT_ROUTE, { skipLocationChange }) |
90 | .then(() => this.redirectingToHomepage = false) | 78 | .then(() => this.redirectingToHomepage = false) |
91 | .catch(() => { | 79 | .catch(() => { |
92 | this.redirectingToHomepage = false | 80 | this.redirectingToHomepage = false |
@@ -98,7 +86,7 @@ export class RedirectService { | |||
98 | ) | 86 | ) |
99 | 87 | ||
100 | RedirectService.DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE | 88 | RedirectService.DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE |
101 | return this.router.navigate([ RedirectService.DEFAULT_ROUTE ], { skipLocationChange }) | 89 | return this.router.navigateByUrl(RedirectService.DEFAULT_ROUTE, { skipLocationChange }) |
102 | }) | 90 | }) |
103 | 91 | ||
104 | } | 92 | } |
diff --git a/client/src/app/core/routing/trending-guard.service.ts b/client/src/app/core/routing/trending-guard.service.ts deleted file mode 100644 index 7db7fe994..000000000 --- a/client/src/app/core/routing/trending-guard.service.ts +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router' | ||
3 | import { RedirectService } from './redirect.service' | ||
4 | |||
5 | @Injectable() | ||
6 | export class TrendingGuard implements CanActivate { | ||
7 | |||
8 | constructor (private redirectService: RedirectService) {} | ||
9 | |||
10 | canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | ||
11 | this.redirectService.redirectToTrending() | ||
12 | return false | ||
13 | } | ||
14 | } | ||