mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor: config init event for first config load (#13930)
This commit is contained in:
parent
c383e115af
commit
d456d35510
18 changed files with 160 additions and 146 deletions
|
|
@ -4,17 +4,17 @@ import _ from 'lodash';
|
|||
import { defaults } from 'src/config';
|
||||
import { OnEvent } from 'src/decorators';
|
||||
import { SystemConfigDto, mapConfig } from 'src/dtos/system-config.dto';
|
||||
import { ArgOf } from 'src/interfaces/event.interface';
|
||||
import { ArgOf, BootstrapEventPriority } from 'src/interfaces/event.interface';
|
||||
import { BaseService } from 'src/services/base.service';
|
||||
import { clearConfigCache } from 'src/utils/config';
|
||||
import { toPlainObject } from 'src/utils/object';
|
||||
|
||||
@Injectable()
|
||||
export class SystemConfigService extends BaseService {
|
||||
@OnEvent({ name: 'app.bootstrap', priority: -100 })
|
||||
@OnEvent({ name: 'app.bootstrap', priority: BootstrapEventPriority.SystemConfig })
|
||||
async onBootstrap() {
|
||||
const config = await this.getConfig({ withCache: false });
|
||||
await this.eventRepository.emit('config.update', { newConfig: config });
|
||||
await this.eventRepository.emit('config.init', { newConfig: config });
|
||||
}
|
||||
|
||||
async getSystemConfig(): Promise<SystemConfigDto> {
|
||||
|
|
@ -26,14 +26,18 @@ export class SystemConfigService extends BaseService {
|
|||
return mapConfig(defaults);
|
||||
}
|
||||
|
||||
@OnEvent({ name: 'config.update', server: true })
|
||||
onConfigUpdate({ newConfig: { logging } }: ArgOf<'config.update'>) {
|
||||
@OnEvent({ name: 'config.init' })
|
||||
onConfigInit({ newConfig: { logging } }: ArgOf<'config.init'>) {
|
||||
const { logLevel: envLevel } = this.configRepository.getEnv();
|
||||
const configLevel = logging.enabled ? logging.level : false;
|
||||
const level = envLevel ?? configLevel;
|
||||
this.logger.setLogLevel(level);
|
||||
this.logger.log(`LogLevel=${level} ${envLevel ? '(set via IMMICH_LOG_LEVEL)' : '(set via system config)'}`);
|
||||
// TODO only do this if the event is a socket.io event
|
||||
}
|
||||
|
||||
@OnEvent({ name: 'config.update', server: true })
|
||||
onConfigUpdate({ newConfig }: ArgOf<'config.update'>) {
|
||||
this.onConfigInit({ newConfig });
|
||||
clearConfigCache();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue