Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
findById: function(id, use, callback) {
if (callback) {
redis.get('aliases:' + id, function(data) {
if (!data) {
callback(null);
return;
}
helpers.extend(ad = new Alias(), JSON.parse(""+data));
if (use){
ad.use(function(valid){
callback(valid ? ad : null);
})
}else{
if (ad.max_usage){
redis.get('counter:'+ad.aid, function(data){
var cb = (parseInt(data, 10) > 0) ? ad : null;
callback(cb);
});
(function(lockset){
redis.get(lockset, function(exp){
gc++;
if (exp < (new Date()).getTime()){
garbage.unshift(lockset);
}
if (gc >= locks.length){
if (garbage.length > 0){
sys.puts("Pruning: "+garbage.join(', '));
garbage[garbage.length] = function(data){
sys.puts(data + ' sets removed');
redis.close();
};
redis.del.apply(redis, garbage);
}else{
sys.puts('No rate locks to prune');
redis.close();
}
function getNextId(callback) {
var len = 3, c = "";
redis.get('admin:keylength', function(data){
len = data || len;
var uuidg = function uuidg() {
len++;
var id = UUID.uuid(len);
redis.setnx('reservations:' + id, 'reserved', function(data) {
if (parseInt(""+data, 10) == 0) {
redis.set('admin:keylength', len, function(data){
uuidg();
});
}
callback(id);
});
}();
});
}
return {
redis.setnx(lock_key, t+config.http.rate_limit, function(lr){
if (!lr){
redis.get(lock_key, function(exp){
if (parseInt(exp, 10) < (t)){
redis.set(lock_key, t+config.http.rate_limit, function(){
rbl_check();
});
}else{
err(403, {error: 'rate-limited', description: 'please wait a moment before generating the next alias'});
}
});
}else{
rbl_check();
}
});
};