forked from Cutlery/immich
* refactor: entity imports * refactor: rename user repository token * chore: merge imports * refactor: rename album repository token * refactor: rename asset repository token * refactor: rename tag repository token
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { APP_UPLOAD_LOCATION, userUtils } from '@app/common';
|
|
import { 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 { InjectRepository } from '@nestjs/typeorm';
|
|
import { Job } from 'bull';
|
|
import { join } from 'path';
|
|
import fs from 'fs';
|
|
import { Repository } from 'typeorm';
|
|
|
|
@Processor(QueueNameEnum.USER_DELETION)
|
|
export class UserDeletionProcessor {
|
|
constructor(
|
|
@InjectRepository(UserEntity)
|
|
private userRepository: Repository<UserEntity>,
|
|
|
|
@InjectRepository(AssetEntity)
|
|
private assetRepository: Repository<AssetEntity>,
|
|
) {}
|
|
|
|
@Process(userDeletionProcessorName)
|
|
async processUserDeletion(job: Job<IUserDeletionJob>) {
|
|
const { user } = job.data;
|
|
// just for extra protection here
|
|
if (userUtils.isReadyForDeletion(user)) {
|
|
const basePath = APP_UPLOAD_LOCATION;
|
|
const userAssetDir = join(basePath, user.id);
|
|
fs.rmSync(userAssetDir, { recursive: true, force: true });
|
|
await this.assetRepository.delete({ userId: user.id });
|
|
await this.userRepository.remove(user);
|
|
}
|
|
}
|
|
}
|