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 --- server/controllers/api/config.ts | 26 +++++++++++++------------- server/helpers/audit-logger.ts | 1 - server/initializers/config.ts | 12 +++++------- server/middlewares/validators/config.ts | 4 +++- server/tests/api/check-params/config.ts | 14 ++++++++------ server/tests/api/server/config.ts | 14 ++++++++------ 6 files changed, 37 insertions(+), 34 deletions(-) (limited to 'server') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 24e7601ec..45c03be24 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -68,12 +68,6 @@ async function getConfig (req: express.Request, res: express.Response) { isNSFW: CONFIG.INSTANCE.IS_NSFW, defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, - defaultTrendingRoute: CONFIG.INSTANCE.DEFAULT_TRENDING_ROUTE, - pages: { - hot: { - enabled: CONFIG.INSTANCE.PAGES.HOT.ENABLED - } - }, customizations: { javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT, css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS @@ -189,7 +183,11 @@ async function getConfig (req: express.Request, res: express.Response) { }, trending: { videos: { - intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS + intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS, + algorithms: { + enabled: CONFIG.TRENDING.VIDEOS.ALGORITHMS.ENABLED, + default: CONFIG.TRENDING.VIDEOS.ALGORITHMS.DEFAULT + } } }, tracker: { @@ -371,12 +369,6 @@ function customConfig (): CustomConfig { defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, - defaultTrendingRoute: CONFIG.INSTANCE.DEFAULT_TRENDING_ROUTE, - pages: { - hot: { - enabled: CONFIG.INSTANCE.PAGES.HOT.ENABLED - } - }, customizations: { css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS, @@ -467,6 +459,14 @@ function customConfig (): CustomConfig { } } }, + trending: { + videos: { + algorithms: { + enabled: CONFIG.TRENDING.VIDEOS.ALGORITHMS.ENABLED, + default: CONFIG.TRENDING.VIDEOS.ALGORITHMS.DEFAULT + } + } + }, autoBlacklist: { videos: { ofUsers: { diff --git a/server/helpers/audit-logger.ts b/server/helpers/audit-logger.ts index e474959b2..6aae5e821 100644 --- a/server/helpers/audit-logger.ts +++ b/server/helpers/audit-logger.ts @@ -230,7 +230,6 @@ const customConfigKeysToKeep = [ 'instance-description', 'instance-terms', 'instance-defaultClientRoute', - 'instance-defaultTrendingRoute', 'instance-defaultNSFWPolicy', 'instance-customizations-javascript', 'instance-customizations-css', diff --git a/server/initializers/config.ts b/server/initializers/config.ts index e1f807752..fc4a8b709 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts @@ -110,7 +110,11 @@ const CONFIG = { }, TRENDING: { VIDEOS: { - INTERVAL_DAYS: config.get('trending.videos.interval_days') + INTERVAL_DAYS: config.get('trending.videos.interval_days'), + ALGORITHMS: { + get ENABLED () { return config.get('trending.videos.algorithms.enabled') }, + get DEFAULT () { return config.get('trending.videos.algorithms.default') } + } } }, REDUNDANCY: { @@ -281,12 +285,6 @@ const CONFIG = { get DEFAULT_NSFW_POLICY () { return config.get('instance.default_nsfw_policy') }, get DEFAULT_CLIENT_ROUTE () { return config.get('instance.default_client_route') }, - get DEFAULT_TRENDING_ROUTE () { return config.get('instance.default_trending_route') }, - PAGES: { - HOT: { - get ENABLED () { return config.get('instance.pages.hot.enabled') } - } - }, CUSTOMIZATIONS: { get JAVASCRIPT () { return config.get('instance.customizations.javascript') }, diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 0efe1157f..52c28799f 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -17,7 +17,6 @@ const customConfigUpdateValidator = [ body('instance.terms').exists().withMessage('Should have a valid instance terms'), body('instance.defaultNSFWPolicy').custom(isUserNSFWPolicyValid).withMessage('Should have a valid NSFW policy'), body('instance.defaultClientRoute').exists().withMessage('Should have a valid instance default client route'), - body('instance.defaultTrendingRoute').exists().withMessage('Should have a valid instance default trending route'), body('instance.customizations.css').exists().withMessage('Should have a valid instance CSS customization'), body('instance.customizations.javascript').exists().withMessage('Should have a valid instance JavaScript customization'), @@ -55,6 +54,9 @@ const customConfigUpdateValidator = [ body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'), body('import.videos.torrent.enabled').isBoolean().withMessage('Should have a valid import video torrent enabled boolean'), + body('trending.videos.algorithms.default').exists().withMessage('Should have a valid default trending algorithm'), + body('trending.videos.algorithms.enabled').exists().withMessage('Should have a valid array of enabled trending algorithms'), + body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'), body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'), diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index e58e0cd9f..d3ae5fe0a 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -44,12 +44,6 @@ describe('Test config API validators', function () { defaultNSFWPolicy: 'blur', defaultClientRoute: '/videos/recently-added', - defaultTrendingRoute: '/videos/trending', - pages: { - hot: { - enabled: true - } - }, customizations: { javascript: 'alert("coucou")', @@ -142,6 +136,14 @@ describe('Test config API validators', function () { } } }, + trending: { + videos: { + algorithms: { + enabled: [ 'hot', 'most-viewed', 'most-liked' ], + default: 'most-viewed' + } + } + }, autoBlacklist: { videos: { ofUsers: { diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 328f4852a..e0575bdfd 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -276,12 +276,6 @@ describe('Test config', function () { defaultNSFWPolicy: 'blur' as 'blur', defaultClientRoute: '/videos/recently-added', - defaultTrendingRoute: '/videos/trending', - pages: { - hot: { - enabled: true - } - }, customizations: { javascript: 'alert("coucou")', @@ -372,6 +366,14 @@ describe('Test config', function () { } } }, + trending: { + videos: { + algorithms: { + enabled: [ 'hot', 'most-viewed', 'most-liked' ], + default: 'hot' + } + } + }, autoBlacklist: { videos: { ofUsers: { -- cgit v1.2.3