🐛 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";
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<boolean>("drive.featureAntivirus", false);
private MAX_FILE_SIZE: number = getConfigOrDefault<number>("av.maxFileSize", 26214400); // 25 MB
async init(): Promise<this> {
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<boolean>("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<string>("av.host", "localhost"), // IP of the server
port: getConfigOrDefault<number>("av.port", 3310) as number, // ClamAV server port
timeout: getConfigOrDefault<number>("av.timeout", 2000), // Timeout for scans
localFallback: true, // Use local clamscan if needed
},
});
@@ -73,9 +73,9 @@ export class DocumentsService {
userRepository: Repository<User>;
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<boolean>("drive.featureUserQuota", false);
defaultQuota: number = getConfigOrDefault<number>("drive.defaultUserQuota", 0);
manageAccessEnabled: boolean = getConfigOrDefault<boolean>("drive.featureManageAccess", false);
logger: TdriveLogger = getLogger("Documents Service");
async init(): Promise<this> {
@@ -136,7 +136,7 @@ class GlobalResolver {
};
// AV service is optional
if (getConfigOrDefault("drive.featureAntivirus", false))
if (getConfigOrDefault<boolean>("drive.featureAntivirus", false))
this.services.av = await new AVServiceImpl().init();
Object.keys(this.services).forEach((key: keyof TdriveServices) => {
+9 -2
View File
@@ -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 = <T>(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;
};