kylefarris / clamscan

A robust ClamAV virus scanning library supporting scanning files, directories, and streams with local sockets, local/remote TCP, and local clamscan/clamdscan binaries (with failover).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: clamscan.isInfected is not a function

BiraruYT opened this issue · comments

commented

Did it like this:

const clamscan = new NodeClam().init({
    removeInfected: true, // Removes files if they are infected
    quarantineInfected: './node-clam/infected/', // Move files here if they are infected
    scanLog: './node-clam/log/', // You're a detail-oriented virus logger
    debugMode: true, // Whether to log info/debug statements
    clamscan: {
        path: 'S:/ClamAV/clamscan.exe', // <-- change this to the correct path
        db: 'S:/ClamAV/database',
        scanArchives: true,
        active: true
    },
    clamdscan: {
        path: 'S:/ClamAV/clamd.exe', // <-- provide the correct path here
        config_file: 'S:/ClamAV/clamd.conf',
        multiscan: true,
        reloadDb: true,
        active: true,
        bypass_test: false,
    },
    preference: "clamdscan"
});`
try {
        clamscan.isInfected(icon).then((err, file, isInfected, viruses) => {
            if (err) {
                console.log(err);
            }
            else if (isInfected) {
                return res.status(400).json({
                    message: `Uploaded file is infected. Viruses: ${viruses}`,
                    error: 'INFECTED-FILE',
                    csrfToken: req.csrfToken()
                });
            }
        });

    } catch (err) {
        console.log(`Error while scanning file ${icon.path}`, err);
    }

You need to await the response of init. Your should look like this:

async function scanFile {
    const clamscan = await new NodeClam().init({ // You didn't have the "await" here
        // everything else ...
    });
}