mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor(server): make user core singleton (#4607)
This commit is contained in:
parent
50bc92aac0
commit
c6b4bc883b
4 changed files with 29 additions and 7 deletions
|
|
@ -75,7 +75,7 @@ export class AuthService {
|
|||
@Inject(IKeyRepository) private keyRepository: IKeyRepository,
|
||||
) {
|
||||
this.configCore = SystemConfigCore.create(configRepository);
|
||||
this.userCore = new UserCore(userRepository, libraryRepository, cryptoRepository);
|
||||
this.userCore = UserCore.create(cryptoRepository, libraryRepository, userRepository);
|
||||
|
||||
custom.setHttpOptionsDefaults({ timeout: 30000 });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,31 @@ import { ICryptoRepository, ILibraryRepository, IUserRepository, UserListFilter
|
|||
|
||||
const SALT_ROUNDS = 10;
|
||||
|
||||
let instance: UserCore | null;
|
||||
|
||||
export class UserCore {
|
||||
constructor(
|
||||
private userRepository: IUserRepository,
|
||||
private libraryRepository: ILibraryRepository,
|
||||
private constructor(
|
||||
private cryptoRepository: ICryptoRepository,
|
||||
private libraryRepository: ILibraryRepository,
|
||||
private userRepository: IUserRepository,
|
||||
) {}
|
||||
|
||||
static create(
|
||||
cryptoRepository: ICryptoRepository,
|
||||
libraryRepository: ILibraryRepository,
|
||||
userRepository: IUserRepository,
|
||||
) {
|
||||
if (!instance) {
|
||||
instance = new UserCore(cryptoRepository, libraryRepository, userRepository);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
static reset() {
|
||||
instance = null;
|
||||
}
|
||||
|
||||
async updateUser(authUser: AuthUserDto, id: string, dto: Partial<UserEntity>): Promise<UserEntity> {
|
||||
if (!authUser.isAdmin && authUser.id !== id) {
|
||||
throw new ForbiddenException('You are not allowed to update this user');
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ export class UserService {
|
|||
@Inject(IUserRepository) private userRepository: IUserRepository,
|
||||
) {
|
||||
this.storageCore = new StorageCore(storageRepository, assetRepository, moveRepository, personRepository);
|
||||
this.userCore = new UserCore(userRepository, libraryRepository, cryptoRepository);
|
||||
this.userCore = UserCore.create(cryptoRepository, libraryRepository, userRepository);
|
||||
}
|
||||
|
||||
async getAll(authUser: AuthUserDto, isAll: boolean): Promise<UserResponseDto[]> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue