Authored by 周少峰

tdk add

'use strict';
const Router = require('koa-router');
const _ = require('lodash');
let r = new Router();
const tdk = {
// tdk 列表
index: async(ctx, next) => {
await ctx.render('action/seo_tdk', {title: 'TDK管理'});
},
// 添加tdk
add: async(ctx, next) => {
let result = {code: 500, message: '非法参数'},
typeList = ['skn', 'article', 'shop', 'url'];
// skn, article, shop, url
let type = ctx.request.body.type,
val = ctx.request.body.val,
title = ctx.request.body.title || '',
keywords = ctx.request.body.keywords,
description = ctx.request.body.description;
// type 不合法, 返回错误
if (!_.find(typeList, type)) {
ctx.response.body = result;
}
ctx.redis.multi([
["lpush", `tdk:${type}:links`, val],
["hmset", `tdk:${type}:${val}`, "title", title, "keywords", keywords, "description", description]
]).execAsync().then(function(res) {
Object.assign(result, {code:200, message: 'success'})
});
ctx.response.body = result;
}
};
r.get('/', tdk.index);
r.get('/tdk', tdk.index);
r.get('/tdk/add', tdk.add);
module.exports = r;
... ...
... ... @@ -12,6 +12,7 @@ const helpers = require('../../lib/helpers');
const routers = require('./routers');
const collectData = require('./actions/collect_data');
const checkcode = require('./actions/checkcode');
const redis = require('../../lib/redis');
const app = new Koa();
... ... @@ -38,6 +39,8 @@ checkcode.check();
collectData.collect();
app.use(async(ctx, next) => {
ctx.redis = redis.client;
ctx.locals = {
title: 'Yoho Node.js 持续集成平台'
};
... ...
... ... @@ -19,6 +19,7 @@ const deploy = require('./actions/deploy');
const api = require('./actions/api');
const abuseProtection = require('./actions/abuse_protection');
const crawler = require('./actions/crawler');
const seo = require('./actions/seo');
const checkcode = require('./actions/checkcode').router;
const noAuth = new Router();
const base = new Router();
... ... @@ -60,6 +61,7 @@ module.exports = function(app) {
base.use('/crawler_black', black.routes(), black.allowedMethods());
base.use('/abuse_protection', abuseProtection.routes(), degrade.allowedMethods());
base.use('/seo', seo.routes(), seo.allowedMethods());
base.use('', index.routes(), index.allowedMethods());
... ...
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
<li><a href="">Hotfix</a></li>
<li>{{type}}</li>
</ul>
<h4>{{title}}</h4>
</div>
</div>
<!-- media -->
</div>
<!-- pageheader -->
<div class="contentpanel">
<div class="panel panel-primary-head">
<div class="panel-heading">
<div class="pull-right">
<a id="new-page" href="/hotfix/new/{{type}}" class="btn btn-success btn-rounded"><i class="glyphicon glyphicon-plus"></i> 新增Hotfix</a>
</div>
<h4 class="panel-title">{{type}} hotfix</h4>
<p>&nbsp;</p>
</div>
<!-- panel-heading -->
<table id="table-hotfixs" class="table table-striped table-bordered responsive">
<thead class="">
<tr>
<th>ID</th>
<th>类型</th>
<th>标题</th>
<th>关键词</th>
<th>描述</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{{#each hotfixs}}
<tr>
<td>{{id}}</td>
<td>{{type}}</td>
<td>{{title}}</td>
<td>{{keywords}}</td>
<td>{{description}}</td>
<td>{{operate}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
<!-- panel -->
</div>
\ No newline at end of file
... ...
... ... @@ -66,6 +66,7 @@
<li><a href="/check/list">代码检查</a></li>
</ul>
</li>
<li><a href="/seo/tdk"><i class="fa fa-list"></i> <span>TDK管理</span></a></li>
{{/if}}
</ul>
... ...
... ... @@ -11,6 +11,13 @@ const defaults = {
influxdb: {
host: 'influxdblog.web.yohoops.org',
port: 4444
},
redis: {
connect: {
host: '127.0.0.1',
port: '6379',
//password: ''
}
}
};
... ...
const redis = require('redis');
const bluebird = require('bluebird');
const config = require('../config/config');
const client = redis.createClient(config.redis.connect);
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
module.exports = {
client
}
\ No newline at end of file
... ...
... ... @@ -25,7 +25,7 @@
"author": "jiangfeng <jeff.jiang@yoho.cn>",
"license": "ISC",
"dependencies": {
"bluebird": "^3.4.1",
"bluebird": "^3.5.0",
"co": "^4.6.0",
"co-body": "^4.2.0",
"formidable": "^1.0.17",
... ... @@ -57,11 +57,15 @@
"qcloudapi-sdk": "^0.1.5",
"qn": "^1.3.0",
"qs": "^6.2.0",
"redis": "^2.7.1",
"request-promise": "^4.1.1",
"shelljs": "^0.7.0",
"socket.io": "^1.4.6",
"ssh2": "^0.5.4",
"tar": "^2.2.1",
"utility": "^1.8.0"
},
"devDependencies": {
"nodemon": "^1.11.0"
}
}
... ...