From f12f0892f1a22964ad60f44fbb86e0e34eca34a4 Mon Sep 17 00:00:00 2001 From: Montassar Ghanmy Date: Fri, 22 Nov 2024 10:58:51 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20config=20retrieval=20and?= =?UTF-8?q?=20type=20handling=20(#739)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 Fix config retrieval and type handling --- tdrive/backend/node/src/services/av/service/index.ts | 12 ++++++------ .../node/src/services/documents/services/index.ts | 6 +++--- tdrive/backend/node/src/services/global-resolver.ts | 2 +- tdrive/backend/node/src/utils/get-config.ts | 11 +++++++++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tdrive/backend/node/src/services/av/service/index.ts b/tdrive/backend/node/src/services/av/service/index.ts index 8774d891e..8bcf44fbf 100644 --- a/tdrive/backend/node/src/services/av/service/index.ts +++ b/tdrive/backend/node/src/services/av/service/index.ts @@ -13,8 +13,8 @@ export class AVServiceImpl implements TdriveServiceProvider, Initializable { version: "1"; av: NodeClam = null; logger: TdriveLogger = getLogger("Antivirus Service"); - avEnabled = getConfigOrDefault("drive.featureAntivirus", false); - private MAX_FILE_SIZE = getConfigOrDefault("av.maxFileSize", 26214400); // 25 MB + avEnabled: boolean = getConfigOrDefault("drive.featureAntivirus", false); + private MAX_FILE_SIZE: number = getConfigOrDefault("av.maxFileSize", 26214400); // 25 MB async init(): Promise { try { @@ -23,11 +23,11 @@ export class AVServiceImpl implements TdriveServiceProvider, Initializable { removeInfected: false, // Do not remove infected files quarantineInfected: false, // Do not quarantine, just alert scanLog: null, // No log file for this test - debugMode: getConfigOrDefault("av.debugMode", false), // Enable debug messages + debugMode: getConfigOrDefault("av.debugMode", false), // Enable debug messages clamdscan: { - host: getConfigOrDefault("av.host", "localhost"), // IP of the server - port: getConfigOrDefault("av.port", 3310) as number, // ClamAV server port - timeout: getConfigOrDefault("av.timeout", 2000), // Timeout for scans + host: getConfigOrDefault("av.host", "localhost"), // IP of the server + port: getConfigOrDefault("av.port", 3310) as number, // ClamAV server port + timeout: getConfigOrDefault("av.timeout", 2000), // Timeout for scans localFallback: true, // Use local clamscan if needed }, }); diff --git a/tdrive/backend/node/src/services/documents/services/index.ts b/tdrive/backend/node/src/services/documents/services/index.ts index d11285adc..43bb13d33 100644 --- a/tdrive/backend/node/src/services/documents/services/index.ts +++ b/tdrive/backend/node/src/services/documents/services/index.ts @@ -73,9 +73,9 @@ export class DocumentsService { userRepository: Repository; ROOT: RootType = "root"; TRASH: TrashType = "trash"; - quotaEnabled: boolean = getConfigOrDefault("drive.featureUserQuota", false); - defaultQuota: number = getConfigOrDefault("drive.defaultUserQuota", 0); - manageAccessEnabled: boolean = getConfigOrDefault("drive.featureManageAccess", false); + quotaEnabled: boolean = getConfigOrDefault("drive.featureUserQuota", false); + defaultQuota: number = getConfigOrDefault("drive.defaultUserQuota", 0); + manageAccessEnabled: boolean = getConfigOrDefault("drive.featureManageAccess", false); logger: TdriveLogger = getLogger("Documents Service"); async init(): Promise { diff --git a/tdrive/backend/node/src/services/global-resolver.ts b/tdrive/backend/node/src/services/global-resolver.ts index f3897b49e..3e68328b4 100644 --- a/tdrive/backend/node/src/services/global-resolver.ts +++ b/tdrive/backend/node/src/services/global-resolver.ts @@ -136,7 +136,7 @@ class GlobalResolver { }; // AV service is optional - if (getConfigOrDefault("drive.featureAntivirus", false)) + if (getConfigOrDefault("drive.featureAntivirus", false)) this.services.av = await new AVServiceImpl().init(); Object.keys(this.services).forEach((key: keyof TdriveServices) => { diff --git a/tdrive/backend/node/src/utils/get-config.ts b/tdrive/backend/node/src/utils/get-config.ts index 24d71beb1..abf07f4dd 100644 --- a/tdrive/backend/node/src/utils/get-config.ts +++ b/tdrive/backend/node/src/utils/get-config.ts @@ -1,5 +1,12 @@ import config from "config"; -export const getConfigOrDefault = (key: string, defaultValue: any) => { - return config.has(key) ? config.get(key) : defaultValue; +export const getConfigOrDefault = (key: string, defaultValue: T): T => { + const value = config.has(key) ? config.get(key) : defaultValue; + + // Handle specific cases for boolean + if (typeof defaultValue === "boolean") { + return (value === "true" || value === true) as T; + } + + return value as T; };