From ba5d4a849c7d7ba05f093480ae12286c4af61556 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 27 Jan 2021 17:15:21 +0100 Subject: move from trending routes to alg param --- client/src/app/core/core.module.ts | 3 +- client/src/app/core/routing/index.ts | 1 - client/src/app/core/routing/redirect.service.ts | 34 +++++++--------------- .../src/app/core/routing/trending-guard.service.ts | 14 --------- client/src/app/core/server/server.service.ts | 12 ++++---- 5 files changed, 17 insertions(+), 47 deletions(-) delete mode 100644 client/src/app/core/routing/trending-guard.service.ts (limited to 'client/src/app/core') diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts index 32dfc8f36..2392a234c 100644 --- a/client/src/app/core/core.module.ts +++ b/client/src/app/core/core.module.ts @@ -15,7 +15,7 @@ import { throwIfAlreadyLoaded } from './module-import-guard' import { Notifier } from './notification' import { HtmlRendererService, LinkifierService, MarkdownService } from './renderer' import { RestExtractor, RestService } from './rest' -import { LoginGuard, RedirectService, UserRightGuard, UnloggedGuard, TrendingGuard } from './routing' +import { LoginGuard, RedirectService, UserRightGuard, UnloggedGuard } from './routing' import { CanDeactivateGuard } from './routing/can-deactivate-guard.service' import { ServerConfigResolver } from './routing/server-config-resolver.service' import { ScopedTokensService } from './scoped-tokens' @@ -56,7 +56,6 @@ import { LocalStorageService, ScreenService, SessionStorageService } from './wra LoginGuard, UserRightGuard, UnloggedGuard, - TrendingGuard, PluginService, HooksService, 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' export * from './server-config-resolver.service' export * from './unlogged-guard.service' export * from './user-right-guard.service' -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 { // Default route could change according to the instance configuration static INIT_DEFAULT_ROUTE = '/videos/trending' static DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE - static INIT_DEFAULT_TRENDING_ROUTE = '/videos/most-viewed' - static DEFAULT_TRENDING_ROUTE = RedirectService.INIT_DEFAULT_TRENDING_ROUTE + static INIT_DEFAULT_TRENDING_ALGORITHM = 'most-viewed' + static DEFAULT_TRENDING_ALGORITHM = RedirectService.INIT_DEFAULT_TRENDING_ALGORITHM private previousUrl: string private currentUrl: string private redirectingToHomepage = false - private redirectingToTrending = false constructor ( private router: Router, @@ -22,27 +21,25 @@ export class RedirectService { ) { // The config is first loaded from the cache so try to get the default route const tmpConfig = this.serverService.getTmpConfig() - if (tmpConfig && tmpConfig.instance) { - if (tmpConfig.instance.defaultClientRoute) { - RedirectService.DEFAULT_ROUTE = tmpConfig.instance.defaultClientRoute - } - if (tmpConfig.instance.defaultTrendingRoute) { - RedirectService.DEFAULT_TRENDING_ROUTE = tmpConfig.instance.defaultTrendingRoute - } + if (tmpConfig?.instance?.defaultClientRoute) { + RedirectService.DEFAULT_ROUTE = tmpConfig.instance.defaultClientRoute + } + if (tmpConfig?.trending?.videos?.algorithms?.default) { + RedirectService.DEFAULT_TRENDING_ALGORITHM = tmpConfig.trending.videos.algorithms.default } // Load default route this.serverService.getConfig() .subscribe(config => { const defaultRouteConfig = config.instance.defaultClientRoute - const defaultTrendingConfig = config.instance.defaultTrendingRoute + const defaultTrendingConfig = config.trending.videos.algorithms.default if (defaultRouteConfig) { RedirectService.DEFAULT_ROUTE = defaultRouteConfig } if (defaultTrendingConfig) { - RedirectService.DEFAULT_TRENDING_ROUTE = defaultTrendingConfig + RedirectService.DEFAULT_TRENDING_ALGORITHM = defaultTrendingConfig } }) @@ -70,15 +67,6 @@ export class RedirectService { return this.redirectToHomepage() } - redirectToTrending () { - if (this.redirectingToTrending) return - - this.redirectingToTrending = true - - this.router.navigate([ RedirectService.DEFAULT_TRENDING_ROUTE ]) - .then(() => this.redirectingToTrending = false) - } - redirectToHomepage (skipLocationChange = false) { if (this.redirectingToHomepage) return @@ -86,7 +74,7 @@ export class RedirectService { console.log('Redirecting to %s...', RedirectService.DEFAULT_ROUTE) - this.router.navigate([ RedirectService.DEFAULT_ROUTE ], { skipLocationChange }) + this.router.navigateByUrl(RedirectService.DEFAULT_ROUTE, { skipLocationChange }) .then(() => this.redirectingToHomepage = false) .catch(() => { this.redirectingToHomepage = false @@ -98,7 +86,7 @@ export class RedirectService { ) RedirectService.DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE - return this.router.navigate([ RedirectService.DEFAULT_ROUTE ], { skipLocationChange }) + return this.router.navigateByUrl(RedirectService.DEFAULT_ROUTE, { skipLocationChange }) }) } 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 @@ -import { Injectable } from '@angular/core' -import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router' -import { RedirectService } from './redirect.service' - -@Injectable() -export class TrendingGuard implements CanActivate { - - constructor (private redirectService: RedirectService) {} - - canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { - this.redirectService.redirectToTrending() - return false - } -} diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index 5f13190b4..a38883eee 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts @@ -39,12 +39,6 @@ export class ServerService { isNSFW: false, defaultNSFWPolicy: 'do_not_list' as 'do_not_list', defaultClientRoute: '', - defaultTrendingRoute: '', - pages: { - hot: { - enabled: true - } - }, customizations: { javascript: '', css: '' @@ -131,7 +125,11 @@ export class ServerService { }, trending: { videos: { - intervalDays: 0 + intervalDays: 0, + algorithms: { + enabled: [ 'hot', 'most-viewed', 'most-liked' ], + default: 'most-viewed' + } } }, autoBlacklist: { -- cgit v1.2.3