Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var rate_limit_check = function(){
// too bad SETNX counts as a write operation even when it doesn't write.
// that's why I can't just use redis' EXPIRE command
var lock_key = 'lock:'+remote_addr;
var t = (new Date()).getTime();
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();
}
});
};
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);
});
}();
});