Fix default trending algorithm in admin config

pull/5616/head
Chocobozzz 2023-02-20 10:17:03 +01:00
parent 5471449f99
commit 15825ef18d
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
7 changed files with 30 additions and 25 deletions

View File

@ -44,9 +44,6 @@
<div class="peertube-select-container"> <div class="peertube-select-container">
<select id="trendingVideosAlgorithmsDefault" formControlName="default" class="form-control"> <select id="trendingVideosAlgorithmsDefault" formControlName="default" class="form-control">
<option i18n value="publishedAt">Recently added videos</option>
<option i18n value="originallyPublishedAt">Original publication date</option>
<option i18n value="name">Name</option>
<option i18n value="hot">Hot videos</option> <option i18n value="hot">Hot videos</option>
<option i18n value="most-viewed">Recent views</option> <option i18n value="most-viewed">Recent views</option>
<option i18n value="most-liked">Most liked videos</option> <option i18n value="most-liked">Most liked videos</option>

View File

@ -177,9 +177,6 @@ export class VideosListCommonPageComponent implements OnInit, OnDestroy, Disable
case 'best': case 'best':
return '-hot' return '-hot'
case 'name':
return 'name'
default: default:
return '-' + algorithm as VideoSortField return '-' + algorithm as VideoSortField
} }

View File

@ -8,7 +8,7 @@ import { ServiceWorkerModule } from '@angular/service-worker'
import localeOc from '@app/helpers/locales/oc' import localeOc from '@app/helpers/locales/oc'
import { AppRoutingModule } from './app-routing.module' import { AppRoutingModule } from './app-routing.module'
import { AppComponent } from './app.component' import { AppComponent } from './app.component'
import { CoreModule, PluginService, ServerService } from './core' import { CoreModule, PluginService, RedirectService, ServerService } from './core'
import { EmptyComponent } from './empty.component' import { EmptyComponent } from './empty.component'
import { HeaderComponent, SearchTypeaheadComponent, SuggestionComponent } from './header' import { HeaderComponent, SearchTypeaheadComponent, SuggestionComponent } from './header'
import { HighlightPipe } from './header/highlight.pipe' import { HighlightPipe } from './header/highlight.pipe'
@ -28,13 +28,17 @@ import { SharedUserInterfaceSettingsModule } from './shared/shared-user-settings
registerLocaleData(localeOc, 'oc') registerLocaleData(localeOc, 'oc')
export function loadConfigFactory (server: ServerService, pluginService: PluginService) { export function loadConfigFactory (server: ServerService, pluginService: PluginService, redirectService: RedirectService) {
const initializeServices = () => {
redirectService.init()
pluginService.initializePlugins()
}
return () => { return () => {
const result = server.loadHTMLConfig() const result = server.loadHTMLConfig()
if (result) return result.pipe(tap(() => initializeServices()))
if (result) return result.pipe(tap(() => pluginService.initializePlugins())) initializeServices()
return pluginService.initializePlugins()
} }
} }
@ -84,7 +88,7 @@ export function loadConfigFactory (server: ServerService, pluginService: PluginS
{ {
provide: APP_INITIALIZER, provide: APP_INITIALIZER,
useFactory: loadConfigFactory, useFactory: loadConfigFactory,
deps: [ ServerService, PluginService ], deps: [ ServerService, PluginService, RedirectService ],
multi: true multi: true
} }
] ]

View File

@ -31,12 +31,15 @@ export class RedirectService {
private serverService: ServerService, private serverService: ServerService,
private storage: SessionStorageService private storage: SessionStorageService
) { ) {
// The config is first loaded from the cache so try to get the default route
}
init () {
const config = this.serverService.getHTMLConfig() const config = this.serverService.getHTMLConfig()
if (config?.instance?.defaultClientRoute) { if (config.instance.defaultClientRoute) {
this.defaultRoute = config.instance.defaultClientRoute this.defaultRoute = config.instance.defaultClientRoute
} }
if (config?.trending?.videos?.algorithms?.default) { if (config.trending.videos.algorithms.default) {
this.defaultTrendingAlgorithm = config.trending.videos.algorithms.default this.defaultTrendingAlgorithm = config.trending.videos.algorithms.default
} }
@ -47,7 +50,7 @@ export class RedirectService {
// Track previous url // Track previous url
this.currentUrl = this.router.url this.currentUrl = this.router.url
router.events.subscribe(event => { this.router.events.subscribe(event => {
if (event instanceof NavigationEnd || event instanceof NavigationCancel) { if (event instanceof NavigationEnd || event instanceof NavigationCancel) {
if ([ '/401', '/404' ].includes(event.url)) return if ([ '/401', '/404' ].includes(event.url)) return

View File

@ -40,7 +40,7 @@ export class ServerService {
loadHTMLConfig () { loadHTMLConfig () {
try { try {
return this.loadHTMLConfigLocally() this.loadHTMLConfigLocally()
} catch (err) { } catch (err) {
// Expected in dev mode since we can't inject the config in the HTML // Expected in dev mode since we can't inject the config in the HTML
if (environment.production !== false) { if (environment.production !== false) {

View File

@ -236,12 +236,14 @@ open_telemetry:
trending: trending:
videos: videos:
interval_days: 7 # Compute trending videos for the last x days interval_days: 7 # Compute trending videos for the last x days for 'most-viewed' algorithm
algorithms: algorithms:
enabled: enabled:
- 'hot' # adaptation of Reddit's 'Hot' algorithm - 'hot' # Adaptation of Reddit's 'Hot' algorithm
- 'most-viewed' # default, used initially by PeerTube as the trending page - 'most-viewed' # Number of views in the last x days
- 'most-liked' - 'most-liked' # Global views since the upload of the video
default: 'most-viewed' default: 'most-viewed'
# Cache remote videos on your server, to help other instances to broadcast the video # Cache remote videos on your server, to help other instances to broadcast the video

View File

@ -234,12 +234,14 @@ open_telemetry:
trending: trending:
videos: videos:
interval_days: 7 # Compute trending videos for the last x days interval_days: 7 # Compute trending videos for the last x days for 'most-viewed' algorithm
algorithms: algorithms:
enabled: enabled:
- 'hot' # adaptation of Reddit's 'Hot' algorithm - 'hot' # Adaptation of Reddit's 'Hot' algorithm
- 'most-viewed' # default, used initially by PeerTube as the trending page - 'most-viewed' # Number of views in the last x days
- 'most-liked' - 'most-liked' # Global views since the upload of the video
default: 'most-viewed' default: 'most-viewed'
# Cache remote videos on your server, to help other instances to broadcast the video # Cache remote videos on your server, to help other instances to broadcast the video