High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
refactor(server): event names (#12084)
Jason Rasmussen0be3c4472f6e
diff --git a/server/src/app.module.ts b/server/src/app.module.tsindex 1a8a05fd4d..c6cd68a96f 100644--- a/server/src/app.module.ts+++ b/server/src/app.module.ts@@ -62,7 +62,7 @@ export class ApiModule implements OnModuleInit, OnModuleDestroy {async onModuleInit() {const items = setupEventHandlers(this.moduleRef);- await this.eventRepository.emit('onBootstrap', 'api');+ await this.eventRepository.emit('app.bootstrap', 'api');this.logger.setContext('EventLoader');const eventMap = _.groupBy(items, 'event');@@ -74,7 +74,7 @@ export class ApiModule implements OnModuleInit, OnModuleDestroy {}async onModuleDestroy() {- await this.eventRepository.emit('onShutdown');+ await this.eventRepository.emit('app.shutdown');}}@@ -90,11 +90,11 @@ export class MicroservicesModule implements OnModuleInit, OnModuleDestroy {async onModuleInit() {setupEventHandlers(this.moduleRef);- await this.eventRepository.emit('onBootstrap', 'microservices');+ await this.eventRepository.emit('app.bootstrap', 'microservices');}async onModuleDestroy() {- await this.eventRepository.emit('onShutdown');+ await this.eventRepository.emit('app.shutdown');}}diff --git a/server/src/interfaces/event.interface.ts b/server/src/interfaces/event.interface.tsindex 613a6423a4..609f42cc32 100644--- a/server/src/interfaces/event.interface.ts+++ b/server/src/interfaces/event.interface.ts@@ -6,19 +6,19 @@ export const IEventRepository = 'IEventRepository';type EmitEventMap = {// app events- onBootstrap: ['api' | 'microservices'];- onShutdown: [];+ 'app.bootstrap': ['api' | 'microservices'];+ 'app.shutdown': [];// config events- onConfigUpdate: [{ newConfig: SystemConfig; oldConfig: SystemConfig }];- onConfigValidate: [{ newConfig: SystemConfig; oldConfig: SystemConfig }];+ 'config.update': [{ newConfig: SystemConfig; oldConfig: SystemConfig }];+ 'config.validate': [{ newConfig: SystemConfig; oldConfig: SystemConfig }];// album events- onAlbumUpdate: [{ id: string; updatedBy: string }];- onAlbumInvite: [{ id: string; userId: string }];+ 'album.update': [{ id: string; updatedBy: string }];+ 'album.invite': [{ id: string; userId: string }];// user events- onUserSignup: [{ notify: boolean; id: string; tempPassword?: string }];+ 'user.signup': [{ notify: boolean; id: string; tempPassword?: string }];};export type EmitEvent = keyof EmitEventMap;diff --git a/server/src/services/album.service.spec.ts b/server/src/services/album.service.spec.tsindex 16b2d97fdd..164e823336 100644--- a/server/src/services/album.service.spec.ts+++ b/server/src/services/album.service.spec.ts@@ -205,7 +205,7 @@ describe(AlbumService.name, () => {expect(userMock.get).toHaveBeenCalledWith('user-id', {});expect(accessMock.asset.checkOwnerAccess).toHaveBeenCalledWith(authStub.admin.user.id, new Set(['123']));- expect(eventMock.emit).toHaveBeenCalledWith('onAlbumInvite', {+ expect(eventMock.emit).toHaveBeenCalledWith('album.invite', {id: albumStub.empty.id,userId: 'user-id',});@@ -384,7 +384,7 @@ describe(AlbumService.name, () => {userId: authStub.user2.user.id,albumId: albumStub.sharedWithAdmin.id,});- expect(eventMock.emit).toHaveBeenCalledWith('onAlbumInvite', {+ expect(eventMock.emit).toHaveBeenCalledWith('album.invite', {id: albumStub.sharedWithAdmin.id,userId: userStub.user2.id,});@@ -572,7 +572,7 @@ describe(AlbumService.name, () => {albumThumbnailAssetId: 'asset-1',});expect(albumMock.addAssetIds).toHaveBeenCalledWith('album-123', ['asset-1', 'asset-2', 'asset-3']);- expect(eventMock.emit).toHaveBeenCalledWith('onAlbumUpdate', {+ expect(eventMock.emit).toHaveBeenCalledWith('album.update', {id: 'album-123',updatedBy: authStub.admin.user.id,});@@ -616,7 +616,7 @@ describe(AlbumService.name, () => {albumThumbnailAssetId: 'asset-1',});expect(albumMock.addAssetIds).toHaveBeenCalledWith('album-123', ['asset-1', 'asset-2', 'asset-3']);- expect(eventMock.emit).toHaveBeenCalledWith('onAlbumUpdate', {+ expect(eventMock.emit).toHaveBeenCalledWith('album.update', {id: 'album-123',updatedBy: authStub.user1.user.id,});diff --git a/server/src/services/album.service.ts b/server/src/services/album.service.tsindex b2b5ea32a2..1cd5237b7a 100644--- a/server/src/services/album.service.ts+++ b/server/src/services/album.service.ts@@ -140,7 +140,7 @@ export class AlbumService {});for (const { userId } of albumUsers) {- await this.eventRepository.emit('onAlbumInvite', { id: album.id, userId });+ await this.eventRepository.emit('album.invite', { id: album.id, userId });}return mapAlbumWithAssets(album);@@ -192,7 +192,7 @@ export class AlbumService {albumThumbnailAssetId: album.albumThumbnailAssetId ?? firstNewAssetId,});- await this.eventRepository.emit('onAlbumUpdate', { id, updatedBy: auth.user.id });+ await this.eventRepository.emit('album.update', { id, updatedBy: auth.user.id });}return results;@@ -240,7 +240,7 @@ export class AlbumService {}await this.albumUserRepository.create({ userId: userId, albumId: id, role });- await this.eventRepository.emit('onAlbumInvite', { id, userId });+ await this.eventRepository.emit('album.invite', { id, userId });}return this.findOrFail(id, { withAssets: true }).then(mapAlbumWithoutAssets);diff --git a/server/src/services/database.service.ts b/server/src/services/database.service.tsindex b6d61c578d..d2a2813a05 100644--- a/server/src/services/database.service.ts+++ b/server/src/services/database.service.ts@@ -68,7 +68,7 @@ export class DatabaseService {this.logger.setContext(DatabaseService.name);}- @OnEmit({ event: 'onBootstrap', priority: -200 })+ @OnEmit({ event: 'app.bootstrap', priority: -200 })async onBootstrap() {const version = await this.databaseRepository.getPostgresVersion();const current = semver.coerce(version);diff --git a/server/src/services/library.service.ts b/server/src/services/library.service.tsindex 1bee2d32c3..4b82c9811d 100644--- a/server/src/services/library.service.ts+++ b/server/src/services/library.service.ts@@ -66,7 +66,7 @@ export class LibraryService {this.configCore = SystemConfigCore.create(systemMetadataRepository, this.logger);}- @OnEmit({ event: 'onBootstrap' })+ @OnEmit({ event: 'app.bootstrap' })async onBootstrap() {const config = await this.configCore.getConfig({ withCache: false });@@ -104,7 +104,8 @@ export class LibraryService {});}- onConfigValidate({ newConfig }: ArgOf<'onConfigValidate'>) {+ @OnEmit({ event: 'config.validate' })+ onConfigValidate({ newConfig }: ArgOf<'config.validate'>) {const { scan } = newConfig.library;if (!validateCronExpression(scan.cronExpression)) {throw new Error(`Invalid cron expression ${scan.cronExpression}`);@@ -189,7 +190,7 @@ export class LibraryService {}}- @OnEmit({ event: 'onShutdown' })+ @OnEmit({ event: 'app.shutdown' })async onShutdown() {await this.unwatchAll();}diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.tsindex dcdf07b8c3..3c938a4e59 100644--- a/server/src/services/metadata.service.ts+++ b/server/src/services/metadata.service.ts@@ -121,8 +121,8 @@ export class MetadataService {);}- @OnEmit({ event: 'onBootstrap' })- async onBootstrap(app: ArgOf<'onBootstrap'>) {+ @OnEmit({ event: 'app.bootstrap' })+ async onBootstrap(app: ArgOf<'app.bootstrap'>) {if (app !== 'microservices') {return;}@@ -130,8 +130,8 @@ export class MetadataService {await this.init(config);}- @OnEmit({ event: 'onConfigUpdate' })- async onConfigUpdate({ newConfig }: ArgOf<'onConfigUpdate'>) {+ @OnEmit({ event: 'config.update' })+ async onConfigUpdate({ newConfig }: ArgOf<'config.update'>) {await this.init(newConfig);}@@ -153,7 +153,7 @@ export class MetadataService {}}- @OnEmit({ event: 'onShutdown' })+ @OnEmit({ event: 'app.shutdown' })async onShutdown() {await this.repository.teardown();}diff --git a/server/src/services/microservices.service.ts b/server/src/services/microservices.service.tsindex 46ca4118d1..5b28e6a00a 100644--- a/server/src/services/microservices.service.ts+++ b/server/src/services/microservices.service.ts@@ -39,8 +39,8 @@ export class MicroservicesService {private versionService: VersionService,) {}- @OnEmit({ event: 'onBootstrap' })- async onBootstrap(app: ArgOf<'onBootstrap'>) {+ @OnEmit({ event: 'app.bootstrap' })+ async onBootstrap(app: ArgOf<'app.bootstrap'>) {if (app !== 'microservices') {return;}diff --git a/server/src/services/notification.service.ts b/server/src/services/notification.service.tsindex 31701013b7..fa4f79f6d6 100644--- a/server/src/services/notification.service.ts+++ b/server/src/services/notification.service.ts@@ -42,8 +42,8 @@ export class NotificationService {this.configCore = SystemConfigCore.create(systemMetadataRepository, logger);}- @OnEmit({ event: 'onConfigValidate', priority: -100 })- async onConfigValidate({ oldConfig, newConfig }: ArgOf<'onConfigValidate'>) {+ @OnEmit({ event: 'config.validate', priority: -100 })+ async onConfigValidate({ oldConfig, newConfig }: ArgOf<'config.validate'>) {try {if (newConfig.notifications.smtp.enabled &&@@ -57,20 +57,20 @@ export class NotificationService {}}- @OnEmit({ event: 'onUserSignup' })- async onUserSignup({ notify, id, tempPassword }: ArgOf<'onUserSignup'>) {+ @OnEmit({ event: 'user.signup' })+ async onUserSignup({ notify, id, tempPassword }: ArgOf<'user.signup'>) {if (notify) {await this.jobRepository.queue({ name: JobName.NOTIFY_SIGNUP, data: { id, tempPassword } });}}- @OnEmit({ event: 'onAlbumUpdate' })- async onAlbumUpdate({ id, updatedBy }: ArgOf<'onAlbumUpdate'>) {+ @OnEmit({ event: 'album.update' })+ async onAlbumUpdate({ id, updatedBy }: ArgOf<'album.update'>) {await this.jobRepository.queue({ name: JobName.NOTIFY_ALBUM_UPDATE, data: { id, senderId: updatedBy } });}- @OnEmit({ event: 'onAlbumInvite' })- async onAlbumInvite({ id, userId }: ArgOf<'onAlbumInvite'>) {+ @OnEmit({ event: 'album.invite' })+ async onAlbumInvite({ id, userId }: ArgOf<'album.invite'>) {await this.jobRepository.queue({ name: JobName.NOTIFY_ALBUM_INVITE, data: { id, recipientId: userId } });}diff --git a/server/src/services/server.service.ts b/server/src/services/server.service.tsindex faf4d98164..5ea8a3e459 100644--- a/server/src/services/server.service.ts+++ b/server/src/services/server.service.ts@@ -42,7 +42,7 @@ export class ServerService {this.configCore = SystemConfigCore.create(systemMetadataRepository, this.logger);}- @OnEmit({ event: 'onBootstrap' })+ @OnEmit({ event: 'app.bootstrap' })async onBootstrap(): Promise<void> {const featureFlags = await this.getFeatures();if (featureFlags.configFile) {diff --git a/server/src/services/smart-info.service.ts b/server/src/services/smart-info.service.tsindex d57b5fb54f..a75594100f 100644--- a/server/src/services/smart-info.service.ts+++ b/server/src/services/smart-info.service.ts@@ -39,8 +39,8 @@ export class SmartInfoService {this.configCore = SystemConfigCore.create(systemMetadataRepository, this.logger);}- @OnEmit({ event: 'onBootstrap' })- async onBootstrap(app: ArgOf<'onBootstrap'>) {+ @OnEmit({ event: 'app.bootstrap' })+ async onBootstrap(app: ArgOf<'app.bootstrap'>) {if (app !== 'microservices') {return;}@@ -49,8 +49,8 @@ export class SmartInfoService {await this.init(config);}- @OnEmit({ event: 'onConfigValidate' })- onConfigValidate({ newConfig }: ArgOf<'onConfigValidate'>) {+ @OnEmit({ event: 'config.validate' })+ onConfigValidate({ newConfig }: ArgOf<'config.validate'>) {try {getCLIPModelInfo(newConfig.machineLearning.clip.modelName);} catch {@@ -60,8 +60,8 @@ export class SmartInfoService {}}- @OnEmit({ event: 'onConfigUpdate' })- async onConfigUpdate({ oldConfig, newConfig }: ArgOf<'onConfigUpdate'>) {+ @OnEmit({ event: 'config.update' })+ async onConfigUpdate({ oldConfig, newConfig }: ArgOf<'config.update'>) {await this.init(newConfig, oldConfig);}diff --git a/server/src/services/storage-template.service.ts b/server/src/services/storage-template.service.tsindex 4855d602d7..829863e228 100644--- a/server/src/services/storage-template.service.ts+++ b/server/src/services/storage-template.service.ts@@ -89,8 +89,8 @@ export class StorageTemplateService {);}- @OnEmit({ event: 'onConfigValidate' })- onConfigValidate({ newConfig }: ArgOf<'onConfigValidate'>) {+ @OnEmit({ event: 'config.validate' })+ onConfigValidate({ newConfig }: ArgOf<'config.validate'>) {try {const { compiled } = this.compile(newConfig.storageTemplate.template);this.render(compiled, {diff --git a/server/src/services/storage.service.ts b/server/src/services/storage.service.tsindex 1535d53d95..c3f2c06438 100644--- a/server/src/services/storage.service.ts+++ b/server/src/services/storage.service.ts@@ -14,7 +14,7 @@ export class StorageService {this.logger.setContext(StorageService.name);}- @OnEmit({ event: 'onBootstrap' })+ @OnEmit({ event: 'app.bootstrap' })onBootstrap() {const libraryBase = StorageCore.getBaseFolder(StorageFolder.LIBRARY);this.storageRepository.mkdirSync(libraryBase);diff --git a/server/src/services/system-config.service.ts b/server/src/services/system-config.service.tsindex b4e6f903b1..26a91f1d09 100644--- a/server/src/services/system-config.service.ts+++ b/server/src/services/system-config.service.ts@@ -33,7 +33,7 @@ export class SystemConfigService {this.core.config$.subscribe((config) => this.setLogLevel(config));}- @OnEmit({ event: 'onBootstrap', priority: -100 })+ @OnEmit({ event: 'app.bootstrap', priority: -100 })async onBootstrap() {const config = await this.core.getConfig({ withCache: false });this.core.config$.next(config);@@ -48,8 +48,8 @@ export class SystemConfigService {return mapConfig(defaults);}- @OnEmit({ event: 'onConfigValidate' })- onConfigValidate({ newConfig, oldConfig }: ArgOf<'onConfigValidate'>) {+ @OnEmit({ event: 'config.validate' })+ onConfigValidate({ newConfig, oldConfig }: ArgOf<'config.validate'>) {if (!_.isEqual(instanceToPlain(newConfig.logging), oldConfig.logging) && this.getEnvLogLevel()) {throw new Error('Logging cannot be changed while the environment variable IMMICH_LOG_LEVEL is set.');}@@ -63,7 +63,7 @@ export class SystemConfigService {const oldConfig = await this.core.getConfig({ withCache: false });try {- await this.eventRepository.emit('onConfigValidate', { newConfig: dto, oldConfig });+ await this.eventRepository.emit('config.validate', { newConfig: dto, oldConfig });} catch (error) {this.logger.warn(`Unable to save system config due to a validation error: ${error}`);throw new BadRequestException(error instanceof Error ? error.message : error);@@ -74,7 +74,7 @@ export class SystemConfigService {// TODO probably move web socket emits to a separate servicethis.eventRepository.clientBroadcast(ClientEvent.CONFIG_UPDATE, {});this.eventRepository.serverSend(ServerEvent.CONFIG_UPDATE, null);- await this.eventRepository.emit('onConfigUpdate', { newConfig, oldConfig });+ await this.eventRepository.emit('config.update', { newConfig, oldConfig });return mapConfig(newConfig);}diff --git a/server/src/services/user-admin.service.ts b/server/src/services/user-admin.service.tsindex 95eeed0475..6a5b6ea06e 100644--- a/server/src/services/user-admin.service.ts+++ b/server/src/services/user-admin.service.ts@@ -45,7 +45,7 @@ export class UserAdminService {const { notify, ...rest } = dto;const user = await this.userCore.createUser(rest);- await this.eventRepository.emit('onUserSignup', {+ await this.eventRepository.emit('user.signup', {notify: !!notify,id: user.id,tempPassword: user.shouldChangePassword ? rest.password : undefined,diff --git a/server/src/services/version.service.ts b/server/src/services/version.service.tsindex 2f04a51014..468e8c9bdd 100644--- a/server/src/services/version.service.ts+++ b/server/src/services/version.service.ts@@ -37,7 +37,7 @@ export class VersionService {this.configCore = SystemConfigCore.create(systemMetadataRepository, this.logger);}- @OnEmit({ event: 'onBootstrap' })+ @OnEmit({ event: 'app.bootstrap' })async onBootstrap(): Promise<void> {await this.handleVersionCheck();}