Last active
December 16, 2022 11:14
-
-
Save samuelkarani/760e63d9d93f4498f9ca52da32bb23e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const NodeClam = require('clamscan'); | |
module.exports = async function scanFile(filePath) { | |
console.log(`Attempting virus scan for ${filePath}`); | |
const clamscan = await new NodeClam().init({ | |
remove_infected: true, | |
debug_mode: false, | |
scan_recursively: false, | |
clamdscan: { | |
socket: process.env.CLAMDSCAN_SOCKET || '/var/run/clamav/clamd.ctl', | |
timeout: 120000, | |
local_fallback: true, | |
path: process.env.CLAMDSCAN_PATH || '/var/lib/clamav', | |
config_file: process.env.CLAMDSCAN_CONFIG_FILE || '/etc/clamav/clamd.conf' | |
} | |
}); | |
const { is_infected, viruses } = await clamscan.scan_file(filePath); | |
if (is_infected) { | |
console.error(`Virus scan failed, file INFECTED`, { filePath, viruses }); | |
} else { | |
console.log(`Virus scan OK`, { filePath }); | |
} | |
return { is_infected, viruses }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment