Browse Source

Fix default trending algorithm in admin config

Chocobozzz 1 year ago
parent
commit
15825ef18d

+ 0 - 3
client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html

@@ -44,9 +44,6 @@
 
             <div class="peertube-select-container">
               <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="most-viewed">Recent views</option>
                 <option i18n value="most-liked">Most liked videos</option>

+ 0 - 3
client/src/app/+videos/video-list/videos-list-common-page.component.ts

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

+ 10 - 6
client/src/app/app.module.ts

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

+ 7 - 4
client/src/app/core/routing/redirect.service.ts

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

+ 1 - 1
client/src/app/core/server/server.service.ts

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

+ 6 - 4
config/default.yaml

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

+ 6 - 4
config/production.yaml.example

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