Skip to content

Instantly share code, notes, and snippets.

@darkcl
Created May 22, 2018 15:13
Show Gist options
  • Save darkcl/93adbc07a499c8c6b3df11ecc32a08b8 to your computer and use it in GitHub Desktop.
Save darkcl/93adbc07a499c8c6b3df11ecc32a08b8 to your computer and use it in GitHub Desktop.
import express from "express";
import multer = require("multer");
import * as stream from "stream";
import clamav from "clamav.js";
var upload = multer({
storage: multer.memoryStorage()
});
class Application {
private app = express();
version(): string {
return "1.0";
}
start() {
console.log("Application Started");
this.app.post("/photos/upload", upload.single("photo"), function(
req,
res,
next
) {
const readStream = new stream.Readable();
readStream.push(req.file.buffer);
readStream.push(null);
clamav
.createScanner(3310, "127.0.0.1")
.scan(readStream, function(err, object, malicious) {
if (err) {
console.log(object.path + ": " + err);
next(err);
} else if (malicious) {
console.log(object.path + ": " + malicious + " FOUND");
next(new Error("Virus Detected"));
} else {
console.log(object.path + ": OK");
res.send("OK");
}
});
});
this.app.use(function(err, req, res, next) {
if (err !== null) {
console.log(err);
res.send({ result: "fail", error: err.message });
} else {
next();
}
});
this.app.listen(3000, function() {
console.log("Server listening on port 3000");
});
}
stop(): boolean {
return true;
}
}
const app = new Application();
app.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment