unpkg/server/BlacklistAPI.js

72 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-11-25 21:25:01 +00:00
const db = require("./RedisClient")
2017-11-11 20:18:13 +00:00
2017-11-25 21:25:01 +00:00
const BlacklistSet = "blacklisted-packages"
2017-11-11 20:18:13 +00:00
function addPackage(packageName) {
return new Promise((resolve, reject) => {
db.sadd(BlacklistSet, packageName, (error, value) => {
if (error) {
reject(error)
} else {
resolve(value === 1)
}
})
})
}
function removePackage(packageName) {
return new Promise((resolve, reject) => {
db.srem(BlacklistSet, packageName, (error, value) => {
if (error) {
reject(error)
} else {
resolve(value === 1)
}
})
})
}
function removeAllPackages() {
return new Promise((resolve, reject) => {
db.del(BlacklistSet, error => {
if (error) {
reject(error)
} else {
resolve()
}
})
})
}
function getPackages() {
return new Promise((resolve, reject) => {
db.smembers(BlacklistSet, (error, value) => {
if (error) {
reject(error)
} else {
resolve(value)
}
})
})
}
2017-11-12 06:35:30 +00:00
function includesPackage(packageName) {
2017-11-11 20:18:13 +00:00
return new Promise((resolve, reject) => {
db.sismember(BlacklistSet, packageName, (error, value) => {
if (error) {
reject(error)
} else {
resolve(value === 1)
}
})
})
}
module.exports = {
addPackage,
removePackage,
removeAllPackages,
getPackages,
2017-11-12 06:35:30 +00:00
includesPackage
2017-11-11 20:18:13 +00:00
}