refactor(server): events (#13003)

* refactor(server): events

* chore: better type

---------

Co-authored-by: Daniel Dietzler <mail@ddietzler.dev>
This commit is contained in:
Jason Rasmussen
2024-09-30 10:35:11 -04:00
committed by GitHub
parent 95c67949f7
commit a2d457b01d
28 changed files with 260 additions and 259 deletions
+10 -10
View File
@@ -8,7 +8,7 @@ import path from 'node:path';
import { SystemConfig } from 'src/config';
import { StorageCore } from 'src/cores/storage.core';
import { SystemConfigCore } from 'src/cores/system-config.core';
import { OnEmit } from 'src/decorators';
import { OnEvent } from 'src/decorators';
import { AssetFaceEntity } from 'src/entities/asset-face.entity';
import { AssetEntity } from 'src/entities/asset.entity';
import { ExifEntity } from 'src/entities/exif.entity';
@@ -132,7 +132,7 @@ export class MetadataService {
);
}
@OnEmit({ event: 'app.bootstrap' })
@OnEvent({ name: 'app.bootstrap' })
async onBootstrap(app: ArgOf<'app.bootstrap'>) {
if (app !== 'microservices') {
return;
@@ -141,7 +141,12 @@ export class MetadataService {
await this.init(config);
}
@OnEmit({ event: 'config.update' })
@OnEvent({ name: 'app.shutdown' })
async onShutdown() {
await this.repository.teardown();
}
@OnEvent({ name: 'config.update' })
async onConfigUpdate({ newConfig }: ArgOf<'config.update'>) {
await this.init(newConfig);
}
@@ -164,11 +169,6 @@ export class MetadataService {
}
}
@OnEmit({ event: 'app.shutdown' })
async onShutdown() {
await this.repository.teardown();
}
async handleLivePhotoLinking(job: IEntityJob): Promise<JobStatus> {
const { id } = job;
const [asset] = await this.assetRepository.getByIds([id], { exifInfo: true });
@@ -333,12 +333,12 @@ export class MetadataService {
return this.processSidecar(id, false);
}
@OnEmit({ event: 'asset.tag' })
@OnEvent({ name: 'asset.tag' })
async handleTagAsset({ assetId }: ArgOf<'asset.tag'>) {
await this.jobRepository.queue({ name: JobName.SIDECAR_WRITE, data: { id: assetId, tags: true } });
}
@OnEmit({ event: 'asset.untag' })
@OnEvent({ name: 'asset.untag' })
async handleUntagAsset({ assetId }: ArgOf<'asset.untag'>) {
await this.jobRepository.queue({ name: JobName.SIDECAR_WRITE, data: { id: assetId, tags: true } });
}