-1

我想在将文件上传到服务器时扫描文件内容和病毒扫描。我了解了 ClamAV,但不知道如何使用它或在 Angular 组件中安装。感谢任何帮助。

4

1 回答 1

0

Clamav 在 Node.js 上运行,它不会在 Angular 上运行。您可以通过将文件上传到服务器上的临时位置来检查文件是否没有病毒或任何恶意软件。

您可以使用 Node.js API 并且可以运行clamscan. 可能还有其他工具,但这是免费且值得使用的。

npm install clamscan
const NodeClam = require('clamscan');
const ClamScan = new NodeClam().init(options);

// Get instance by resolving ClamScan promise object
ClamScan.then(async clamscan => {
    try {
        // You can re-use the `clamscan` object as many times as you want
        const version = await clamscan.getVersion();
        console.log(`ClamAV Version: ${version}`);

        const {isInfected, file, viruses} = await clamscan.isInfected('/some/file.zip');
        if (isInfected) console.log(`${file} is infected with ${viruses}!`);
    } catch (err) {
        // Handle any errors raised by the code in the try block
    }
}).catch(err => {
    // Handle errors that may have occurred during initialization
});

如果您想使用 async/await,此代码可以提供帮助:

const NodeClam = require('clamscan');

async some_function() {
    try {
        // Get instance by resolving ClamScan promise object
        const clamscan = await new NodeClam().init(options);
        const {goodFiles, badFiles} = await clamscan.scanDir('/foo/bar');
    } catch (err) {
        // Handle any errors raised by the code in the try block
    }
}

some_function();

检查链接以获取更多详细信息。

于 2021-10-25T09:52:01.333 回答