chore(server): move commands (#8121)

move commands
This commit is contained in:
Daniel Dietzler 2024-03-20 21:25:33 +01:00 committed by GitHub
parent 96a22ec3c1
commit 2dcce03352
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 15 additions and 19 deletions

View file

@ -0,0 +1,32 @@
import { Command, CommandRunner } from 'nest-commander';
import { UserService } from 'src/domain/user/user.service';
import { UserEntity } from 'src/infra/entities/user.entity';
@Command({
name: 'list-users',
description: 'List Immich users',
})
export class ListUsersCommand extends CommandRunner {
constructor(private userService: UserService) {
super();
}
async run(): Promise<void> {
try {
const users = await this.userService.getAll(
{
user: {
id: 'cli',
email: 'cli@immich.app',
isAdmin: true,
} as UserEntity,
},
true,
);
console.dir(users);
} catch (error) {
console.error(error);
console.error('Unable to load users');
}
}
}

View file

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

View file

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

View file

@ -0,0 +1,53 @@
import { Command, CommandRunner, InquirerService, Question, QuestionSet } from 'nest-commander';
import { UserResponseDto } from 'src/domain/user/response-dto/user-response.dto';
import { UserService } from 'src/domain/user/user.service';
@Command({
name: 'reset-admin-password',
description: 'Reset the admin password',
})
export class ResetAdminPasswordCommand extends CommandRunner {
constructor(
private userService: UserService,
private readonly inquirer: InquirerService,
) {
super();
}
ask = (admin: UserResponseDto) => {
const { id, oauthId, email, name } = admin;
console.log(`Found Admin:
- ID=${id}
- OAuth ID=${oauthId}
- Email=${email}
- Name=${name}`);
return this.inquirer.ask<{ password: string }>('prompt-password', {}).then(({ password }) => password);
};
async run(): Promise<void> {
try {
const { password, provided } = await this.userService.resetAdminPassword(this.ask);
if (provided) {
console.log(`The admin password has been updated.`);
} else {
console.log(`The admin password has been updated to:\n${password}`);
}
} catch (error) {
console.error(error);
console.error('Unable to reset admin password');
}
}
}
@QuestionSet({ name: 'prompt-password' })
export class PromptPasswordQuestions {
@Question({
message: 'Please choose a new password (optional)',
name: 'password',
})
parsePassword(value: string) {
return value;
}
}