Provide the clamav socket, correctly upsert file hashes
diff --git a/src/reflex/scanners.ts b/src/reflex/scanners.ts
index 49b203b..59bfa2a 100644
--- a/src/reflex/scanners.ts
+++ b/src/reflex/scanners.ts
@@ -11,6 +11,7 @@
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import getEmojiByName from "../utils/getEmojiByName.js";
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
+import config from "../config/main.js";
interface NSFWSchema {
nsfw: boolean;
@@ -22,7 +23,11 @@
}
const nsfw_model = await nsfwjs.load();
-const clamscanner = await new ClamScan().init({});
+const clamscanner = await new ClamScan().init({
+ clamdscan: {
+ socket: config.clamavSocket
+ }
+});
export async function testNSFW(link: string): Promise<NSFWSchema> {
const [fileStream, hash] = await streamAttachment(link);
@@ -34,26 +39,29 @@
const predictions = (await nsfw_model.classify(image, 1))[0]!;
image.dispose();
- return { nsfw: predictions.className === "Hentai" || predictions.className === "Porn" };
+ const nsfw = predictions.className === "Hentai" || predictions.className === "Porn";
+ await client.database.scanCache.write(hash, "nsfw", nsfw);
+
+ return { nsfw };
}
export async function testMalware(link: string): Promise<MalwareSchema> {
const [fileName, hash] = await saveAttachment(link);
const alreadyHaveCheck = await client.database.scanCache.read(hash);
if (alreadyHaveCheck?.malware) return { safe: alreadyHaveCheck.malware };
- let safe;
+ let malware;
try {
- safe = !(await clamscanner.scanFile(fileName)).isInfected;
+ malware = (await clamscanner.scanFile(fileName)).isInfected;
} catch (e) {
return { safe: true };
}
- client.database.scanCache.write(hash, "malware", safe);
- return { safe };
+ client.database.scanCache.write(hash, "malware", malware);
+ return { safe: !malware };
}
export async function testLink(link: string): Promise<{ safe: boolean; tags: string[] }> {
const alreadyHaveCheck = await client.database.scanCache.read(link);
- if (alreadyHaveCheck?.bad_link) return { safe: alreadyHaveCheck.bad_link, tags: alreadyHaveCheck.tags };
+ if (alreadyHaveCheck?.bad_link) return { safe: alreadyHaveCheck.bad_link, tags: alreadyHaveCheck.tags ?? [] };
const scanned: { safe?: boolean; tags?: string[] } = await fetch("https://unscan.p.rapidapi.com/link", {
method: "POST",
headers: {