2018-02-17 00:00:06 +00:00
|
|
|
const BlacklistAPI = require("../BlacklistAPI");
|
2017-11-11 20:18:13 +00:00
|
|
|
|
|
|
|
function checkBlacklist(req, res, next) {
|
2017-11-12 06:35:30 +00:00
|
|
|
BlacklistAPI.includesPackage(req.packageName).then(
|
2017-11-11 20:18:13 +00:00
|
|
|
blacklisted => {
|
|
|
|
// Disallow packages that have been blacklisted.
|
|
|
|
if (blacklisted) {
|
|
|
|
res
|
|
|
|
.status(403)
|
2017-11-25 21:25:01 +00:00
|
|
|
.type("text")
|
2018-02-17 00:00:06 +00:00
|
|
|
.send(`Package "${req.packageName}" is blacklisted`);
|
2017-11-11 20:18:13 +00:00
|
|
|
} else {
|
2018-02-17 00:00:06 +00:00
|
|
|
next();
|
2017-11-11 20:18:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error => {
|
2018-02-17 00:00:06 +00:00
|
|
|
console.error(error);
|
2017-11-11 20:18:13 +00:00
|
|
|
|
|
|
|
res.status(500).send({
|
2017-11-25 21:25:01 +00:00
|
|
|
error: "Unable to fetch the blacklist"
|
2018-02-17 00:00:06 +00:00
|
|
|
});
|
2017-08-17 06:03:28 +00:00
|
|
|
}
|
2018-02-17 00:00:06 +00:00
|
|
|
);
|
2017-08-17 06:03:28 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 00:00:06 +00:00
|
|
|
module.exports = checkBlacklist;
|