ip.js 766 Bytes
const cache = global.yoho.cache.master;
const logger = global.yoho.logger;

const {limitKey} = require('./vars');

module.exports = async({user}, next) => {
    const ipBlackKey = `pc:limiter:${user.ip}`; // ci ip黑名单
    const ipLimitKey = `${user.appType}:${limitKey}:${user.ip}`; // 业务黑名单

    const result = await Promise.all([
        cache.getAsync(ipBlackKey),
        cache.getAsync(ipLimitKey)
    ]);

    let ipBlackRes = result[0];
    let ipLimitRes = result[1];

    logger.debug('ip==>%s value=%d', ipBlackKey, ipBlackRes || 0);
    logger.debug('ip==>%s value=%d', ipLimitKey, ipLimitRes || 0);

    if ((ipBlackRes && +ipBlackRes > 0) || (ipLimitRes && +ipLimitRes > 0)) {
        return;
    } else {
        return next();
    }
};