...
|
...
|
@@ -27,12 +27,18 @@ module.exports = (limiter, policy) => { |
|
|
getOp[key] = cache.getAsync(ruleKeys[key]);
|
|
|
});
|
|
|
|
|
|
getOp.human = cache.getAsync(`${config.app}:limiter:ishuman:${limiter.remoteIp}`);
|
|
|
|
|
|
return Promise.props(getOp).then((results) => {
|
|
|
|
|
|
logger.debug(MAX_TIMES);
|
|
|
logger.debug(_.values(ruleKeys));
|
|
|
logger.debug(results);
|
|
|
|
|
|
if (results.human) { // 经过验证码之后1小时有效期内不再验证qps
|
|
|
return Promise.resolve(true);
|
|
|
}
|
|
|
|
|
|
// 遍历限制规则,若满足返回相应处理策略, 否则页面访问次数加1
|
|
|
let operation = [];
|
|
|
|
...
|
...
|
@@ -42,9 +48,10 @@ module.exports = (limiter, policy) => { |
|
|
if (!results[key]) {
|
|
|
operation.push(cache.setAsync(cacheKey, 1, +key));
|
|
|
} else if (+results[key] > +val) {
|
|
|
logger.warn(`${config.app}:limiter:${limiter.remoteIp}`);
|
|
|
|
|
|
// ip限制1小时
|
|
|
operation.push(cache.setAsync(`pc:limiter:${limiter.remoteIp}`, 1, limiterIpTime));
|
|
|
operation.push(cache.setAsync(`${config.app}:limiter:${limiter.remoteIp}`, 1, limiterIpTime));
|
|
|
return Promise.resolve(policy);
|
|
|
} else {
|
|
|
operation.push(cache.incrAsync(cacheKey, 1));
|
...
|
...
|
|