Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch connection error #31

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const clamscanConfig = {
active: process.env.CLAMD_ACTIVE ? /^true$/i.test(process.env.CLAMD_ACTIVE) : true // If true, this module will consider using the clamscan binary
},
clamdscan: {
socket: process.env.CLAMD_SOCKET ? process.env.CLAMD_SOCKET : '/tmp/clamd.sock', // Socket file for connecting via TCP
socket: process.env.CLAMD_SOCKET && process.env.CLAMD_SOCKET != 'null'? process.env.CLAMD_SOCKET : null, // Socket file for connecting via TCP
host: process.env.CLAMD_HOST ? process.env.CLAMD_HOST : '127.0.0.1', // IP of host to connect to TCP interface
port: process.env.CLAMD_PORT ? parseInt(process.env.CLAMD_PORT) : 65615, // Port of host to use when connecting via TCP interface
timeout: process.env.CLAMD_TIMEOUT ? parseInt(process.env.CLAMD_TIMEOUT) : 120000, // Timeout for scanning files
Expand Down
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ app.use(express.json());
app.use(cors())

// Middleware for attaching clamscan with the express request
app.use(async (req, _, next) => {
req.clamscan = await new NodeClam().init({ ...config.clamscanConfig })
app.use(async (req, res, next) => {
try {
req.clamscan = await new NodeClam().init({ ...config.clamscanConfig })
} catch (err) {
console.log(err);
return res.status(500).json({message: 'Could not connect to clamav for scanning' });
}
next()
})

Expand Down Expand Up @@ -43,7 +48,13 @@ app.post('/virus-scan', async (req, res) => {
})
}
// await req.files.energuide.mv('./tmp/' + req.files.energuide.name);
const scanResult = await scanFile(req.files.energuide, req.clamscan);
let scanResult;
try {
scanResult = await scanFile(req.files.energuide, req.clamscan);
} catch (err) {
console.log(err);
return res.status(500).json({message: 'Clam av encountered an error while scanning'});
}
console.log(scanResult);

if (scanResult.is_infected === true || scanFile.is_infected === null) {
Expand Down
Loading