Add files via upload

This commit is contained in:
Kosztyk 2025-12-04 16:08:48 +02:00 committed by GitHub
parent d4be44c316
commit 3420464d72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,38 +8,90 @@ import {
setAntivirusEnabled, setAntivirusEnabled,
} from "../helpers/avToggle"; } from "../helpers/avToggle";
/**
* Antivirus toggle API
*
* GET /api/antivirus (auth required)
* -> { available: boolean, enabled: boolean }
*
* POST /api/antivirus (auth required)
* body: { enabled: boolean }
* -> { available: boolean, enabled: boolean }
*
* - `available` reflects CLAMAV_URL (via isAntivirusAvailable()).
* - `enabled` is the global effective flag used by upload.tsx.
*/
export const antivirus = new Elysia() export const antivirus = new Elysia()
.use(userService) .use(userService)
// Get current AV status
.get("/api/antivirus", () => { // Read current antivirus state
.get(
"/api/antivirus",
() => {
const available = isAntivirusAvailable(); const available = isAntivirusAvailable();
const enabled = isAntivirusEnabled(); const enabled = isAntivirusEnabled();
console.log(
"[Antivirus API][GET] available:",
available,
"enabled:",
enabled,
);
return { available, enabled }; return { available, enabled };
}) },
// Update AV status {
// 🔒 Only logged-in users should see global AV state
auth: true,
},
)
// Update antivirus state (enable/disable)
.post( .post(
"/api/antivirus", "/api/antivirus",
({ body }) => { ({ body }) => {
const { enabled } = body; const requested = Boolean(body.enabled);
const available = isAntivirusAvailable();
if (!isAntivirusAvailable()) { console.log(
// CLAMAV_URL missing: force disabled and report unavailable "[Antivirus API][POST] requested enabled=",
requested,
"available=",
available,
);
// If AV is not available (CLAMAV_URL missing), force disabled
if (!available) {
console.warn(
"[Antivirus API][POST] CLAMAV_URL not configured. Refusing to enable antivirus.",
);
return { return {
available: false, available: false,
enabled: false, enabled: false,
}; };
} }
setAntivirusEnabled(Boolean(enabled)); // Persist the new state
setAntivirusEnabled(requested);
const effectiveEnabled = isAntivirusEnabled();
console.log(
"[Antivirus API][POST] effective enabled=",
effectiveEnabled,
);
return { return {
available: true, available: true,
enabled: isAntivirusEnabled(), enabled: effectiveEnabled,
}; };
}, },
{ {
body: t.Object({ body: t.Object({
enabled: t.Boolean(), enabled: t.Boolean(),
}), }),
// 🔒 Only logged-in users can change global AV setting
auth: true,
}, },
); );