refactor(server): cli service (#9672)

This commit is contained in:
Jason Rasmussen 2024-05-22 16:23:47 -04:00 committed by GitHub
parent 967d195a05
commit 13cbdf6851
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 176 additions and 91 deletions

View file

@ -1,18 +1,18 @@
import { Command, CommandRunner } from 'nest-commander';
import { UserService } from 'src/services/user.service';
import { CliService } from 'src/services/cli.service';
@Command({
name: 'list-users',
description: 'List Immich users',
})
export class ListUsersCommand extends CommandRunner {
constructor(private userService: UserService) {
constructor(private service: CliService) {
super();
}
async run(): Promise<void> {
try {
const users = await this.userService.listUsers();
const users = await this.service.listUsers();
console.dir(users);
} catch (error) {
console.error(error);

View file

@ -1,19 +1,17 @@
import { Command, CommandRunner } from 'nest-commander';
import { SystemConfigService } from 'src/services/system-config.service';
import { CliService } from 'src/services/cli.service';
@Command({
name: 'enable-oauth-login',
description: 'Enable OAuth login',
})
export class EnableOAuthLogin extends CommandRunner {
constructor(private configService: SystemConfigService) {
constructor(private service: CliService) {
super();
}
async run(): Promise<void> {
const config = await this.configService.getConfig();
config.oauth.enabled = true;
await this.configService.updateConfig(config);
await this.service.enableOAuthLogin();
console.log('OAuth login has been enabled.');
}
}
@ -23,14 +21,12 @@ export class EnableOAuthLogin extends CommandRunner {
description: 'Disable OAuth login',
})
export class DisableOAuthLogin extends CommandRunner {
constructor(private configService: SystemConfigService) {
constructor(private service: CliService) {
super();
}
async run(): Promise<void> {
const config = await this.configService.getConfig();
config.oauth.enabled = false;
await this.configService.updateConfig(config);
await this.service.disableOAuthLogin();
console.log('OAuth login has been disabled.');
}
}

View file

@ -1,19 +1,17 @@
import { Command, CommandRunner } from 'nest-commander';
import { SystemConfigService } from 'src/services/system-config.service';
import { CliService } from 'src/services/cli.service';
@Command({
name: 'enable-password-login',
description: 'Enable password login',
})
export class EnablePasswordLoginCommand extends CommandRunner {
constructor(private configService: SystemConfigService) {
constructor(private service: CliService) {
super();
}
async run(): Promise<void> {
const config = await this.configService.getConfig();
config.passwordLogin.enabled = true;
await this.configService.updateConfig(config);
await this.service.enablePasswordLogin();
console.log('Password login has been enabled.');
}
}
@ -23,14 +21,12 @@ export class EnablePasswordLoginCommand extends CommandRunner {
description: 'Disable password login',
})
export class DisablePasswordLoginCommand extends CommandRunner {
constructor(private configService: SystemConfigService) {
constructor(private service: CliService) {
super();
}
async run(): Promise<void> {
const config = await this.configService.getConfig();
config.passwordLogin.enabled = false;
await this.configService.updateConfig(config);
await this.service.disablePasswordLogin();
console.log('Password login has been disabled.');
}
}

View file

@ -1,20 +1,9 @@
import { Command, CommandRunner, InquirerService, Question, QuestionSet } from 'nest-commander';
import { UserResponseDto } from 'src/dtos/user.dto';
import { UserService } from 'src/services/user.service';
import { CliService } from 'src/services/cli.service';
@Command({
name: 'reset-admin-password',
description: 'Reset the admin password',
})
export class ResetAdminPasswordCommand extends CommandRunner {
constructor(
private userService: UserService,
private inquirer: InquirerService,
) {
super();
}
ask = (admin: UserResponseDto) => {
const prompt = (inquirer: InquirerService) => {
return function ask(admin: UserResponseDto) {
const { id, oauthId, email, name } = admin;
console.log(`Found Admin:
- ID=${id}
@ -22,12 +11,25 @@ export class ResetAdminPasswordCommand extends CommandRunner {
- Email=${email}
- Name=${name}`);
return this.inquirer.ask<{ password: string }>('prompt-password', {}).then(({ password }) => password);
return inquirer.ask<{ password: string }>('prompt-password', {}).then(({ password }) => password);
};
};
@Command({
name: 'reset-admin-password',
description: 'Reset the admin password',
})
export class ResetAdminPasswordCommand extends CommandRunner {
constructor(
private service: CliService,
private inquirer: InquirerService,
) {
super();
}
async run(): Promise<void> {
try {
const { password, provided } = await this.userService.resetAdminPassword(this.ask);
const { password, provided } = await this.service.resetAdminPassword(prompt(this.inquirer));
if (provided) {
console.log(`The admin password has been updated.`);