...
|
...
|
@@ -44,6 +44,7 @@ exports.index = (req, res) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
const limitKey = 'limit2';
|
|
|
|
|
|
const submitValidate = {
|
|
|
errRes: {
|
...
|
...
|
@@ -54,6 +55,7 @@ const submitValidate = { |
|
|
},
|
|
|
clearLimitIp(req) {
|
|
|
let remoteIp = req.yoho.clientIp;
|
|
|
let operations = [];
|
|
|
|
|
|
if (remoteIp.indexOf(',') > 0) {
|
|
|
let arr = remoteIp.split(',');
|
...
|
...
|
@@ -61,21 +63,51 @@ const submitValidate = { |
|
|
remoteIp = arr[0];
|
|
|
}
|
|
|
|
|
|
let operations = [cache.delAsync(`${config.app}:limiter:${remoteIp}`)];
|
|
|
const isOpenApmrisk = _.get(req.app.locals, 'wap.open.apmrisk', false);
|
|
|
|
|
|
// 验证码之后一小时之内不再限制qps
|
|
|
if (req.session.apiLimitValidate || req.session.apiRiskValidate) {
|
|
|
operations.push(cache.setAsync(
|
|
|
`${config.app}:limiter:api:ishuman:${remoteIp}`,
|
|
|
1,
|
|
|
config.LIMITER_IP_TIME
|
|
|
));
|
|
|
// 新的计数
|
|
|
if (isOpenApmrisk) {
|
|
|
operations.push(cache.delAsync(`${config.app}:${limitKey}:${remoteIp}`));
|
|
|
|
|
|
if (req.session.apiLimitValidate || req.session.apiRiskValidate) {
|
|
|
operations.push(cache.setAsync(
|
|
|
`${config.app}:limiter:api:ishuman:${remoteIp}`,
|
|
|
1,
|
|
|
config.LIMITER_IP_TIME
|
|
|
));
|
|
|
} else {
|
|
|
operations.push(cache.setAsync(
|
|
|
`${config.app}:${limitKey}:ishuman:${remoteIp}`,
|
|
|
1,
|
|
|
config.LIMITER_IP_TIME
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
_.forEach(config.REQUEST_LIMIT, (val, key) => {
|
|
|
operations.push(cache.delAsync(`${config.app}:${limitKey}:${key}:max:${remoteIp}`));
|
|
|
});
|
|
|
} else {
|
|
|
operations.push(cache.setAsync(
|
|
|
`${config.app}:limiter:ishuman:${remoteIp}`,
|
|
|
1,
|
|
|
config.LIMITER_IP_TIME
|
|
|
));
|
|
|
operations.push(cache.delAsync(`${config.app}:limiter:${remoteIp}`));
|
|
|
|
|
|
// 验证码之后一小时之内不再限制qps
|
|
|
if (req.session.apiLimitValidate || req.session.apiRiskValidate) {
|
|
|
operations.push(cache.setAsync(
|
|
|
`${config.app}:limiter:api:ishuman:${remoteIp}`,
|
|
|
1,
|
|
|
config.LIMITER_IP_TIME
|
|
|
));
|
|
|
} else {
|
|
|
operations.push(cache.setAsync(
|
|
|
`${config.app}:limiter:ishuman:${remoteIp}`,
|
|
|
1,
|
|
|
config.LIMITER_IP_TIME
|
|
|
));
|
|
|
}
|
|
|
|
|
|
_.forEach(config.REQUEST_LIMIT, (val, key) => {
|
|
|
operations.push(cache.delAsync(`${config.app}:limiter:${key}:max:${remoteIp}`));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
delete req.session.apiLimitValidate;
|
...
|
...
|
@@ -87,10 +119,6 @@ const submitValidate = { |
|
|
operations.push(cache.delAsync(riskPid));
|
|
|
}
|
|
|
|
|
|
_.forEach(config.REQUEST_LIMIT, (val, key) => {
|
|
|
operations.push(cache.delAsync(`${config.app}:limiter:${key}:max:${remoteIp}`));
|
|
|
});
|
|
|
|
|
|
return Promise.all(operations);
|
|
|
},
|
|
|
geetest(req, res) {
|
...
|
...
|
@@ -135,7 +163,7 @@ const submitValidate = { |
|
|
imgCheckRisk(req, res) {
|
|
|
const self = this;
|
|
|
|
|
|
co(function * () {
|
|
|
co(function*() {
|
|
|
let result = yield req.ctx(checkModel).verifyImgCheckRisk(req.cookies.udid, req.body.captcha);
|
|
|
|
|
|
if (result.code === 200) {
|
...
|
...
|
|