refactor: more process.env references (#13106)

This commit is contained in:
Jason Rasmussen 2024-10-02 08:37:26 -04:00 committed by GitHub
parent e5457ac8ee
commit 6c7d51da34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 62 additions and 28 deletions

View file

@ -14,7 +14,6 @@ import {
} from 'src/constants';
import { OnEvent } from 'src/decorators';
import { SystemConfigDto, SystemConfigTemplateStorageOptionDto, mapConfig } from 'src/dtos/system-config.dto';
import { LogLevel } from 'src/enum';
import { IConfigRepository } from 'src/interfaces/config.interface';
import { ArgOf, IEventRepository } from 'src/interfaces/event.interface';
import { ILoggerRepository } from 'src/interfaces/logger.interface';
@ -52,7 +51,7 @@ export class SystemConfigService extends BaseService {
@OnEvent({ name: 'config.update', server: true })
onConfigUpdate({ newConfig: { logging } }: ArgOf<'config.update'>) {
const envLevel = this.getEnvLogLevel();
const { logLevel: envLevel } = this.configRepository.getEnv();
const configLevel = logging.enabled ? logging.level : false;
const level = envLevel ?? configLevel;
this.logger.setLogLevel(level);
@ -63,7 +62,8 @@ export class SystemConfigService extends BaseService {
@OnEvent({ name: 'config.validate' })
onConfigValidate({ newConfig, oldConfig }: ArgOf<'config.validate'>) {
if (!_.isEqual(instanceToPlain(newConfig.logging), oldConfig.logging) && this.getEnvLogLevel()) {
const { logLevel } = this.configRepository.getEnv();
if (!_.isEqual(instanceToPlain(newConfig.logging), oldConfig.logging) && logLevel) {
throw new Error('Logging cannot be changed while the environment variable IMMICH_LOG_LEVEL is set.');
}
}
@ -109,8 +109,4 @@ export class SystemConfigService extends BaseService {
const { theme } = await this.getConfig({ withCache: false });
return theme.customCss;
}
private getEnvLogLevel() {
return process.env.IMMICH_LOG_LEVEL as LogLevel;
}
}