Remove virustotal.js as a dependency

This commit is contained in:
Jonathan Cremin 2015-08-30 21:15:31 +02:00
parent 9202b59a5b
commit fece70f66e
6 changed files with 31 additions and 32 deletions

View file

@ -1,6 +1,4 @@
import virustotal from 'virustotal.js';
virustotal.setKey(process.env.VIRUSTOTAL_KEY);
import virustotal from './virustotal';
const extensions = ['EXE', 'PIF', 'APPLICATION', 'GADGET', 'MSI', 'MSP', 'COM', 'SCR', 'HTA', 'CPL', 'MSC',
'JAR', 'BAT', 'CMD', 'VB', 'VBS', 'VBE', 'JS', 'JSE', 'WS', 'WSF', 'WSC', 'WSH', 'PS1', 'PS1XML', 'PS2',
@ -14,21 +12,13 @@ function getExtension(filename) {
return (i < 0) ? '' : filename.substr(i + 1);
}
export default function(file) {
return new Promise((resolve, reject) => {
if (extensions.indexOf(getExtension(file.file_name.toUpperCase())) >= 0) {
virustotal.getFileReport(file.md5, (err, res) => {
if (err) {
return reject(err);
}
if (res.scans) {
resolve({positive: res.positives >= 5, result: res});
} else {
resolve();
}
});
} else {
resolve();
}
});
export default function* (file) {
if (extensions.indexOf(getExtension(file.file_name.toUpperCase())) < 0) {
return false;
}
const result = yield virustotal.getFileReport(file.md5);
return {
positive: result.positives >= 5,
result: result,
};
}

11
lib/virustotal.js Normal file
View file

@ -0,0 +1,11 @@
import fetch from 'node-fetch';
import FormData from 'form-data';
const apiRoot = 'https://www.virustotal.com/vtapi/v2';
export function* getFileReport(resource, apiKey = process.env.VIRUSTOTAL_KEY) {
const form = new FormData();
form.append('apikey', apiKey);
form.append('resource', resource);
return yield fetch(`${apiRoot}/file/report`, { method: 'POST'});
}