Add files via upload
This commit is contained in:
parent
718f87ec31
commit
179abac88d
2 changed files with 69 additions and 3 deletions
45
src/pages/antivirus.tsx
Normal file
45
src/pages/antivirus.tsx
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
// src/pages/antivirus.tsx
|
||||||
|
|
||||||
|
import { Elysia, t } from "elysia";
|
||||||
|
import { userService } from "./user";
|
||||||
|
import {
|
||||||
|
isAntivirusAvailable,
|
||||||
|
isAntivirusEnabled,
|
||||||
|
setAntivirusEnabled,
|
||||||
|
} from "../helpers/avToggle";
|
||||||
|
|
||||||
|
export const antivirus = new Elysia()
|
||||||
|
.use(userService)
|
||||||
|
// Get current AV status
|
||||||
|
.get("/api/antivirus", () => {
|
||||||
|
const available = isAntivirusAvailable();
|
||||||
|
const enabled = isAntivirusEnabled();
|
||||||
|
return { available, enabled };
|
||||||
|
})
|
||||||
|
// Update AV status
|
||||||
|
.post(
|
||||||
|
"/api/antivirus",
|
||||||
|
({ body }) => {
|
||||||
|
const { enabled } = body;
|
||||||
|
|
||||||
|
if (!isAntivirusAvailable()) {
|
||||||
|
// CLAMAV_URL missing: force disabled and report unavailable
|
||||||
|
return {
|
||||||
|
available: false,
|
||||||
|
enabled: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
setAntivirusEnabled(Boolean(enabled));
|
||||||
|
|
||||||
|
return {
|
||||||
|
available: true,
|
||||||
|
enabled: isAntivirusEnabled(),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
|
body: t.Object({
|
||||||
|
enabled: t.Boolean(),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
|
// src/pages/upload.tsx
|
||||||
|
|
||||||
import { Elysia, t } from "elysia";
|
import { Elysia, t } from "elysia";
|
||||||
import db from "../db/db";
|
import db from "../db/db";
|
||||||
import { WEBROOT, CLAMAV_URL } from "../helpers/env";
|
import { WEBROOT, CLAMAV_URL } from "../helpers/env";
|
||||||
import { uploadsDir } from "../index";
|
import { uploadsDir } from "../index";
|
||||||
import { userService } from "./user";
|
import { userService } from "./user";
|
||||||
import sanitize from "sanitize-filename";
|
import sanitize from "sanitize-filename";
|
||||||
|
import { isAntivirusEnabled } from "../helpers/avToggle";
|
||||||
|
|
||||||
type ClamAvResultItem = {
|
type ClamAvResultItem = {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -23,8 +26,22 @@ type ClamAvResponse = {
|
||||||
* Returns { infected: boolean, viruses: string[] } and logs everything.
|
* Returns { infected: boolean, viruses: string[] } and logs everything.
|
||||||
*/
|
*/
|
||||||
async function scanFileWithClamAV(file: any, fileName: string) {
|
async function scanFileWithClamAV(file: any, fileName: string) {
|
||||||
|
// 🔀 Respect toggle + CLAMAV_URL availability
|
||||||
|
if (!isAntivirusEnabled()) {
|
||||||
|
console.log(
|
||||||
|
"[ClamAV] Antivirus disabled (toggle off or CLAMAV_URL unset). Skipping scan for",
|
||||||
|
fileName,
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
infected: false,
|
||||||
|
viruses: [] as string[],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (!CLAMAV_URL) {
|
if (!CLAMAV_URL) {
|
||||||
console.error("[ClamAV] CLAMAV_URL is not configured, skipping scan.");
|
console.error(
|
||||||
|
"[ClamAV] CLAMAV_URL is not configured, but antivirus was considered enabled. Skipping scan.",
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
infected: false,
|
infected: false,
|
||||||
viruses: [] as string[],
|
viruses: [] as string[],
|
||||||
|
|
@ -161,7 +178,12 @@ export const upload = new Elysia()
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const originalName = (file as any).name ?? "upload";
|
const originalName = (file as any).name ?? "upload";
|
||||||
const sanitizedFileName = sanitize(originalName) || "file";
|
const sanitizedFileName = sanitize(originalName) || "file";
|
||||||
console.log("[Upload] Handling file:", originalName, "=> sanitized:", sanitizedFileName);
|
console.log(
|
||||||
|
"[Upload] Handling file:",
|
||||||
|
originalName,
|
||||||
|
"=> sanitized:",
|
||||||
|
sanitizedFileName,
|
||||||
|
);
|
||||||
|
|
||||||
// 1) Scan with ClamAV REST API (use original name just for logging / AV metadata)
|
// 1) Scan with ClamAV REST API (use original name just for logging / AV metadata)
|
||||||
const scan = await scanFileWithClamAV(file, originalName);
|
const scan = await scanFileWithClamAV(file, originalName);
|
||||||
|
|
@ -216,4 +238,3 @@ export const upload = new Elysia()
|
||||||
auth: true,
|
auth: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue