|
|
'use strict';
|
|
|
|
|
|
const cache = global.yoho.cache.master;
|
|
|
const _ = require('lodash');
|
|
|
const logger = global.yoho.logger;
|
|
|
const config = global.yoho.config;
|
|
|
|
|
|
module.exports = (limiter, policy) => {
|
|
|
// 和pc共用
|
|
|
const key = `pc:limiter:${limiter.remoteIp}`;
|
|
|
const ipBlackKey = `pc:limiter:${limiter.remoteIp}`; // ci ip黑名单
|
|
|
const ipLimitKey = `${config.app}:limiter:${limiter.remoteIp}`; // 业务黑名单
|
|
|
|
|
|
return cache.getAsync(key).then((result) => {
|
|
|
logger.debug(key, result);
|
|
|
return Promise.all([
|
|
|
cache.getAsync(ipBlackKey),
|
|
|
cache.getAsync(ipLimitKey)
|
|
|
]).then(result => {
|
|
|
let ipBlackRes = result[0];
|
|
|
let ipLimitRes = result[1];
|
|
|
|
|
|
if (result && _.isNumber(result) && result !== -1) {
|
|
|
logger.debug(ipBlackKey, ipBlackRes);
|
|
|
logger.debug(ipLimitKey, ipLimitRes);
|
|
|
|
|
|
if ((ipBlackRes && +ipBlackRes > 0) || (ipLimitRes && +ipLimitRes > 0)) {
|
|
|
return Promise.resolve(policy);
|
|
|
} else {
|
|
|
return Promise.resolve(true);
|
...
|
...
|
|