robot-check-service.js 971 Bytes
'use strict';

const cache = global.yoho.cache.master;
const Promise = require('bluebird');
const co = Promise.coroutine;
const config = global.yoho.config;
const _ = require('lodash');
const humanExpire = 60;

const HeaderModel = require('../../../doraemon/models/header');

const index = co(function* (channel) {
    const header = yield HeaderModel.requestHeaderData(channel);

    return {
        headerData: header.headerData
    };
});

const removeBlack = (remoteIp) => {
    let operations = [];

    operations.push(cache.delAsync(`${config.app}:limiter:${remoteIp}`));

    // 验证码之后一小时之内不再限制qps
    operations.push(cache.setAsync(`${config.app}:limiter:ishuman:${remoteIp}`, 1, humanExpire));
    _.forEach(config.REQUEST_LIMIT, (val, key) => {
        operations.push(cache.delAsync(`${config.app}:limiter:${key}:max:${remoteIp}`));
    });

    return Promise.all(operations);
};

module.exports = {
    index,
    removeBlack
};