Add support for scoped packages in blacklist URLs

This commit is contained in:
MICHAEL JACKSON
2017-11-14 16:47:57 -08:00
parent 4e31fd02cf
commit 36efac099f
4 changed files with 69 additions and 27 deletions

View File

@ -2,17 +2,7 @@ const validateNpmPackageName = require('validate-npm-package-name')
const BlacklistAPI = require('../BlacklistAPI')
function removeFromBlacklist(req, res) {
const packageName = req.params.packageName
const nameErrors = validateNpmPackageName(packageName).errors
// Disallow invalid package names.
if (nameErrors) {
const reason = nameErrors.join(', ')
return res.status(403).send({
error: `Invalid package name "${packageName}" (${reason})`
})
}
const packageName = req.packageName
BlacklistAPI.removePackage(packageName).then(
removed => {
@ -25,13 +15,14 @@ function removeFromBlacklist(req, res) {
res.send({
ok: true,
message: `Package "${packageName}" was ${removed
? 'removed from'
: 'not in'} the blacklist`
message: `Package "${packageName}" was ${
removed ? 'removed from' : 'not in'
} the blacklist`
})
},
error => {
console.error(error)
res.status(500).send({
error: `Unable to remove "${packageName}" from the blacklist`
})