Add auth and blacklist APIs
This commit is contained in:
@ -1,15 +1,26 @@
|
||||
function checkBlacklist(blacklist) {
|
||||
return function(req, res, next) {
|
||||
// Do not allow packages that have been blacklisted.
|
||||
if (blacklist.includes(req.packageName)) {
|
||||
res
|
||||
.status(403)
|
||||
.type('text')
|
||||
.send(`Package "${req.packageName}" is blacklisted`)
|
||||
} else {
|
||||
next()
|
||||
const BlacklistAPI = require('../BlacklistAPI')
|
||||
|
||||
function checkBlacklist(req, res, next) {
|
||||
BlacklistAPI.containsPackage(req.packageName).then(
|
||||
blacklisted => {
|
||||
// Disallow packages that have been blacklisted.
|
||||
if (blacklisted) {
|
||||
res
|
||||
.status(403)
|
||||
.type('text')
|
||||
.send(`Package "${req.packageName}" is blacklisted`)
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
},
|
||||
error => {
|
||||
console.error(error)
|
||||
|
||||
res.status(500).send({
|
||||
error: 'Unable to fetch the blacklist'
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = checkBlacklist
|
||||
|
Reference in New Issue
Block a user