2017-09-03 08:43:13 +08:00
|
|
|
const koaRouter = require('koa-router');
|
|
|
|
const interfaceController = require('./controllers/interface.js');
|
|
|
|
const groupController = require('./controllers/group.js');
|
|
|
|
const userController = require('./controllers/user.js');
|
|
|
|
const interfaceColController = require('./controllers/interfaceCol.js');
|
2017-09-14 17:14:01 +08:00
|
|
|
const testController = require('./controllers/test.js');
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-09-03 08:43:13 +08:00
|
|
|
const yapi = require('./yapi.js');
|
|
|
|
const projectController = require('./controllers/project.js');
|
|
|
|
const logController = require('./controllers/log.js');
|
|
|
|
const followController = require('./controllers/follow.js');
|
2017-11-15 12:37:23 +08:00
|
|
|
const { createAction } = require("./utils/commons.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-09-17 13:36:51 +08:00
|
|
|
let INTERFACE_CONFIG = {
|
2017-11-15 12:37:23 +08:00
|
|
|
interface: {
|
|
|
|
prefix: '/interface/',
|
|
|
|
controller: interfaceController
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
prefix: '/user/',
|
|
|
|
controller: userController
|
|
|
|
},
|
|
|
|
group: {
|
|
|
|
prefix: '/group/',
|
|
|
|
controller: groupController
|
|
|
|
},
|
|
|
|
project: {
|
|
|
|
prefix: '/project/',
|
|
|
|
controller: projectController
|
|
|
|
},
|
|
|
|
log: {
|
|
|
|
prefix: '/log/',
|
|
|
|
controller: logController
|
2017-08-09 16:16:35 +08:00
|
|
|
},
|
2017-08-10 12:13:32 +08:00
|
|
|
follow: {
|
2017-11-15 12:37:23 +08:00
|
|
|
prefix: '/follow/',
|
|
|
|
controller: followController
|
2017-08-10 12:13:32 +08:00
|
|
|
},
|
2017-08-09 16:16:35 +08:00
|
|
|
col: {
|
|
|
|
prefix: '/col/',
|
|
|
|
controller: interfaceColController
|
2017-09-14 17:14:01 +08:00
|
|
|
},
|
|
|
|
test: {
|
|
|
|
prefix: '/test/',
|
|
|
|
controller: testController
|
2017-08-09 16:16:35 +08:00
|
|
|
}
|
2017-07-03 16:16:05 +08:00
|
|
|
};
|
|
|
|
|
2017-09-17 13:36:51 +08:00
|
|
|
let routerConfig = {
|
2017-08-08 14:45:19 +08:00
|
|
|
"group": [
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "list",
|
|
|
|
"path": "list",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "add",
|
|
|
|
"path": "add",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "up",
|
|
|
|
"path": "up",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "del",
|
|
|
|
"path": "del",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "addMember",
|
|
|
|
"path": "add_member",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-15 17:55:52 +08:00
|
|
|
{
|
|
|
|
"action": "changeMemberRole",
|
|
|
|
"path": "change_member_role",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "delMember",
|
|
|
|
"path": "del_member",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "getMemberList",
|
2017-08-15 17:55:52 +08:00
|
|
|
"path": "get_member_list",
|
2017-08-08 14:45:19 +08:00
|
|
|
"method": "get"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-16 17:13:14 +08:00
|
|
|
action: 'get',
|
|
|
|
path: 'get',
|
|
|
|
method: 'get'
|
2017-08-08 14:45:19 +08:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"user": [
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "login",
|
|
|
|
"path": "login",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "reg",
|
|
|
|
"path": "reg",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "list",
|
|
|
|
"path": "list",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "findById",
|
|
|
|
"path": "find",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "update",
|
|
|
|
"path": "update",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "del",
|
|
|
|
"path": "del",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "getLoginStatus",
|
|
|
|
"path": "status",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "logout",
|
|
|
|
"path": "logout",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "loginByToken",
|
|
|
|
"path": "login_by_token",
|
2017-10-20 17:52:10 +08:00
|
|
|
"method": "all"
|
2017-12-11 11:44:21 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"action": "getLdapAuth",
|
|
|
|
"path": "login_by_ldap",
|
|
|
|
"method": "all"
|
2017-08-08 14:45:19 +08:00
|
|
|
},
|
2017-09-28 15:59:11 +08:00
|
|
|
{
|
|
|
|
action: 'upStudy',
|
|
|
|
path: 'up_study',
|
|
|
|
method: 'get'
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "changePassword",
|
|
|
|
"path": "change_password",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "search",
|
|
|
|
"path": "search",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-10 18:54:32 +08:00
|
|
|
"action": "project",
|
|
|
|
"path": "project",
|
2017-08-08 14:45:19 +08:00
|
|
|
"method": "get"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-10 15:22:42 +08:00
|
|
|
"action": "avatar",
|
|
|
|
"path": "avatar",
|
|
|
|
"method": "get"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-10 15:22:42 +08:00
|
|
|
action: "uploadAvatar",
|
|
|
|
path: "upload_avatar",
|
|
|
|
method: "post"
|
2017-08-08 14:45:19 +08:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"project": [
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-22 11:23:00 +08:00
|
|
|
"action": "upSet",
|
|
|
|
"path": "upset",
|
|
|
|
"method": "post"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "add",
|
|
|
|
"path": "add",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "list",
|
|
|
|
"path": "list",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "get",
|
|
|
|
"path": "get",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "up",
|
|
|
|
"path": "up",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "del",
|
|
|
|
"path": "del",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "addMember",
|
|
|
|
"path": "add_member",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "delMember",
|
|
|
|
"path": "del_member",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-18 17:08:37 +08:00
|
|
|
{
|
|
|
|
"action": "changeMemberRole",
|
|
|
|
"path": "change_member_role",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "getMemberList",
|
|
|
|
"path": "get_member_list",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "search",
|
|
|
|
"path": "search",
|
|
|
|
"method": "get"
|
2017-08-10 10:24:24 +08:00
|
|
|
},
|
2017-08-18 17:08:37 +08:00
|
|
|
{
|
2017-09-22 12:08:23 +08:00
|
|
|
"action": "upEnv",
|
|
|
|
"path": "up_env",
|
|
|
|
"method": "post"
|
2017-08-08 14:45:19 +08:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"interface": [
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "add",
|
|
|
|
"path": "add",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-09-29 14:58:07 +08:00
|
|
|
{
|
|
|
|
"action": "downloadCrx",
|
2017-11-15 12:37:23 +08:00
|
|
|
"path": "download_crx",
|
2017-09-29 14:58:07 +08:00
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-31 17:26:09 +08:00
|
|
|
{
|
|
|
|
"action": "getCatMenu",
|
|
|
|
"path": "getCatMenu",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "list",
|
|
|
|
"path": "list",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "get",
|
|
|
|
"path": "get",
|
|
|
|
"method": "get"
|
|
|
|
},
|
2017-08-10 10:24:24 +08:00
|
|
|
{
|
2017-08-08 14:45:19 +08:00
|
|
|
"action": "up",
|
|
|
|
"path": "up",
|
|
|
|
"method": "post"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"action": "del",
|
|
|
|
"path": "del",
|
|
|
|
"method": "post"
|
2017-08-18 20:35:31 +08:00
|
|
|
},
|
2017-08-31 17:26:09 +08:00
|
|
|
{
|
|
|
|
"action": "interUpload",
|
|
|
|
"path": "interUpload",
|
|
|
|
"method": "post"
|
|
|
|
},
|
2017-08-18 20:35:31 +08:00
|
|
|
{
|
|
|
|
action: 'listByCat',
|
|
|
|
path: 'list_cat',
|
|
|
|
method: 'get'
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-18 20:35:31 +08:00
|
|
|
action: 'listByMenu',
|
|
|
|
path: 'list_menu',
|
|
|
|
method: 'get'
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-18 20:35:31 +08:00
|
|
|
action: 'addCat',
|
|
|
|
path: 'add_cat',
|
|
|
|
method: 'post'
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-18 20:35:31 +08:00
|
|
|
action: 'upCat',
|
|
|
|
path: 'up_cat',
|
|
|
|
method: 'post'
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-18 20:35:31 +08:00
|
|
|
action: 'delCat',
|
|
|
|
path: 'del_cat',
|
|
|
|
method: 'post'
|
2017-12-27 21:12:10 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'getCustomField',
|
|
|
|
path: 'get_custom_field',
|
|
|
|
method: 'get'
|
2018-01-22 17:26:05 +08:00
|
|
|
},
|
|
|
|
{
|
2018-01-23 10:24:51 +08:00
|
|
|
action: 'save',
|
|
|
|
path: 'save',
|
2018-01-22 17:26:05 +08:00
|
|
|
method: 'post'
|
|
|
|
}
|
2017-08-08 14:45:19 +08:00
|
|
|
],
|
|
|
|
"log": [
|
|
|
|
{
|
|
|
|
"action": "list",
|
|
|
|
"path": "list",
|
|
|
|
"method": "get"
|
2018-01-24 19:59:20 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"action": "listByUpdate",
|
|
|
|
"path": "list_by_update",
|
|
|
|
"method": "post"
|
|
|
|
}
|
2017-08-09 16:16:35 +08:00
|
|
|
],
|
2017-08-10 12:13:32 +08:00
|
|
|
"follow": [{
|
|
|
|
"action": "list",
|
|
|
|
"path": "list",
|
|
|
|
"method": "get"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-10 12:13:32 +08:00
|
|
|
"action": "add",
|
|
|
|
"path": "add",
|
|
|
|
"method": "post"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-10 12:13:32 +08:00
|
|
|
"action": "del",
|
|
|
|
"path": "del",
|
|
|
|
"method": "post"
|
|
|
|
}],
|
2017-08-09 16:16:35 +08:00
|
|
|
"col": [{
|
2017-08-09 20:01:51 +08:00
|
|
|
action: "addCol",
|
|
|
|
path: "add_col",
|
2017-08-09 16:16:35 +08:00
|
|
|
method: "post"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-09-29 14:58:07 +08:00
|
|
|
action: 'addCaseList',
|
|
|
|
path: 'add_case_list',
|
2017-11-15 12:37:23 +08:00
|
|
|
method: 'post'
|
|
|
|
|
2017-12-08 16:23:10 +08:00
|
|
|
}, {
|
|
|
|
action: 'cloneCaseList',
|
|
|
|
path: 'clone_case_list',
|
|
|
|
method: 'post'
|
|
|
|
|
2017-08-09 16:16:35 +08:00
|
|
|
}, {
|
|
|
|
action: "list",
|
|
|
|
path: "list",
|
|
|
|
method: "get"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-09 20:01:51 +08:00
|
|
|
action: "getCaseList",
|
|
|
|
path: "case_list",
|
|
|
|
method: "get"
|
2017-11-23 15:25:46 +08:00
|
|
|
}, {
|
|
|
|
action: "getCaseListByVariableParams",
|
|
|
|
path: "case_list_by_var_params",
|
|
|
|
method: "get"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-09 20:01:51 +08:00
|
|
|
action: "addCase",
|
|
|
|
path: "add_case",
|
|
|
|
method: "post"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-24 10:33:17 +08:00
|
|
|
action: "upCase",
|
|
|
|
path: "up_case",
|
|
|
|
method: "post"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-09 20:01:51 +08:00
|
|
|
action: "getCase",
|
|
|
|
path: "case",
|
|
|
|
method: "get"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-09 20:01:51 +08:00
|
|
|
action: "upCol",
|
|
|
|
path: "up_col",
|
|
|
|
method: "post"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-09 20:01:51 +08:00
|
|
|
action: "upCaseIndex",
|
|
|
|
path: "up_col_index",
|
|
|
|
method: "post"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-09 20:01:51 +08:00
|
|
|
action: "delCol",
|
|
|
|
path: "del_col",
|
2017-08-22 18:05:20 +08:00
|
|
|
method: "get"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-08-09 20:01:51 +08:00
|
|
|
action: "delCase",
|
|
|
|
path: "del_case",
|
2017-08-22 18:05:20 +08:00
|
|
|
method: "get"
|
2017-11-15 12:37:23 +08:00
|
|
|
}, {
|
2017-10-24 15:58:38 +08:00
|
|
|
action: "runCaseScript",
|
|
|
|
path: "run_script",
|
|
|
|
method: "post"
|
2017-08-09 20:01:51 +08:00
|
|
|
}
|
2017-09-14 17:14:01 +08:00
|
|
|
],
|
|
|
|
"test": [{
|
|
|
|
action: "testPost",
|
|
|
|
path: "post",
|
|
|
|
method: "post"
|
|
|
|
}, {
|
|
|
|
action: "testGet",
|
|
|
|
path: "get",
|
|
|
|
method: "get"
|
|
|
|
}, {
|
|
|
|
action: "testPut",
|
|
|
|
path: "put",
|
|
|
|
method: "put"
|
|
|
|
}, {
|
|
|
|
action: "testDelete",
|
|
|
|
path: "delete",
|
|
|
|
method: "del"
|
|
|
|
}, {
|
|
|
|
action: "testHead",
|
|
|
|
path: "head",
|
|
|
|
method: "head"
|
|
|
|
}, {
|
|
|
|
action: "testOptions",
|
|
|
|
path: "options",
|
|
|
|
method: "options"
|
|
|
|
}, {
|
|
|
|
action: "testPatch",
|
|
|
|
path: "patch",
|
|
|
|
method: "patch"
|
|
|
|
}, {
|
|
|
|
action: "testFilesUpload",
|
|
|
|
path: "files/upload",
|
|
|
|
method: "post"
|
|
|
|
}, {
|
|
|
|
action: "testSingleUpload",
|
|
|
|
path: "single/upload",
|
|
|
|
method: "post"
|
2017-11-21 20:02:58 +08:00
|
|
|
}, {
|
|
|
|
action: "testHttpCode",
|
|
|
|
path: "http/code",
|
|
|
|
method: "post"
|
|
|
|
}
|
2017-12-08 16:23:10 +08:00
|
|
|
]
|
2017-08-08 14:45:19 +08:00
|
|
|
}
|
2017-07-06 18:25:53 +08:00
|
|
|
|
2017-09-17 13:36:51 +08:00
|
|
|
let pluginsRouterPath = [];
|
|
|
|
|
2017-11-15 12:37:23 +08:00
|
|
|
function addPluginRouter(config) {
|
|
|
|
if (!config.path || !config.controller || !config.action) {
|
2017-09-17 13:36:51 +08:00
|
|
|
throw new Error('Plugin Route config Error');
|
|
|
|
}
|
|
|
|
let method = config.method || 'GET';
|
|
|
|
let routerPath = '/plugin/' + config.path;
|
2017-11-15 12:37:23 +08:00
|
|
|
if (pluginsRouterPath.indexOf(routerPath) > -1) {
|
2017-09-17 13:36:51 +08:00
|
|
|
throw new Error('Plugin Route path conflict, please try rename the path')
|
|
|
|
}
|
|
|
|
pluginsRouterPath.push(routerPath);
|
2017-12-08 16:23:10 +08:00
|
|
|
createAction(router, "/api", config.controller, config.action, routerPath, method, false);
|
2017-09-17 13:36:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
yapi.emitHookSync('add_router', addPluginRouter);
|
|
|
|
|
2017-11-15 12:37:23 +08:00
|
|
|
for (let ctrl in routerConfig) {
|
|
|
|
let actions = routerConfig[ctrl];
|
|
|
|
actions.forEach((item) => {
|
|
|
|
let routerController = INTERFACE_CONFIG[ctrl].controller;
|
|
|
|
let routerPath = INTERFACE_CONFIG[ctrl].prefix + item.path;
|
|
|
|
createAction(router, "/api", routerController, item.action, routerPath, item.method);
|
|
|
|
})
|
2017-08-10 10:24:24 +08:00
|
|
|
}
|
2017-07-20 19:21:46 +08:00
|
|
|
|
2017-10-10 18:03:09 +08:00
|
|
|
|
2017-08-11 10:25:19 +08:00
|
|
|
|
2017-08-10 10:24:24 +08:00
|
|
|
module.exports = router;
|