From bb5d4ce9da54ca40da8bd3c9c9db3ecfbdfc93a0 Mon Sep 17 00:00:00 2001 From: izzy Date: Fri, 31 Oct 2025 15:12:00 +0000 Subject: [PATCH] feat: cli command to toggle maintenance mode --- server/src/commands/index.ts | 3 +++ server/src/commands/maintenance-mode.ts | 32 +++++++++++++++++++++++++ server/src/controllers/index.ts | 2 +- server/src/services/cli.service.ts | 12 ++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 server/src/commands/maintenance-mode.ts diff --git a/server/src/commands/index.ts b/server/src/commands/index.ts index 46a8d13e35..2aef2e8c8b 100644 --- a/server/src/commands/index.ts +++ b/server/src/commands/index.ts @@ -1,5 +1,6 @@ import { GrantAdminCommand, PromptEmailQuestion, RevokeAdminCommand } from 'src/commands/grant-admin'; import { ListUsersCommand } from 'src/commands/list-users.command'; +import { DisableMaintenanceModeCommand, EnableMaintenanceModeCommand } from 'src/commands/maintenance-mode'; import { ChangeMediaLocationCommand, PromptConfirmMoveQuestions, @@ -16,6 +17,8 @@ export const commandsAndQuestions = [ PromptEmailQuestion, EnablePasswordLoginCommand, DisablePasswordLoginCommand, + EnableMaintenanceModeCommand, + DisableMaintenanceModeCommand, EnableOAuthLogin, DisableOAuthLogin, ListUsersCommand, diff --git a/server/src/commands/maintenance-mode.ts b/server/src/commands/maintenance-mode.ts new file mode 100644 index 0000000000..1b3d3fc2df --- /dev/null +++ b/server/src/commands/maintenance-mode.ts @@ -0,0 +1,32 @@ +import { Command, CommandRunner } from 'nest-commander'; +import { CliService } from 'src/services/cli.service'; + +@Command({ + name: 'enable-maintenance-mode', + description: 'Enable maintenance mode', +}) +export class EnableMaintenanceModeCommand extends CommandRunner { + constructor(private service: CliService) { + super(); + } + + async run(): Promise { + await this.service.enableMaintenanceMode(); + console.log("Maintenance mode has been enabled.\nThis change won't automatically propagate."); + } +} + +@Command({ + name: 'disable-maintenance-mode', + description: 'Disable maintenance mode', +}) +export class DisableMaintenanceModeCommand extends CommandRunner { + constructor(private service: CliService) { + super(); + } + + async run(): Promise { + await this.service.disableMaintenanceMode(); + console.log("Maintenance mode has been disabled.\nThis change won't automatically propagate."); + } +} diff --git a/server/src/controllers/index.ts b/server/src/controllers/index.ts index df79319bd0..01bc2a19e8 100644 --- a/server/src/controllers/index.ts +++ b/server/src/controllers/index.ts @@ -70,4 +70,4 @@ export const controllers = [ ViewController, ]; -export const maintenanceControllers = [MaintenanceServerController]; +export const maintenanceControllers = [MaintenanceServerController, SystemConfigController]; diff --git a/server/src/services/cli.service.ts b/server/src/services/cli.service.ts index 38144e95b4..00c2749f2c 100644 --- a/server/src/services/cli.service.ts +++ b/server/src/services/cli.service.ts @@ -38,6 +38,18 @@ export class CliService extends BaseService { await this.updateConfig(config); } + async disableMaintenanceMode(): Promise { + const config = await this.getConfig({ withCache: false }); + config.maintenance.enabled = false; + await this.updateConfig(config); + } + + async enableMaintenanceMode(): Promise { + const config = await this.getConfig({ withCache: false }); + config.maintenance.enabled = true; + await this.updateConfig(config); + } + async grantAdminAccess(email: string): Promise { const user = await this.userRepository.getByEmail(email); if (!user) {