risk_management.js 2.09 KB
'use strict';

const Router = require('koa-router');
const ApiCache = require('../../ci/api_cache');
const _ = require('lodash');

const getter = require('../../zookeeper/getter');
const setter = require('../../zookeeper/setter');
const tester = require('../../zookeeper/tester');

let r = new Router();

const risk = {
    index: async(ctx, next) => {
        // const regexp = /pc:limiter:faker:(.*)/;
        // const threshold = ctx.request.query.threshold || 100;
        // const limit = ctx.request.query.limit || 10;

        // let hosts = await MemcachedHost.findAll();

        // const selectedHosts = _.filter(hosts, host => {
        //     const isCurrent = host.host === ctx.request.query.node;
        //     if (isCurrent) {
        //         host.isCurrent = true;
        //     }
        //     return isCurrent;
        // });

        // let results = await Promise.all(_.map(selectedHosts, (h) => {
        //     return (new ApiCache(h.host)).find((key) => {
        //         return regexp.test(key);
        //     });
        // }));

        // let list = [];

        // if (results && results[0]) {
        //     Object.keys(results[0]).forEach((key) => {
        //         const index = results[0][key];

        //         if (index > threshold) {
        //             list.push({
        //                 ip: ((key) => {
        //                     const m = key.match(regexp);

        //                     return m && m.length > 0 ? m[1] : 'Unknown';
        //                 })(key),
        //                 index: index
        //             })
        //         }
        //     });
        // }

        // list = _.orderBy(list, (item) => {
        //     return item.index;
        // }, 'desc').slice(0, limit);
        console.log(11111)

        await ctx.render('action/risk_management', {
        });
    },
    add: async(ctx, next) => {
        await ctx.render('action/add_risk', {
        });
    },
    setter: async(ctx) => {

    }
};

r.get('/risk_management', risk.index);
r.get('/add_risk', risk.add);
r.post('/add_risk_data', risk.setter);

module.exports = r;