47 lines
926 B
JavaScript
47 lines
926 B
JavaScript
|
import co from 'co';
|
||
|
|
||
|
import models from '../models';
|
||
|
import { mongo } from '../lib/mongo';
|
||
|
|
||
|
import debugname from 'debug';
|
||
|
const debug = debugname('hostr:db');
|
||
|
let db;
|
||
|
|
||
|
|
||
|
co(function *sync() {
|
||
|
debug('Syncing schema');
|
||
|
yield models.sequelize.sync();
|
||
|
debug('Schema synced');
|
||
|
db = yield mongo;
|
||
|
|
||
|
const files = db.Files.find({}, {
|
||
|
sort: [['time_added', 'desc']],
|
||
|
skip: 0,
|
||
|
});
|
||
|
debug('fetched files');
|
||
|
|
||
|
while (true) {
|
||
|
const file = yield files.next();
|
||
|
if (!file) {
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
if (!file.time_added || !file.file_size || !file.malware) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
yield models.malware.upsert({
|
||
|
fileId: file._id,
|
||
|
positives: file.virustotal ? file.virustotal.positives : 100,
|
||
|
virustotal: file.virustotal || null,
|
||
|
}, { /* logging: false */ });
|
||
|
}
|
||
|
|
||
|
models.sequelize.close();
|
||
|
db.close();
|
||
|
}).catch((err) => {
|
||
|
models.sequelize.close();
|
||
|
db.close();
|
||
|
debug(err);
|
||
|
});
|