1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +02:00

fix(server): log user delete errors (#1255)

This commit is contained in:
Jason Rasmussen 2023-01-04 16:33:13 -05:00 committed by GitHub
parent 9852376b38
commit fd15cdbf40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ import { APIKeyEntity, AssetEntity, UserEntity } from '@app/database';
import { QueueNameEnum, userDeletionProcessorName } from '@app/job';
import { IUserDeletionJob } from '@app/job/interfaces/user-deletion.interface';
import { Process, Processor } from '@nestjs/bull';
import { Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Job } from 'bull';
import { join } from 'path';
@ -11,6 +12,8 @@ import { Repository } from 'typeorm';
@Processor(QueueNameEnum.USER_DELETION)
export class UserDeletionProcessor {
private logger = new Logger(UserDeletionProcessor.name);
constructor(
@InjectRepository(UserEntity)
private userRepository: Repository<UserEntity>,
@ -25,14 +28,29 @@ export class UserDeletionProcessor {
@Process(userDeletionProcessorName)
async processUserDeletion(job: Job<IUserDeletionJob>) {
const { user } = job.data;
// just for extra protection here
if (userUtils.isReadyForDeletion(user)) {
if (!userUtils.isReadyForDeletion(user)) {
this.logger.warn(`Skipped user that was not ready for deletion: id=${user.id}`);
return;
}
this.logger.log(`Deleting user: ${user.id}`);
try {
const basePath = APP_UPLOAD_LOCATION;
const userAssetDir = join(basePath, user.id);
this.logger.warn(`Removing user from filesystem: ${userAssetDir}`);
fs.rmSync(userAssetDir, { recursive: true, force: true });
this.logger.warn(`Removing user from database: ${user.id}`);
await this.apiKeyRepository.delete({ userId: user.id });
await this.assetRepository.delete({ userId: user.id });
await this.userRepository.remove(user);
} catch (error: any) {
this.logger.error(`Failed to remove user`);
this.logger.error(error, error?.stack);
throw error;
}
}
}