Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
Adds quick and dirty catch if something goes wrong
Browse files Browse the repository at this point in the history
Needed for the final presentation.
  • Loading branch information
botic committed May 31, 2019
1 parent 7dc7c5e commit a2b7e3c
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,35 @@ exports.scoreUrl = async function(req, res) {
return;
}

// Spam Blacklisting
const spamBlacklisted = await isDomainBlacklisted(url.hostname) === true;
scorePoints -= spamBlacklisted ? 50 : 0;
scoreDetails.spamBacklisted = spamBlacklisted;

// Certificate Statistics
const certStats = await getCertificateStats(url.hostname);
scoreDetails.certificateChecks = certStats;

// Only add points if certs are available
if (certStats.duration >= 4) {
scorePoints += certStats.freeRate < 0.25 ? 10 : 0;
scorePoints += certStats.freeRate < 0.10 ? 20 : 0;
scorePoints += certStats.freeCount === 0 ? 10 : 0;
scorePoints += certStats.holes === 0 ? 10 : 0;
const durationFactor = certStats.holes === 0 ? 0.5 : (1 / (4 + certStats.holes));
scorePoints += Math.min(Math.floor(certStats.duration * durationFactor), 50);
}
try {
// Spam Blacklisting
const spamBlacklisted = await isDomainBlacklisted(url.hostname) === true;
scorePoints -= spamBlacklisted ? 50 : 0;
scoreDetails.spamBacklisted = spamBlacklisted;

res.status(200).json({
score: (Math.max(Math.min(scorePoints, 100), -100) / 100),
details: scoreDetails
});
// Certificate Statistics
const certStats = await getCertificateStats(url.hostname);
scoreDetails.certificateChecks = certStats;

// Only add points if certs are available
if (certStats.duration >= 4) {
scorePoints += certStats.freeRate < 0.25 ? 10 : 0;
scorePoints += certStats.freeRate < 0.10 ? 20 : 0;
scorePoints += certStats.freeCount === 0 ? 10 : 0;
scorePoints += certStats.holes === 0 ? 10 : 0;
const durationFactor = certStats.holes === 0 ? 0.5 : (1 / (4 + certStats.holes));
scorePoints += Math.min(Math.floor(certStats.duration * durationFactor), 50);
}

res.status(200).json({
score: (Math.max(Math.min(scorePoints, 100), -100) / 100),
details: scoreDetails
});
} catch (e) {
console.error(e);
res.status(200).json({
score: 0,
details: {}
});
}
};

0 comments on commit a2b7e3c

Please sign in to comment.