From 1a1b246d4547ceef0e3e02cb0562bbdfd299f057 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Thu, 7 Sep 2023 17:25:48 +0200 Subject: [PATCH] refactoring. --- server/lib/routers/api.ts | 4 ++-- server/lib/routers/api/configuration.ts | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/server/lib/routers/api.ts b/server/lib/routers/api.ts index ba04c6bd..5ce0257b 100644 --- a/server/lib/routers/api.ts +++ b/server/lib/routers/api.ts @@ -35,6 +35,8 @@ async function initApiRouter (options: RegisterServerOptions): Promise { await initFederationServerInfosApiRouter(options, router) + await initConfigurationApiRouter(options, router) + if (isDebugMode(options)) { // Only add this route if the debug mode is enabled at time of the server launch. // Note: the isDebugMode will be tested again when the API is called. @@ -53,8 +55,6 @@ async function initApiRouter (options: RegisterServerOptions): Promise { )) } - router.use('/configuration', await initConfigurationApiRouter(options)) - return router } diff --git a/server/lib/routers/api/configuration.ts b/server/lib/routers/api/configuration.ts index e057127c..fed4af86 100644 --- a/server/lib/routers/api/configuration.ts +++ b/server/lib/routers/api/configuration.ts @@ -7,11 +7,10 @@ import { checkConfigurationEnabledMiddleware } from '../../middlewares/configura import { getChannelConfigurationOptions, storeChannelConfigurationOptions } from '../../configuration/channel/storage' import { sanitizeChannelConfigurationOptions } from '../../configuration/channel/sanitize' -async function initConfigurationApiRouter (options: RegisterServerOptions): Promise { - const router = options.getRouter() +async function initConfigurationApiRouter (options: RegisterServerOptions, router: Router): Promise { const logger = options.peertubeHelpers.logger - router.get('/channel/:channelId', asyncMiddleware([ + router.get('/configuration/channel/:channelId', asyncMiddleware([ checkConfigurationEnabledMiddleware(options), getCheckConfigurationChannelMiddleware(options), async (req: Request, res: Response, _next: NextFunction): Promise => { @@ -28,7 +27,7 @@ async function initConfigurationApiRouter (options: RegisterServerOptions): Prom } ])) - router.post('/channel/:channelId', asyncMiddleware([ + router.post('/configuration/channel/:channelId', asyncMiddleware([ checkConfigurationEnabledMiddleware(options), getCheckConfigurationChannelMiddleware(options), async (req: Request, res: Response, _next: NextFunction): Promise => { @@ -59,8 +58,6 @@ async function initConfigurationApiRouter (options: RegisterServerOptions): Prom res.json(result) } ])) - - return router } export {