From 86e67d44eb4c188c5f20f5e6b468a07cb6b00891 Mon Sep 17 00:00:00 2001 From: Kosztyk <36381705+Kosztyk@users.noreply.github.com> Date: Mon, 5 Jan 2026 21:24:31 +0200 Subject: [PATCH] Add files via upload --- src/helpers/avToggle.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/helpers/avToggle.ts b/src/helpers/avToggle.ts index 7959404..9071856 100644 --- a/src/helpers/avToggle.ts +++ b/src/helpers/avToggle.ts @@ -1,11 +1,11 @@ // src/helpers/avToggle.ts +// +// Simple in-memory antivirus toggle. +// Default behaviour: enabled by default when ClamAV is configured, unless explicitly overridden. -import { - ANTIVIRUS_ENABLED_DEFAULT, - CLAMAV_CONFIGURED, -} from "./env"; +import { ANTIVIRUS_ENABLED_DEFAULT, CLAMAV_CONFIGURED } from "./env"; -let antivirusEnabled = ANTIVIRUS_ENABLED_DEFAULT; +let antivirusEnabled: boolean = CLAMAV_CONFIGURED ? ANTIVIRUS_ENABLED_DEFAULT : false; /** * Is ClamAV configured at all (CLAMAV_URL set)? @@ -15,10 +15,12 @@ export function isAntivirusAvailable(): boolean { } /** - * Is antivirus scanning currently enabled (and available)? + * Current effective antivirus enabled state. + * If ClamAV is not configured, this always returns false. */ export function isAntivirusEnabled(): boolean { - return CLAMAV_CONFIGURED && antivirusEnabled; + if (!CLAMAV_CONFIGURED) return false; + return antivirusEnabled; } /** @@ -30,5 +32,13 @@ export function setAntivirusEnabled(enabled: boolean): void { antivirusEnabled = false; return; } - antivirusEnabled = enabled; + antivirusEnabled = Boolean(enabled); } + +/** + * Useful if env / configuration changes at runtime (tests, hot reload). + */ +export function resetAntivirusEnabledToDefault(): void { + antivirusEnabled = CLAMAV_CONFIGURED ? ANTIVIRUS_ENABLED_DEFAULT : false; +} +