feat: cli command to toggle maintenance mode

This commit is contained in:
izzy 2025-10-31 15:12:00 +00:00
parent 42ac9cf922
commit bb5d4ce9da
No known key found for this signature in database
GPG key ID: 5059F398521BB0F6
4 changed files with 48 additions and 1 deletions

View file

@ -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,

View file

@ -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<void> {
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<void> {
await this.service.disableMaintenanceMode();
console.log("Maintenance mode has been disabled.\nThis change won't automatically propagate.");
}
}

View file

@ -70,4 +70,4 @@ export const controllers = [
ViewController,
];
export const maintenanceControllers = [MaintenanceServerController];
export const maintenanceControllers = [MaintenanceServerController, SystemConfigController];

View file

@ -38,6 +38,18 @@ export class CliService extends BaseService {
await this.updateConfig(config);
}
async disableMaintenanceMode(): Promise<void> {
const config = await this.getConfig({ withCache: false });
config.maintenance.enabled = false;
await this.updateConfig(config);
}
async enableMaintenanceMode(): Promise<void> {
const config = await this.getConfig({ withCache: false });
config.maintenance.enabled = true;
await this.updateConfig(config);
}
async grantAdminAccess(email: string): Promise<void> {
const user = await this.userRepository.getByEmail(email);
if (!user) {