2017-07-26 22:03:18 +08:00
|
|
|
import koaRouter from 'koa-router';
|
|
|
|
import interfaceController from './controllers/interface.js';
|
|
|
|
import groupController from './controllers/group.js';
|
|
|
|
import userController from './controllers/user.js';
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
import yapi from './yapi.js';
|
|
|
|
import projectController from './controllers/project.js';
|
|
|
|
import logController from './controllers/log.js';
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-04 16:43:07 +08:00
|
|
|
const router = koaRouter();
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
const INTERFACE_CONFIG = {
|
|
|
|
interface: {
|
|
|
|
prefix: '/interface/',
|
|
|
|
controller: interfaceController
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
prefix: '/user/',
|
2017-07-06 18:25:53 +08:00
|
|
|
controller: userController
|
2017-07-05 16:17:58 +08:00
|
|
|
},
|
|
|
|
group: {
|
|
|
|
prefix: '/group/',
|
|
|
|
controller: groupController
|
2017-07-06 19:21:54 +08:00
|
|
|
},
|
|
|
|
project: {
|
|
|
|
prefix: '/project/',
|
|
|
|
controller: projectController
|
2017-07-20 19:21:46 +08:00
|
|
|
},
|
2017-07-20 20:30:24 +08:00
|
|
|
log: {
|
|
|
|
prefix: '/log/',
|
|
|
|
controller: logController
|
2017-07-05 16:17:58 +08:00
|
|
|
}
|
2017-07-03 16:16:05 +08:00
|
|
|
};
|
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
//group
|
2017-07-26 22:03:18 +08:00
|
|
|
createAction('group', 'list', 'get', 'list');
|
|
|
|
createAction('group', 'add', 'post', 'add');
|
|
|
|
createAction('group', 'up', 'post', 'up');
|
|
|
|
createAction('group', 'del', 'post', 'del');
|
2017-07-05 16:17:58 +08:00
|
|
|
|
2017-07-06 19:56:45 +08:00
|
|
|
//user
|
2017-07-26 22:03:18 +08:00
|
|
|
createAction('user', 'login', 'post', 'login');
|
|
|
|
createAction('user', 'reg', 'post', 'reg');
|
|
|
|
createAction('user', 'list', 'get', 'list');
|
|
|
|
createAction('user', 'find', 'get', 'findById');
|
|
|
|
createAction('user', 'update', 'post', 'update');
|
|
|
|
createAction('user', 'del', 'post', 'del');
|
|
|
|
createAction('user', 'status', 'get', 'getLoginStatus');
|
|
|
|
createAction('user', 'logout', 'get', 'logout');
|
|
|
|
createAction('user', 'login_by_token', 'post', 'loginByToken');
|
|
|
|
createAction('user', 'change_password', 'post', 'changePassword');
|
|
|
|
createAction('user', 'search', 'get', 'search');
|
2017-07-06 19:56:45 +08:00
|
|
|
|
2017-07-06 19:48:25 +08:00
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
//project
|
2017-07-26 22:03:18 +08:00
|
|
|
createAction('project', 'add', 'post', 'add');
|
|
|
|
createAction('project', 'list', 'get', 'list');
|
|
|
|
createAction('project', 'get', 'get', 'get');
|
|
|
|
createAction('project', 'up', 'post', 'up');
|
|
|
|
createAction('project', 'del', 'post', 'del');
|
|
|
|
createAction('project', 'add_member', 'post', 'addMember');
|
|
|
|
createAction('project', 'del_member', 'post', 'delMember');
|
|
|
|
createAction('project', 'get_member_list', 'get', 'getMemberList');
|
|
|
|
createAction('project', 'search', 'get', 'search');
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
|
|
//interface
|
2017-07-26 22:03:18 +08:00
|
|
|
createAction('interface', 'add', 'post', 'add');
|
|
|
|
createAction('interface', 'list', 'get', 'list');
|
|
|
|
createAction('interface', 'get', 'get', 'get');
|
|
|
|
createAction('interface', 'up', 'post', 'up');
|
|
|
|
createAction('interface', 'del', 'post', 'del');
|
2017-07-06 18:25:53 +08:00
|
|
|
|
2017-07-20 19:21:46 +08:00
|
|
|
//node
|
2017-07-20 20:30:24 +08:00
|
|
|
createAction('log', 'list', 'get', 'list');
|
2017-07-20 19:21:46 +08:00
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
/**
|
2017-07-06 01:09:33 +08:00
|
|
|
*
|
2017-07-05 16:17:58 +08:00
|
|
|
* @param {*} controller controller_name
|
|
|
|
* @param {*} path request_path
|
|
|
|
* @param {*} method request_method , post get put delete ...
|
|
|
|
* @param {*} action controller_action_name
|
|
|
|
*/
|
2017-07-26 22:03:18 +08:00
|
|
|
function createAction(controller, path, method, action) {
|
2017-07-05 16:17:58 +08:00
|
|
|
router[method](INTERFACE_CONFIG[controller].prefix + path, async (ctx) => {
|
2017-07-10 11:59:13 +08:00
|
|
|
let inst = new INTERFACE_CONFIG[controller].controller(ctx);
|
2017-07-26 22:03:18 +08:00
|
|
|
|
2017-07-11 12:12:43 +08:00
|
|
|
await inst.init(ctx);
|
2017-07-26 22:03:18 +08:00
|
|
|
|
|
|
|
if (inst.$auth === true) {
|
2017-07-11 12:12:43 +08:00
|
|
|
await inst[action].call(inst, ctx);
|
2017-07-26 22:03:18 +08:00
|
|
|
} else {
|
2017-07-11 12:12:43 +08:00
|
|
|
ctx.body = yapi.commons.resReturn(null, 400, 'Without Permission.');
|
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
|
|
|
|
});
|
2017-07-06 01:09:33 +08:00
|
|
|
}
|
2017-07-05 16:17:58 +08:00
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
module.exports = router;
|