|
|
/**
|
|
|
*
|
|
|
* @author: jiangfeng<jeff.jiang@yoho.cn>
|
|
|
* @date: 16/8/22
|
|
|
* @author: shijian<jian.shi@yoho.cn>
|
|
|
* @date: 17/5/31
|
|
|
*/
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const Router = require('koa-router');
|
|
|
const moment = require('moment');
|
|
|
const redisStore = require('koa-redis');
|
|
|
const redis = require("redis");
|
|
|
const client = redis.createClient();
|
|
|
const multi = client.multi();
|
|
|
|
|
|
client.on("error", function (err) {
|
|
|
console.log("Error " + err);
|
|
|
});
|
|
|
|
|
|
const {
|
|
|
OperationLogger
|
...
|
...
|
@@ -15,46 +23,46 @@ const { |
|
|
|
|
|
const r = new Router();
|
|
|
|
|
|
r.get('/', async(ctx) => {
|
|
|
await ctx.render('action/keywords');
|
|
|
});
|
|
|
|
|
|
// r.post('/log/query', async(ctx) => {
|
|
|
const setData = ()=>{
|
|
|
client.set('keywords_mana:aaa', 'aaa');
|
|
|
client.set('keywords_mana:bbb', 'bbb');
|
|
|
let arr = ['keywords_mana:aaa', 'keywords_mana:bbb'];
|
|
|
|
|
|
// let q = ctx.request.body;
|
|
|
for (var i=0; i<arr.length; i++) {
|
|
|
multi.sadd('keywords_mana_list', arr[i]);
|
|
|
}
|
|
|
|
|
|
// let start = parseInt(q.start || 0, 10);
|
|
|
// let length = parseInt(q.length || 10, 10);
|
|
|
// let draw = parseInt(q.draw, 10);
|
|
|
multi.exec(function(errors, results) {
|
|
|
|
|
|
// let sort = {time: -1};
|
|
|
// if (q.order && q.order.length > 0) {
|
|
|
// let col = q.order[0].column;
|
|
|
// let dir = q.order[0].dir === 'desc' ? -1 : 1;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// col = parseInt(col, 10);
|
|
|
// if (q.columns && q.columns.length > col) {
|
|
|
// sort = {};
|
|
|
// sort[q.columns[col].data] = dir;
|
|
|
// }
|
|
|
// }
|
|
|
const getData = async(key)=>{
|
|
|
multi.smembers(key);
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
multi.exec(function(errors, results) {
|
|
|
resolve(results);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// let logs = await OperationLogger.cfind({}).sort(sort).skip(start).limit(length).exec();
|
|
|
// let total = await OperationLogger.count();
|
|
|
r.get('/', async(ctx) => {
|
|
|
await ctx.render('action/keywords');
|
|
|
});
|
|
|
|
|
|
// logs.forEach(l => {
|
|
|
// l.username = l.user.username;
|
|
|
// l.time = moment(l.time).format('YYYY-MM-DD HH:mm:ss.sss');
|
|
|
// l.meta = JSON.stringify(l.meta || {});
|
|
|
// });
|
|
|
r.get('/getKeywords', async(ctx) => {
|
|
|
|
|
|
// ctx.body = {
|
|
|
// draw: draw,
|
|
|
// recordsTotal: total,
|
|
|
// recordsFiltered: total,
|
|
|
// data: logs
|
|
|
// };
|
|
|
let q = ctx.request.query;
|
|
|
|
|
|
let r = await getData("keywords_mana_list");
|
|
|
|
|
|
ctx.body = {
|
|
|
code: 200,
|
|
|
message: 'success',
|
|
|
data: r[0]
|
|
|
};
|
|
|
|
|
|
|
|
|
// });
|
|
|
});
|
|
|
|
|
|
module.exports = r; |
...
|
...
|
|