refactor: enum casing (#19946)

This commit is contained in:
Jason Rasmussen 2025-07-15 14:50:13 -04:00 committed by GitHub
parent 920d7de349
commit e73abe0762
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
174 changed files with 2675 additions and 2459 deletions

View file

@ -78,7 +78,7 @@ export class UserService extends BaseService {
const updated = mergePreferences(getPreferences(metadata), dto);
await this.userRepository.upsertMetadata(auth.user.id, {
key: UserMetadataKey.PREFERENCES,
key: UserMetadataKey.Preferences,
value: getPreferencesPartial(updated),
});
@ -99,7 +99,7 @@ export class UserService extends BaseService {
});
if (oldpath !== '') {
await this.jobRepository.queue({ name: JobName.DELETE_FILES, data: { files: [oldpath] } });
await this.jobRepository.queue({ name: JobName.DeleteFiles, data: { files: [oldpath] } });
}
return {
@ -115,7 +115,7 @@ export class UserService extends BaseService {
throw new BadRequestException("Can't delete a missing profile Image");
}
await this.userRepository.update(auth.user.id, { profileImagePath: '', profileChangedAt: new Date() });
await this.jobRepository.queue({ name: JobName.DELETE_FILES, data: { files: [user.profileImagePath] } });
await this.jobRepository.queue({ name: JobName.DeleteFiles, data: { files: [user.profileImagePath] } });
}
async getProfileImage(id: string): Promise<ImmichFileResponse> {
@ -127,7 +127,7 @@ export class UserService extends BaseService {
return new ImmichFileResponse({
path: user.profileImagePath,
contentType: 'image/jpeg',
cacheControl: CacheControl.NONE,
cacheControl: CacheControl.None,
});
}
@ -135,7 +135,7 @@ export class UserService extends BaseService {
const metadata = await this.userRepository.getMetadata(auth.user.id);
const license = metadata.find(
(item): item is UserMetadataItem<UserMetadataKey.LICENSE> => item.key === UserMetadataKey.LICENSE,
(item): item is UserMetadataItem<UserMetadataKey.License> => item.key === UserMetadataKey.License,
);
if (!license) {
throw new NotFoundException();
@ -144,7 +144,7 @@ export class UserService extends BaseService {
}
async deleteLicense({ user }: AuthDto): Promise<void> {
await this.userRepository.deleteMetadata(user.id, UserMetadataKey.LICENSE);
await this.userRepository.deleteMetadata(user.id, UserMetadataKey.License);
}
async setLicense(auth: AuthDto, license: LicenseKeyDto): Promise<LicenseResponseDto> {
@ -173,7 +173,7 @@ export class UserService extends BaseService {
const activatedAt = new Date();
await this.userRepository.upsertMetadata(auth.user.id, {
key: UserMetadataKey.LICENSE,
key: UserMetadataKey.License,
value: { ...license, activatedAt: activatedAt.toISOString() },
});
@ -184,7 +184,7 @@ export class UserService extends BaseService {
const metadata = await this.userRepository.getMetadata(auth.user.id);
const onboardingData = metadata.find(
(item): item is UserMetadataItem<UserMetadataKey.ONBOARDING> => item.key === UserMetadataKey.ONBOARDING,
(item): item is UserMetadataItem<UserMetadataKey.Onboarding> => item.key === UserMetadataKey.Onboarding,
)?.value;
if (!onboardingData) {
@ -197,12 +197,12 @@ export class UserService extends BaseService {
}
async deleteOnboarding({ user }: AuthDto): Promise<void> {
await this.userRepository.deleteMetadata(user.id, UserMetadataKey.ONBOARDING);
await this.userRepository.deleteMetadata(user.id, UserMetadataKey.Onboarding);
}
async setOnboarding(auth: AuthDto, onboarding: OnboardingDto): Promise<OnboardingResponseDto> {
await this.userRepository.upsertMetadata(auth.user.id, {
key: UserMetadataKey.ONBOARDING,
key: UserMetadataKey.Onboarding,
value: {
isOnboarded: onboarding.isOnboarded,
},
@ -213,42 +213,42 @@ export class UserService extends BaseService {
};
}
@OnJob({ name: JobName.USER_SYNC_USAGE, queue: QueueName.BACKGROUND_TASK })
@OnJob({ name: JobName.userSyncUsage, queue: QueueName.BackgroundTask })
async handleUserSyncUsage(): Promise<JobStatus> {
await this.userRepository.syncUsage();
return JobStatus.SUCCESS;
return JobStatus.Success;
}
@OnJob({ name: JobName.USER_DELETE_CHECK, queue: QueueName.BACKGROUND_TASK })
@OnJob({ name: JobName.UserDeleteCheck, queue: QueueName.BackgroundTask })
async handleUserDeleteCheck(): Promise<JobStatus> {
const config = await this.getConfig({ withCache: false });
const users = await this.userRepository.getDeletedAfter(DateTime.now().minus({ days: config.user.deleteDelay }));
await this.jobRepository.queueAll(users.map((user) => ({ name: JobName.USER_DELETION, data: { id: user.id } })));
return JobStatus.SUCCESS;
await this.jobRepository.queueAll(users.map((user) => ({ name: JobName.UserDeletion, data: { id: user.id } })));
return JobStatus.Success;
}
@OnJob({ name: JobName.USER_DELETION, queue: QueueName.BACKGROUND_TASK })
async handleUserDelete({ id, force }: JobOf<JobName.USER_DELETION>): Promise<JobStatus> {
@OnJob({ name: JobName.UserDeletion, queue: QueueName.BackgroundTask })
async handleUserDelete({ id, force }: JobOf<JobName.UserDeletion>): Promise<JobStatus> {
const config = await this.getConfig({ withCache: false });
const user = await this.userRepository.get(id, { withDeleted: true });
if (!user) {
return JobStatus.FAILED;
return JobStatus.Failed;
}
// just for extra protection here
if (!force && !this.isReadyForDeletion(user, config.user.deleteDelay)) {
this.logger.warn(`Skipped user that was not ready for deletion: id=${id}`);
return JobStatus.SKIPPED;
return JobStatus.Skipped;
}
this.logger.log(`Deleting user: ${user.id}`);
const folders = [
StorageCore.getLibraryFolder(user),
StorageCore.getFolderLocation(StorageFolder.UPLOAD, user.id),
StorageCore.getFolderLocation(StorageFolder.PROFILE, user.id),
StorageCore.getFolderLocation(StorageFolder.THUMBNAILS, user.id),
StorageCore.getFolderLocation(StorageFolder.ENCODED_VIDEO, user.id),
StorageCore.getFolderLocation(StorageFolder.Upload, user.id),
StorageCore.getFolderLocation(StorageFolder.Profile, user.id),
StorageCore.getFolderLocation(StorageFolder.Thumbnails, user.id),
StorageCore.getFolderLocation(StorageFolder.EncodedVideo, user.id),
];
for (const folder of folders) {
@ -260,7 +260,7 @@ export class UserService extends BaseService {
await this.albumRepository.deleteAll(user.id);
await this.userRepository.delete(user, true);
return JobStatus.SUCCESS;
return JobStatus.Success;
}
private isReadyForDeletion(user: { id: string; deletedAt?: Date | null }, deleteDelay: number): boolean {