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).
MIT License
230 stars 68 forks source link

TypeError: clamscan.isInfected is not a function #116

Closed BiraruYT closed 5 months ago

BiraruYT commented 8 months ago

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);
    }
kylefarris commented 5 months ago

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 ...
    });
}