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

Fix for category/subcategory updates #1321

Open
wants to merge 2 commits into
base: better-updating
Choose a base branch
from
Open
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
19 changes: 13 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ module.exports.check = (input) => {
}

module.exports.update = async () => {
if(config.lookups.DNS.IP.enabled || config.lookups.DNS.NS.enabled || config.lookups.HTTP.enabled) {
debug("Spawning update process...");
const updateProcess = fork(path.join(__dirname,'scripts/update.js'));
updateProcess.on('message', data => db.write(data.url,data));
updateProcess.on('exit', () => setTimeout(() => this.update(),config.interval.cacheRenewCheck));
}
/* Create and write to cache.db */
debug("Spawning update process...");
const updateProcess = fork(path.join(__dirname,'scripts/update.js'));
debug("Writing to cache.db")
updateProcess.on('message', data => db.write(data.url,data));

/* After db is initially written, write the cache.db every cacheRenewCheck-defined period */
updateProcess.on('exit', () => {
debug("UpdateProcess completed - Next run is in " + config.interval.cacheRenewCheck/1000 + " seconds.")
setTimeout(() => {
this.update();
}, config.interval.cacheRenewCheck);
})
}

module.exports.serve = async (electronApp) => {
Expand Down
10 changes: 7 additions & 3 deletions src/scripts/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ process.once('close', () => process.exit(1));

debug("Updating scams...");

await Promise.all(serialijse.deserialize(cacheFile).scams.reverse().filter(scam => scam.howRecent() > config.interval.cacheExpiration).map(async scam => {
Promise.all(serialijse.deserialize(cacheFile).scams.reverse().filter(scam => scam.howRecent() > config.interval.cacheExpiration).map(async scam => {
if(config.lookups.HTTP.enabled) await scam.getStatus();
if(config.lookups.DNS.IP.enabled) await scam.getIP();
if(config.lookups.DNS.NS.enabled) await scam.getNameservers();
Expand All @@ -27,12 +27,16 @@ process.once('close', () => process.exit(1));
url: scam.url,
name: scam.name,
ip: scam.ip,
category: scam.category,
subcategory: scam.subcategory,
nameservers: scam.nameservers,
status: scam.status,
statusCode: scam.statusCode,
updated: Date.now()
});
}));

debug("Done updating!");
})).then(() => {
debug("Updating scams completed!")
process.exit(1)
})
})();
13 changes: 12 additions & 1 deletion src/utils/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@ const readEntries = async () => {
Object.assign(db,serialijse.deserialize(cacheFile));
yaml.safeLoad(scamsFile).filter(entry => !db.scams.find(scam => scam.url == entry.url)).map(entry => new Scam(entry)).forEach(entry => db.scams.push(entry));
yaml.safeLoad(verifiedFile).filter(entry => !db.verified.find(verified => verified.url == entry.url)).forEach(entry => db.verified.push(entry));
yaml.safeLoad(scamsFile).forEach(entry => {
var index = db.scams.indexOf(db.scams.find(scam => scam.url == entry.url))
db.scams[index].category = entry.category;
db.scams[index].subcategory = entry.subcategory;
db.scams[index].description = entry.description;
});
yaml.safeLoad(verifiedFile).forEach(entry => {
var index = db.verified.indexOf(db.verified.find(verified => verified.url == entry.url))
db.verified[index].url = entry.url;
db.verified[index].description = entry.description;
if(entry.addresses) db.verified[index].addresses = entry.addresses;
});
}
}

const updateIndex = async () => {
debug("Updating index...");
const scamDictionary = createDictionary(db.scams);
const verifiedDictionary = createDictionary(db.verified);

Expand Down