Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix config retrieval and type handling #739

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tdrive/backend/node/src/services/av/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
},
});
Expand Down
6 changes: 3 additions & 3 deletions tdrive/backend/node/src/services/documents/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion tdrive/backend/node/src/services/global-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
11 changes: 9 additions & 2 deletions tdrive/backend/node/src/utils/get-config.ts
Original file line number Diff line number Diff line change
@@ -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;
};