🐛 Fix config retrieval and type handling (#739)

🐛 Fix config retrieval and type handling
This commit is contained in:
Montassar Ghanmy
2024-11-22 10:58:51 +01:00
committed by GitHub
parent c1856ca634
commit f12f0892f1
4 changed files with 19 additions and 12 deletions
@@ -13,8 +13,8 @@ export class AVServiceImpl implements TdriveServiceProvider, Initializable {
version: "1"; version: "1";
av: NodeClam = null; av: NodeClam = null;
logger: TdriveLogger = getLogger("Antivirus Service"); logger: TdriveLogger = getLogger("Antivirus Service");
avEnabled = getConfigOrDefault("drive.featureAntivirus", false); avEnabled: boolean = getConfigOrDefault<boolean>("drive.featureAntivirus", false);
private MAX_FILE_SIZE = getConfigOrDefault("av.maxFileSize", 26214400); // 25 MB private MAX_FILE_SIZE: number = getConfigOrDefault<number>("av.maxFileSize", 26214400); // 25 MB
async init(): Promise<this> { async init(): Promise<this> {
try { try {
@@ -23,11 +23,11 @@ export class AVServiceImpl implements TdriveServiceProvider, Initializable {
removeInfected: false, // Do not remove infected files removeInfected: false, // Do not remove infected files
quarantineInfected: false, // Do not quarantine, just alert quarantineInfected: false, // Do not quarantine, just alert
scanLog: null, // No log file for this test scanLog: null, // No log file for this test
debugMode: getConfigOrDefault("av.debugMode", false), // Enable debug messages debugMode: getConfigOrDefault<boolean>("av.debugMode", false), // Enable debug messages
clamdscan: { clamdscan: {
host: getConfigOrDefault("av.host", "localhost"), // IP of the server host: getConfigOrDefault<string>("av.host", "localhost"), // IP of the server
port: getConfigOrDefault("av.port", 3310) as number, // ClamAV server port port: getConfigOrDefault<number>("av.port", 3310) as number, // ClamAV server port
timeout: getConfigOrDefault("av.timeout", 2000), // Timeout for scans timeout: getConfigOrDefault<number>("av.timeout", 2000), // Timeout for scans
localFallback: true, // Use local clamscan if needed localFallback: true, // Use local clamscan if needed
}, },
}); });
@@ -73,9 +73,9 @@ export class DocumentsService {
userRepository: Repository<User>; userRepository: Repository<User>;
ROOT: RootType = "root"; ROOT: RootType = "root";
TRASH: TrashType = "trash"; TRASH: TrashType = "trash";
quotaEnabled: boolean = getConfigOrDefault("drive.featureUserQuota", false); quotaEnabled: boolean = getConfigOrDefault<boolean>("drive.featureUserQuota", false);
defaultQuota: number = getConfigOrDefault("drive.defaultUserQuota", 0); defaultQuota: number = getConfigOrDefault<number>("drive.defaultUserQuota", 0);
manageAccessEnabled: boolean = getConfigOrDefault("drive.featureManageAccess", false); manageAccessEnabled: boolean = getConfigOrDefault<boolean>("drive.featureManageAccess", false);
logger: TdriveLogger = getLogger("Documents Service"); logger: TdriveLogger = getLogger("Documents Service");
async init(): Promise<this> { async init(): Promise<this> {
@@ -136,7 +136,7 @@ class GlobalResolver {
}; };
// AV service is optional // AV service is optional
if (getConfigOrDefault("drive.featureAntivirus", false)) if (getConfigOrDefault<boolean>("drive.featureAntivirus", false))
this.services.av = await new AVServiceImpl().init(); this.services.av = await new AVServiceImpl().init();
Object.keys(this.services).forEach((key: keyof TdriveServices) => { Object.keys(this.services).forEach((key: keyof TdriveServices) => {
+9 -2
View File
@@ -1,5 +1,12 @@
import config from "config"; import config from "config";
export const getConfigOrDefault = (key: string, defaultValue: any) => { export const getConfigOrDefault = <T>(key: string, defaultValue: T): T => {
return config.has(key) ? config.get(key) : defaultValue; 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;
}; };