Add files via upload
This commit is contained in:
parent
d4be44c316
commit
3420464d72
1 changed files with 64 additions and 12 deletions
|
|
@ -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
|
||||||
const available = isAntivirusAvailable();
|
.get(
|
||||||
const enabled = isAntivirusEnabled();
|
"/api/antivirus",
|
||||||
return { available, enabled };
|
() => {
|
||||||
})
|
const available = isAntivirusAvailable();
|
||||||
// Update AV status
|
const enabled = isAntivirusEnabled();
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"[Antivirus API][GET] available:",
|
||||||
|
available,
|
||||||
|
"enabled:",
|
||||||
|
enabled,
|
||||||
|
);
|
||||||
|
|
||||||
|
return { available, enabled };
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 🔒 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,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue