mirror of
https://github.com/Art051/immich.git
synced 2025-08-11 19:29:00 +00:00
feat(server): use nestjs events to validate config (#7986)
* use events for config validation * chore: better types * add unit tests --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
@@ -2,11 +2,13 @@ import {
|
||||
AuthService,
|
||||
ClientEvent,
|
||||
ICommunicationRepository,
|
||||
InternalEventMap,
|
||||
OnConnectCallback,
|
||||
OnServerEventCallback,
|
||||
ServerEvent,
|
||||
} from '@app/domain';
|
||||
import { ImmichLogger } from '@app/infra/logger';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import {
|
||||
OnGatewayConnection,
|
||||
OnGatewayDisconnect,
|
||||
@@ -35,7 +37,10 @@ export class CommunicationRepository
|
||||
@WebSocketServer()
|
||||
private server?: Server;
|
||||
|
||||
constructor(private authService: AuthService) {}
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private eventEmitter: EventEmitter2,
|
||||
) {}
|
||||
|
||||
afterInit(server: Server) {
|
||||
this.logger.log('Initialized websocket server');
|
||||
@@ -97,4 +102,12 @@ export class CommunicationRepository
|
||||
this.logger.debug(`Server event: ${event} (send)`);
|
||||
this.server?.serverSideEmit(event);
|
||||
}
|
||||
|
||||
emit<E extends keyof InternalEventMap>(event: E, data: InternalEventMap[E]): boolean {
|
||||
return this.eventEmitter.emit(event, data);
|
||||
}
|
||||
|
||||
emitAsync<E extends keyof InternalEventMap, R = any[]>(event: E, data: InternalEventMap[E]): Promise<R> {
|
||||
return this.eventEmitter.emitAsync(event, data) as Promise<R>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user