解决冲突

This commit is contained in:
waliang.wang 2017-07-26 16:29:13 +08:00
commit cc0428efde
30 changed files with 632 additions and 388 deletions

View File

@ -46,16 +46,17 @@ export default class App extends Component {
<HashRouter>
<div className="router-main">
<Header />
<Route path="/" component={Home} exact />
{/*<Route exact path="/group" component={ requireAuthentication(ProjectGroups) } ></Route>*/}
<Switch>
<Redirect exact from='/group' to='/group/1' />
<Route exact path="/group/:groupName" component={ requireAuthentication(ProjectGroups) } />
</Switch>
<Route path="/Interface" component={requireAuthentication(Interface)} />
<Route path="/user" component={requireAuthentication(User)} />
<Route path="/News" component={requireAuthentication(News)} />
<Route path="/AddInterface" component={ requireAuthentication(AddInterface) } />
<div className="router-container">
<Route path="/" component={Home} exact />
<Switch>
<Redirect exact from='/group' to='/group/1' />
<Route exact path="/group/:groupName" component={ requireAuthentication(ProjectGroups) } />
</Switch>
<Route path="/Interface" component={requireAuthentication(Interface)} />
<Route path="/user" component={requireAuthentication(User)} />
<Route path="/News" component={requireAuthentication(News)} />
<Route path="/AddInterface" component={ requireAuthentication(AddInterface) } />
</div>
<Footer/>
</div>
</HashRouter>

View File

@ -11,12 +11,16 @@ import Srch from './Search/Search'
const { Header } = Layout;
const MenuUser = (props) => (
<Menu>
<Menu.Item key="0">
<Link to={`/user/profile/${props.uid}`} onClick={props.relieveLink}><Icon type="user" />{ props.user }</Link>
<Menu
style={{
"boxShadow":"0 1px 6px rgba(0, 0, 0, 0.3)"
}}
>
<Menu.Item key="0" style={{"fontSize": ".14rem"}}>
<Link to={`/user/profile/${props.uid}`} onClick={props.relieveLink}><Icon type="user"/>个人中心</Link>
</Menu.Item>
<Menu.Item key="1">
<a onClick={props.logout}>退出</a>
<Menu.Item key="1" style={{"fontSize": ".14rem"}}>
<a onClick={props.logout}><Icon type="logout" />退出</a>
</Menu.Item>
</Menu>
);
@ -34,17 +38,19 @@ const ToolUser = (props)=> (
<Srch groupList={props.groupList}/>
</li>
<li className="toolbar-li">
<Dropdown overlay={
<MenuUser
user={props.user}
msg={props.msg}
uid={props.uid}
relieveLink={props.relieveLink}
logout={props.logout}
/>
<Dropdown
placement = "bottomRight"
overlay={
<MenuUser
user={props.user}
msg={props.msg}
uid={props.uid}
relieveLink={props.relieveLink}
logout={props.logout}
/>
}>
<a className="dropdown-link">
<Icon type="user"/>
<Icon type="solution" />
</a>
</Dropdown>
</li>
@ -119,40 +125,48 @@ class HeaderCom extends Component {
}
render () {
const { login, user, msg, uid, curKey } = this.props;
const headerStyle = {
'background': 'url(./image/bg-img.jpg) no-repeat center',
'backgroundSize':'cover'
}
return (
<acticle className="header-box">
<Layout className="layout">
<Header>
<div className="content">
<div className="logo">
<Link to="/" onClick={this.relieveLink}>YAPI</Link>
</div>
<Menu
mode="horizontal"
className="nav-toolbar"
theme="dark"
style={{ lineHeight : '.64rem'}}
onClick={this.linkTo}
selectedKeys={[curKey]}
>
<Menu.Item key="/group">
<Link to="/group">项目广场</Link>
</Menu.Item>
</Menu>
<div className="user-toolbar">
{login?
<ToolUser
user = { user }
msg = { msg }
uid = { uid }
relieveLink = { this.relieveLink }
logout = { this.logout }
/>
:""}
</div>
<acticle className={`header-box`} style={headerStyle}>
<Header style={{
background: "linear-gradient(to bottom,rgba(64,64,64,1),rgba(64,64,64,0.9))"
}}>
<div className="content">
<div className="logo">
<Link to="/" onClick={this.relieveLink}>YAPI</Link>
</div>
</Header>
</Layout>
<Menu
mode="horizontal"
className="nav-toolbar"
theme="dark"
style={{
lineHeight : '.64rem',
backgroundColor:"transparent",
borderColor:"transparent"
}}
onClick={this.linkTo}
selectedKeys={[curKey]}
>
<Menu.Item key="/group">
<Link to="/group">项目广场</Link>
</Menu.Item>
</Menu>
<div className="user-toolbar">
{login?
<ToolUser
user = { user }
msg = { msg }
uid = { uid }
relieveLink = { this.relieveLink }
logout = { this.logout }
/>
:""}
</div>
</div>
</Header>
</acticle>
)
}

View File

@ -5,10 +5,18 @@ $color-blue-deeper: #34495E;
$color-grey-deep : #929aac;
$color-black-light : #404040;
/* .header-box.css */
//.light{
// background-color: #f7fafc;
// color: $color-blue;
//}
//.dark {
// background-color: $color-black-light;
// color: $color-white;
//}
.header-box {
display: block;
font-size: 0.14rem;
color: $color-white;
z-index: 99;
// 内容宽度
.content {
@ -17,7 +25,6 @@ $color-black-light : #404040;
zoom: 1;
overflow: hidden;
}
.logo {
font-size: .3rem;
float: left;
@ -51,7 +58,7 @@ $color-black-light : #404040;
}
float: left;
margin: 0 0 0 .12rem;
font-size: .14rem;
font-size: .2rem;
cursor: pointer;
color: $color-white;
&:not(:last-child){
@ -75,11 +82,7 @@ $color-black-light : #404040;
i{
margin-right: .03rem;
}
.dropdown-link{
i{
font-size: .2rem;
}
}
}
}
}

View File

@ -84,7 +84,7 @@ class AddInterface extends Component {
id: 0,
name: '',
value: ''
}]
}]
let interfaceId = undefined
if (ifTrue) {
interfaceId = this.getInterfaceId()
@ -188,7 +188,7 @@ class AddInterface extends Component {
mockData () { // mock 数据
let resParams = ''
let json = ''
if(this.props.resParams){
resParams = JSON.parse(this.props.resParams)
json = JSON.stringify(Mock.mock(resParams), null, 2)
@ -254,8 +254,10 @@ class AddInterface extends Component {
<Result isSave={isSave} mockJson={mockJson} />
<MockUrl mockURL={mockURL} />
</TabPane>
<TabPane tab="Mock" key="2">mock</TabPane>
<TabPane tab="测试" key="3">
{
// <TabPane tab="Mock" key="2">mock</TabPane>
}
<TabPane tab="请求接口" key="3">
<InterfaceTest />
</TabPane>
</Tabs>

View File

@ -6,10 +6,12 @@
.content {
max-width: 11rem;
margin: 0 auto;
margin: 24px auto;
border-radius: 4px;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20);
background: #FFF;
padding: 10px 20px 50px 20px;
.save {
float: right;
margin: 0 0 10px 0;
@ -19,7 +21,7 @@
float: right;
margin: 0 15px 0 0;
}
table {
width: 100%;
border-top: 1px #EEE solid;
@ -27,7 +29,7 @@
th {
padding:0 10px;
}
td {
padding: 10px 0;
}
@ -54,7 +56,7 @@
margin: 0 0 0 10px;
cursor: pointer;
}
/* .req-header.css */
.req-header {
display: -webkit-box;
@ -90,7 +92,7 @@
.req-save, .res-save {
margin: 5px 0 0 107px;
}
/* .req-params.css */
.req-params {
display: -webkit-box;
@ -98,12 +100,12 @@
margin: 20px 0 0 0;
border-top: 1px #EEE solid;
}
.res-params-box {
display: inline-block;
width: 530px;
float: left;
/* .req-save.css */
.res-params {
display: -webkit-box;
@ -131,7 +133,7 @@
}
}
}
/* Result.css */
.result {
display: inline-block;
@ -153,10 +155,10 @@
border: 1px #CCC solid;
height: 300px;
overflow-x: hidden;
overflow-y: auto;
overflow-y: auto;
line-height: 1.2;
}
.ant-tabs {
-webkit-box-flex: 1;
}
@ -260,4 +262,4 @@ body {
padding: 0 20px;
background-color: #FFF;
-webkit-box-flex: 1;
}
}

View File

@ -12,6 +12,8 @@ import {
import './InterfaceTest.scss'
const { TextArea } = Input;
@connect(
state => ({
reqParams: state.addInterface.reqParams,
@ -52,9 +54,34 @@ export default class InterfaceTest extends Component {
@autobind
testInterface() {
const { method, url, seqGroup, interfaceProject } = this.props;
const { prd_host, basepath, protocol } = interfaceProject;
const reqParams = JSON.parse(this.props.reqParams);
const headers = {}
let query = {};
if (method === 'GET') {
Object.keys(reqParams).forEach(key => {
const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams) : reqParams.toString();
query[key] = value;
})
}
seqGroup.forEach((headerItem) => {
headers[headerItem.name] = headerItem.value;
})
const href = URL.format({
protocol: protocol || 'http',
host: prd_host,
pathname: (basepath + url).replace(/\/+/g, '/'),
query
});
crossRequest({
url: 'http://petstore.swagger.io/v2/swagger.json',
method: 'GET',
url: href,
method,
headers,
data: {
a:1
},
@ -74,7 +101,7 @@ export default class InterfaceTest extends Component {
if (method === 'GET') {
Object.keys(reqParams).forEach(key => {
const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams) : reqParams.toString();
const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams[key]) : reqParams[key].toString();
query[key] = value;
})
}
@ -82,37 +109,53 @@ export default class InterfaceTest extends Component {
const href = URL.format({
protocol: protocol || 'http',
host: prd_host,
pathname: URL.resolve(basepath, url),
pathname: (basepath + url).replace(/\/+/g, '/'),
query
});
return (
<div>
<div>接口名{interfaceName}</div>
<div>
METHOD: <Input value={method} disabled />
URL: <Input value={href} />
HEADERS: <Input value={JSON.stringify(seqGroup, 2)} />
请求参数
<div>
<div className="interface-test">
<div className="interface-name">{interfaceName}</div>
<div className="req-part">
<div className="req-row method">
METHOD<Input value={method} disabled style={{display: 'inline-block', width: 200}} />
</div>
<div className="req-row url">
URL<Input value={href} style={{display: 'inline-block', width: 800, margin: 10}} />
<Button onClick={this.testInterface} type="primary">发送</Button>
</div>
<div className="req-row headers">
HEADERS
{
Object.keys(reqParams).map((key, index) => {
const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams) : reqParams.toString();
seqGroup.map((headerItem, index) => {
return (
<div key={index}>
<Input value={key} style={{display: 'inline-block', width: 200}} />{' = '}
<Input value={value} style={{display: 'inline-block', width: 200}} />
<Input disabled value={headerItem.name} style={{display: 'inline-block', width: 200, margin: 10}} />{' = '}
<Input value={headerItem.value} style={{display: 'inline-block', width: 200, margin: 10}} />
</div>
)
})
}
</div>
<div className="req-row params">
请求参数
{
Object.keys(reqParams).map((key, index) => {
const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams[key]) : reqParams[key].toString();
return (
<div key={index}>
<Input disabled value={key} style={{display: 'inline-block', width: 200, margin: 10}} />{' = '}
<Input value={value} style={{display: 'inline-block', width: 200, margin: 10}} />
</div>
)
})
}
</div>
</div>
<Button onClick={this.testInterface}>发送跨域请求</Button>
<div>
<div className="res-part">
返回结果
{JSON.stringify(this.state.res, 2)}
<TextArea value={JSON.stringify(this.state.res, 2)}></TextArea>
</div>
</div>
)

View File

@ -0,0 +1,9 @@
.interface-test {
.interface-name {
font-size: 24px;
margin-bottom: 24px;
}
.req-row {
margin-bottom: 24px;
}
}

View File

@ -13,34 +13,42 @@ import QueueAnim from 'rc-queue-anim';
const oneAnim = { y: '+=30', opacity: 0, type: 'from', ease: 'easeOutQuad' };
const style = {
'height':'100%',
'width':'100%',
'background': 'url(./image/bg-img.jpg) no-repeat center',
'backgroundSize':'cover'
}
const HomeGuest = (props) => (
<div>
<div className="main-one">
<div className="container">
<Row>
<Col span={24}>
<div className="home-des">
<p className="title">YAPI</p>
<div className="detail">一个高效易用可部署的Api管理系统</div>
</div>
</Col>
</Row>
<Row>
<Col span={8} className="main-one-left">
<Login/>
</Col>
<Col span={16} className="main-one-right">
<div className="img-container">
<img src="./image/demo-img.png"/>
</div>
</Col>
</Row>
<div className="main-one" style = {style}>
<div style={{ background: "linear-gradient(to bottom,rgba(64,64,64,0.9),rgba(64,64,64,0.5))"}}>
<div className="container">
<Row>
<Col span={24}>
<div className="home-des">
<p className="title">YAPI</p>
<div className="detail">一个高效易用可部署的Api管理系统</div>
</div>
</Col>
</Row>
<Row>
<Col span={8} className="main-one-left">
<Login/>
</Col>
<Col span={16} className="main-one-right">
<div className="img-container">
<img src="./image/demo-img.png"/>
</div>
</Col>
</Row>
</div>
</div>
</div>
<div className="feat-part">
<div className="container">
<OverPack
playScale={[0.3,0.1]}
playScale={[0.2,0.1]}
>
<TweenOne
key="feat-motion-one"

View File

@ -7,16 +7,13 @@ $color-grey-lighter : #F7F7F7;
$color-blue-light: #5dade2;
$color-black-lighter: #404040;
.home-main {
min-height:calc(100% - 2.47rem);
display: -webkit-box;
-webkit-box-orient: vertical;
background: $color-blue-grey-lighter;
.main-one{
padding: .5rem .5rem 0 .5rem;
//background: radial-gradient(ellipse at center,#45484d 0%,#000 100%);
.home-des{
color: $color-white;
padding: .5rem 0 0;
.title{
font-size: .6rem;
}
@ -25,6 +22,7 @@ $color-black-lighter: #404040;
}
}
.login-form{
color: $color-white;
}
.img-container{
margin-bottom: -.2rem;
@ -40,7 +38,7 @@ $color-black-lighter: #404040;
margin-top: .2rem;
}
.main-one-right{
padding-left: .15rem;
padding-left: .5rem;
}
}
.user-home{

View File

@ -8,7 +8,7 @@ import InterfaceTable from './InterfaceTable/InterfaceTable.js'
import InterfaceMode from './InterfaceMode/InterfaceMode.js'
import moment from 'moment'
import {
fetchInterfaceData,
fetchInterfaceData,
projectMember,
closeProjectMember,
saveInterfaceProjectId

View File

@ -1,46 +1,19 @@
/* .interface-box.css */
.interface-box {
max-width: 11rem;
display: -webkit-box;
-webkit-box-flex: 1;
margin: 15px auto 0 auto;
font-size: 0.14rem;
margin: 24px auto;
border-radius: 4px;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20);
background: #FFF;
.interface-list {
width: 216px;
line-height: 45px;
background: #f9fafe;
li {
padding: 0 0 0 30px;
color: #344562;
cursor: pointer;
&:hover {
color: #29f;
}
a {
color: #344562;
&:hover {
color: #29f;
}
}
}
overflow: hidden;
.interface-btngroup {
margin: .24rem .24rem 0;
}
.interface-btn {
margin-right: .16rem;
}
.interface-table {
-webkit-box-flex: 1;
margin: 0 20px;
.ant-table-wrapper table {
font-size: .14rem;
button {
margin: 0 10px 0 0;
}
}
margin: .24rem;
}
}
@ -69,4 +42,3 @@
}
}
}

View File

@ -1,6 +1,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Link } from 'react-router-dom'
import { Button } from 'antd'
class InterfaceList extends Component {
static propTypes = {
@ -23,10 +24,10 @@ class InterfaceList extends Component {
const getInterfaceId = this.getInterfaceId()
return (
<ul className="interface-list">
<li><Link to={`/AddInterface/${getInterfaceId}`}>添加接口</Link></li>
<li onClick={projectMember}>管理项目成员</li>
</ul>
<div className="interface-btngroup">
<Link to={`/AddInterface/${getInterfaceId}`}><Button className="interface-btn" type="primary" icon="plus">添加接口</Button></Link>
<Button className="interface-btn" type="primary" onClick={projectMember} icon="user">管理成员</Button>
</div>
)
}
}

View File

@ -1,5 +1,5 @@
import React, { Component } from 'react'
import { Table, Button } from 'antd'
import { Table } from 'antd'
import PropTypes from 'prop-types'
import axios from 'axios'
import { connect } from 'react-redux'
@ -74,13 +74,11 @@ class InterfaceTable extends Component {
console.log(data)
return (
<span>
<Button type="primary">
<Link to={`/AddInterface/edit/${data._id}`}>编辑</Link>
</Button>
<Button type="primary">
<Link to={`/AddInterface/edit/${data._id}`}>测试</Link>
</Button>
<Button type="danger" onClick={deleteInterface}>删除</Button>
<Link to={`/AddInterface/edit/${data._id}`}><span>编辑</span></Link>
<span className="ant-divider" />
<Link to={`/AddInterface/edit/${data._id}`}><span>测试</span></Link>
<span className="ant-divider" />
<a onClick={deleteInterface}>删除</a>
</span>
)
}
@ -90,7 +88,7 @@ class InterfaceTable extends Component {
return (
<section className="interface-table">
<Table columns={columns} dataSource={data} />
<Table bordered={true} columns={columns} dataSource={data} />
</section>
)
}

View File

@ -15,17 +15,19 @@
margin-bottom: .1rem;
}
.qsso-breakline {
position: relative;
text-align: center;
margin: .24rem auto;
height: 1px;
background-color: #bbb;
.qsso-breakword {
.qsso-breakline{
display: flex;
align-items: center;
color: #999;
margin: .2rem auto;
&:before, &:after{
content: "";
display: inline-block;
transform: translateY(-50%);
background-color: #f7f7f7;
padding: 0 .08rem;
color: #999;
height: .02rem;
flex: 1;
border-top: .01rem solid #bbb;
}
.qsso-breakword{
padding: 0 .1rem;
}
}

View File

@ -1,7 +1,8 @@
.group-bar {
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20);
border-radius: 4px;
.curr-group {
background: #34495E;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20);
border-radius: 4px 4px 0 0;
padding: 32px 24px;
.curr-group-name {
@ -38,7 +39,7 @@
height: 48px;
min-width: 263px;
padding: 10px 6px;
background: #fff;
background: #eee;
.search {
display: inline-block;
margin-right: 6px;
@ -51,7 +52,7 @@
overflow-x: hidden;
border-bottom: 1px solid #e9e9e9;
padding-bottom: 24px;
border-radius: 0 0 6px 6px;
border-radius: 0 0 4px 4px;
.group-item {
// height: 48px;
// line-height: 48px;

View File

@ -252,7 +252,7 @@ class UpDateModal extends Component {
})(
<Input placeholder="请输入环境域名" style={{ width: '90%', marginRight: 8 }} addonBefore={
getFieldDecorator(`envs-protocol-${index}`, {
initialValue: envMessage.length !== 0 && k.domain ? k.domain.split('\/\/')[0]+'\/\/' : '',
initialValue: envMessage.length !== 0 && k.domain ? k.domain.split('\/\/')[0]+'\/\/' : 'http\:\/\/',
rules: [{
required: true
}]
@ -266,11 +266,14 @@ class UpDateModal extends Component {
</FormItem>
</Col>
<Col span={2}>
{envs.length > 0 ? (
{/* 新增的项中,只有最后一项有删除按钮 */}
{ (envs.length > 0 && k._id) || (envs.length == index + 1) ? (
<Icon
className="dynamic-delete-button"
type="minus-circle-o"
onClick={() => this.remove(k._id ? k._id : k)}
onClick={() => {
return this.remove(k._id ? k._id : k);
}}
/>
) : null}
</Col>

View File

@ -44,4 +44,7 @@ em {
display: -webkit-box;
-webkit-box-orient: vertical;
height: 100%;
.router-container{
min-height:calc(100% - 2.47rem);
}
}

View File

@ -23,6 +23,10 @@ class groupController extends baseController{
*/
async add(ctx) {
let params = ctx.request.body;
params = yapi.commons.handleParams(params, {
group_name: 'string',
group_desc: 'string'
})
if(this.getRole() !== 'admin'){
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
}
@ -38,7 +42,7 @@ class groupController extends baseController{
let data = {
group_name: params.group_name,
group_desc: params.group_desc,
uid: '0',
uid: this.getUid(),
add_time: yapi.commons.time(),
up_time: yapi.commons.time()
}
@ -124,6 +128,12 @@ class groupController extends baseController{
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
}
try{
ctx.request.body = yapi.commons.handleParams(ctx.request.body, {
id: 'number',
group_name: 'string',
group_desc: 'string'
})
var groupInst = yapi.getInst(groupModel);
let id = ctx.request.body.id;
let data = {};

View File

@ -37,6 +37,12 @@ class interfaceController extends baseController{
*/
async add(ctx){
let params = ctx.request.body;
params = yapi.commons.handleParams(params, {
title: 'string',
path: 'string',
method: 'string',
desc: 'string'
})
params.method = params.method || 'GET';
params.method = params.method.toUpperCase()
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
@ -159,6 +165,12 @@ class interfaceController extends baseController{
async up(ctx){
let params = ctx.request.body;
params = yapi.commons.handleParams(params, {
title: 'string',
path: 'string',
method: 'string',
desc: 'string'
})
params.method = params.method || 'GET';
params.method = params.method.toUpperCase()
let id = ctx.request.body.id;

View File

@ -49,7 +49,14 @@ class projectController extends baseController {
*/
async add(ctx) {
let params = ctx.request.body;
params = yapi.commons.handleParams(params, {
name: 'string',
basepath: 'string',
prd_host: 'string',
protocol: 'string',
group_id: 'number',
desc: 'string'
})
if(!params.group_id){
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
}
@ -322,6 +329,14 @@ class projectController extends baseController {
try{
let id = ctx.request.body.id;
let params = ctx.request.body;
params = yapi.commons.handleParams(params, {
name: 'string',
basepath: 'string',
prd_host: 'string',
protocol: 'string',
group_id: 'number',
desc: 'string'
})
if(!id){
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
}

View File

@ -241,6 +241,13 @@ class userController extends baseController {
async reg(ctx) { //注册
var userInst = yapi.getInst(userModel);
let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码
params = yapi.commons.handleParams(params, {
username: 'string',
password: 'string',
email: 'string'
})
if (!params.email) {
return ctx.body = yapi.commons.resReturn(null, 400, '邮箱不能为空');
}
@ -395,6 +402,10 @@ class userController extends baseController {
async update(ctx){ //更新用户信息
try{
let params = ctx.request.body;
params = yapi.commons.handleParams(params, {
username: 'string',
email: 'string'
})
if(this.getRole() !== 'admin' && params.uid != this.getUid()){
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
}

View File

@ -4,13 +4,14 @@ import interfaceModel from '../models/interface.js'
import Mock from 'mockjs'
module.exports = async (ctx, next) => {
yapi.commons.log('mock Server running...')
yapi.commons.log('Server Recevie Request...')
let hostname = ctx.hostname;
let config = yapi.WEBCONFIG;
if(ctx.hostname === config.webhost){
if(next) await next();
return true;
}
yapi.commons.log('MockServer Running...')
let projectInst = yapi.getInst(projectModel), projects;
try{
projects = await projectInst.getByDomain(hostname);
@ -18,10 +19,12 @@ module.exports = async (ctx, next) => {
return ctx.body = yapi.commons.resReturn(null, 403, e.message);
}
let matchProject = false, maxBasepath = 0;
let matchProject = [], maxBasepath = 0;
for(let i=0, l = projects.length; i< l; i++){
let project = projects[i];
if(ctx.path && ctx.path.indexOf(project.basepath) === 0 && project.basepath[project.basepath.length -1] === '/'){
if(ctx.path && ctx.path.indexOf(project.basepath) === 0){
matchProject.push(project);
if(project.basepath.length > maxBasepath){
maxBasepath = project.basepath.length;

View File

@ -107,14 +107,14 @@ exports.sendMail = (options, cb) => {
}
}
try{
try {
yapi.mail.sendMail({
from: yapi.WEBCONFIG.mail.auth.user,
to: options.to,
subject: 'yapi平台',
html: options.contents
from: yapi.WEBCONFIG.mail.auth.user,
to: options.to,
subject: 'yapi平台',
html: options.contents
}, cb)
}catch(e){
} catch (e) {
console.error(e.message)
}
}
@ -150,4 +150,41 @@ exports.verifyPath = (path) => {
} else {
return false;
}
}
function trim(str) {
if (!str) return str;
str = str + '';
return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ltrim(str) {
if (!str) return str;
str = str + '';
return str.replace(/(^\s*)/g, "");
}
function rtrim(str) {
if (!str) return str;
str = str + '';
return str.replace(/(\s*$)/g, "");
}
exports.trim = trim;
exports.ltrim = ltrim;
exports.rtrim = rtrim;
exports.handleParams = (params, keys) => {
if (!params || typeof params !== 'object' || !keys || typeof keys !== 'object') return false;
for (var key in keys) {
var filter = keys[key];
if (params[key]) {
switch (filter) {
case 'string': params[key] = trim(params[key] + ''); break;
case 'number': params[key] = parseInt(params[key], 10); break;
default: params[key] = trim(params + '');
}
}
}
return params;
}

View File

@ -83,68 +83,73 @@ var groupController = function (_baseController) {
case 0:
params = ctx.request.body;
params = _yapi2.default.commons.handleParams(params, {
group_name: 'string',
group_desc: 'string'
});
if (!(this.getRole() !== 'admin')) {
_context.next = 3;
_context.next = 4;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
case 3:
case 4:
if (params.group_name) {
_context.next = 5;
_context.next = 6;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组名不能为空'));
case 5:
case 6:
groupInst = _yapi2.default.getInst(_group2.default);
_context.next = 8;
_context.next = 9;
return groupInst.checkRepeat(params.group_name);
case 8:
case 9:
checkRepeat = _context.sent;
if (!(checkRepeat > 0)) {
_context.next = 11;
_context.next = 12;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '项目分组名已存在'));
case 11:
case 12:
data = {
group_name: params.group_name,
group_desc: params.group_desc,
uid: '0',
uid: this.getUid(),
add_time: _yapi2.default.commons.time(),
up_time: _yapi2.default.commons.time()
};
_context.prev = 12;
_context.next = 15;
_context.prev = 13;
_context.next = 16;
return groupInst.save(data);
case 15:
case 16:
result = _context.sent;
result = _yapi2.default.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']);
ctx.body = _yapi2.default.commons.resReturn(result);
_context.next = 23;
_context.next = 24;
break;
case 20:
_context.prev = 20;
_context.t0 = _context['catch'](12);
case 21:
_context.prev = 21;
_context.t0 = _context['catch'](13);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
case 23:
case 24:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[12, 20]]);
}, _callee, this, [[13, 21]]);
}));
function add(_x) {
@ -323,6 +328,13 @@ var groupController = function (_baseController) {
case 2:
_context4.prev = 2;
ctx.request.body = _yapi2.default.commons.handleParams(ctx.request.body, {
id: 'number',
group_name: 'string',
group_desc: 'string'
});
groupInst = _yapi2.default.getInst(_group2.default);
id = ctx.request.body.id;
data = {};
@ -332,28 +344,28 @@ var groupController = function (_baseController) {
if ((0, _keys2.default)(data).length === 0) {
ctx.body = _yapi2.default.commons.resReturn(null, 404, '分组名和分组描述不能为空');
}
_context4.next = 11;
_context4.next = 12;
return groupInst.up(id, data);
case 11:
case 12:
result = _context4.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context4.next = 18;
_context4.next = 19;
break;
case 15:
_context4.prev = 15;
case 16:
_context4.prev = 16;
_context4.t0 = _context4['catch'](2);
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
case 18:
case 19:
case 'end':
return _context4.stop();
}
}
}, _callee4, this, [[2, 15]]);
}, _callee4, this, [[2, 16]]);
}));
function up(_x4) {

View File

@ -94,49 +94,55 @@ var interfaceController = function (_baseController) {
case 0:
params = ctx.request.body;
params = _yapi2.default.commons.handleParams(params, {
title: 'string',
path: 'string',
method: 'string',
desc: 'string'
});
params.method = params.method || 'GET';
params.method = params.method.toUpperCase();
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
if (params.project_id) {
_context.next = 6;
_context.next = 7;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
case 6:
case 7:
if (params.path) {
_context.next = 8;
_context.next = 9;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口请求路径不能为空'));
case 8:
case 9:
if (_yapi2.default.commons.verifyPath(params.path)) {
_context.next = 10;
_context.next = 11;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/'));
case 10:
_context.next = 12;
case 11:
_context.next = 13;
return this.Model.checkRepeat(params.path, params.method);
case 12:
case 13:
checkRepeat = _context.sent;
if (!(checkRepeat > 0)) {
_context.next = 15;
_context.next = 16;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']'));
case 15:
_context.prev = 15;
case 16:
_context.prev = 16;
data = {
project_id: params.project_id,
title: params.title,
@ -156,28 +162,28 @@ var interfaceController = function (_baseController) {
if (params.req_params_form) data.req_params_form = params.req_params_form;
if (params.req_params_other) data.req_params_other = params.req_params_other;
_context.next = 21;
_context.next = 22;
return this.Model.save(data);
case 21:
case 22:
result = _context.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context.next = 28;
_context.next = 29;
break;
case 25:
_context.prev = 25;
_context.t0 = _context['catch'](15);
case 26:
_context.prev = 26;
_context.t0 = _context['catch'](16);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
case 28:
case 29:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[15, 25]]);
}, _callee, this, [[16, 26]]);
}));
function add(_x) {
@ -349,51 +355,57 @@ var interfaceController = function (_baseController) {
case 0:
params = ctx.request.body;
params = _yapi2.default.commons.handleParams(params, {
title: 'string',
path: 'string',
method: 'string',
desc: 'string'
});
params.method = params.method || 'GET';
params.method = params.method.toUpperCase();
id = ctx.request.body.id;
if (id) {
_context4.next = 6;
_context4.next = 7;
break;
}
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口id不能为空'));
case 6:
_context4.next = 8;
case 7:
_context4.next = 9;
return this.Model.get(id);
case 8:
case 9:
interfaceData = _context4.sent;
if (!(params.path && !_yapi2.default.commons.verifyPath(params.path))) {
_context4.next = 11;
_context4.next = 12;
break;
}
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/'));
case 11:
case 12:
if (!(params.path && params.path !== interfaceData.path && params.method !== interfaceData.method)) {
_context4.next = 17;
_context4.next = 18;
break;
}
_context4.next = 14;
_context4.next = 15;
return this.Model.checkRepeat(params.path, params.method);
case 14:
case 15:
checkRepeat = _context4.sent;
if (!(checkRepeat > 0)) {
_context4.next = 17;
_context4.next = 18;
break;
}
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']'));
case 17:
case 18:
data = {
up_time: _yapi2.default.commons.time()
};
@ -412,29 +424,29 @@ var interfaceController = function (_baseController) {
if (params.res_body_type) data.res_body_type = params.res_body_type;
if (params.res_body) data.res_body = params.res_body;
_context4.prev = 27;
_context4.next = 30;
_context4.prev = 28;
_context4.next = 31;
return this.Model.up(id, data);
case 30:
case 31:
result = _context4.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context4.next = 37;
_context4.next = 38;
break;
case 34:
_context4.prev = 34;
_context4.t0 = _context4['catch'](27);
case 35:
_context4.prev = 35;
_context4.t0 = _context4['catch'](28);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
case 37:
case 38:
case 'end':
return _context4.stop();
}
}
}, _callee4, this, [[27, 34]]);
}, _callee4, this, [[28, 35]]);
}));
function up(_x4) {

View File

@ -119,82 +119,91 @@ var projectController = function (_baseController) {
case 0:
params = ctx.request.body;
params = _yapi2.default.commons.handleParams(params, {
name: 'string',
basepath: 'string',
prd_host: 'string',
protocol: 'string',
group_id: 'number',
desc: 'string'
});
if (params.group_id) {
_context.next = 3;
_context.next = 4;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
case 3:
case 4:
if (params.name) {
_context.next = 5;
_context.next = 6;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目名不能为空'));
case 5:
_context.next = 7;
case 6:
_context.next = 8;
return this.Model.checkNameRepeat(params.name);
case 7:
case 8:
checkRepeat = _context.sent;
if (!(checkRepeat > 0)) {
_context.next = 10;
_context.next = 11;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
case 10:
case 11:
if (params.basepath) {
_context.next = 12;
_context.next = 13;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目basepath不能为空'));
case 12:
case 13:
if (params.prd_host) {
_context.next = 14;
_context.next = 15;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目domain不能为空'));
case 14:
case 15:
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
_context.next = 16;
_context.next = 17;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
case 16:
case 17:
if (this.verifyDomain(params.prd_host)) {
_context.next = 18;
_context.next = 19;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
case 18:
_context.next = 20;
case 19:
_context.next = 21;
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
case 20:
case 21:
checkRepeatDomain = _context.sent;
if (!(checkRepeatDomain > 0)) {
_context.next = 23;
_context.next = 24;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
case 23:
case 24:
data = {
name: params.name,
desc: params.desc,
@ -207,29 +216,29 @@ var projectController = function (_baseController) {
add_time: _yapi2.default.commons.time(),
up_time: _yapi2.default.commons.time()
};
_context.prev = 24;
_context.next = 27;
_context.prev = 25;
_context.next = 28;
return this.Model.save(data);
case 27:
case 28:
result = _context.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context.next = 34;
_context.next = 35;
break;
case 31:
_context.prev = 31;
_context.t0 = _context['catch'](24);
case 32:
_context.prev = 32;
_context.t0 = _context['catch'](25);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
case 34:
case 35:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[24, 31]]);
}, _callee, this, [[25, 32]]);
}));
function add(_x) {
@ -750,50 +759,59 @@ var projectController = function (_baseController) {
id = ctx.request.body.id;
params = ctx.request.body;
params = _yapi2.default.commons.handleParams(params, {
name: 'string',
basepath: 'string',
prd_host: 'string',
protocol: 'string',
group_id: 'number',
desc: 'string'
});
if (id) {
_context8.next = 5;
_context8.next = 6;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
case 5:
_context8.next = 7;
case 6:
_context8.next = 8;
return this.jungeMemberAuth(id, this.getUid());
case 7:
case 8:
_context8.t0 = _context8.sent;
if (!(_context8.t0 !== true)) {
_context8.next = 10;
_context8.next = 11;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 10:
_context8.next = 12;
case 11:
_context8.next = 13;
return this.Model.get(id);
case 12:
case 13:
projectData = _context8.sent;
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
_context8.next = 15;
_context8.next = 16;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
case 15:
case 16:
if (this.verifyDomain(params.prd_host)) {
_context8.next = 17;
_context8.next = 18;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
case 17:
case 18:
if (projectData.name === params.name) {
delete params.name;
@ -804,43 +822,43 @@ var projectController = function (_baseController) {
}
if (!params.name) {
_context8.next = 25;
_context8.next = 26;
break;
}
_context8.next = 22;
_context8.next = 23;
return this.Model.checkNameRepeat(params.name);
case 22:
case 23:
checkRepeat = _context8.sent;
if (!(checkRepeat > 0)) {
_context8.next = 25;
_context8.next = 26;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
case 25:
case 26:
if (!(params.basepath && params.prd_host)) {
_context8.next = 31;
_context8.next = 32;
break;
}
_context8.next = 28;
_context8.next = 29;
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
case 28:
case 29:
checkRepeatDomain = _context8.sent;
if (!(checkRepeatDomain > 0)) {
_context8.next = 31;
_context8.next = 32;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
case 31:
case 32:
data = {
uid: this.getUid(),
up_time: _yapi2.default.commons.time()
@ -856,28 +874,28 @@ var projectController = function (_baseController) {
if (params.protocol) data.protocol = params.protocol;
if (params.env) data.env = params.env;
_context8.next = 39;
_context8.next = 40;
return this.Model.up(id, data);
case 39:
case 40:
result = _context8.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context8.next = 46;
_context8.next = 47;
break;
case 43:
_context8.prev = 43;
case 44:
_context8.prev = 44;
_context8.t1 = _context8['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t1.message);
case 46:
case 47:
case 'end':
return _context8.stop();
}
}
}, _callee8, this, [[0, 43]]);
}, _callee8, this, [[0, 44]]);
}));
function up(_x8) {

View File

@ -547,36 +547,42 @@ var userController = function (_baseController) {
userInst = _yapi2.default.getInst(_user2.default);
params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码
params = _yapi2.default.commons.handleParams(params, {
username: 'string',
password: 'string',
email: 'string'
});
if (params.email) {
_context8.next = 4;
_context8.next = 5;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '邮箱不能为空'));
case 4:
case 5:
if (params.password) {
_context8.next = 6;
_context8.next = 7;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '密码不能为空'));
case 6:
_context8.next = 8;
case 7:
_context8.next = 9;
return userInst.checkRepeat(params.email);
case 8:
case 9:
checkRepeat = _context8.sent;
if (!(checkRepeat > 0)) {
_context8.next = 11;
_context8.next = 12;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '该email已经注册'));
case 11:
case 12:
passsalt = _yapi2.default.commons.randStr();
data = {
username: params.username,
@ -591,11 +597,11 @@ var userController = function (_baseController) {
if (!data.username) {
data.username = data.email.substr(0, data.email.indexOf('@'));
}
_context8.prev = 14;
_context8.next = 17;
_context8.prev = 15;
_context8.next = 18;
return userInst.save(data);
case 17:
case 18:
user = _context8.sent;
this.setLoginCookie(user._id, user.passsalt);
@ -612,21 +618,21 @@ var userController = function (_baseController) {
to: user.email,
contents: '<h3>\u4EB2\u7231\u7684\u7528\u6237\uFF1A</h3><p>\u60A8\u597D\uFF0C\u611F\u8C22\u4F7F\u7528YApi,\u60A8\u7684\u8D26\u53F7 ' + params.email + ' \u5DF2\u7ECF\u6CE8\u518C\u6210\u529F</p>'
});
_context8.next = 26;
_context8.next = 27;
break;
case 23:
_context8.prev = 23;
_context8.t0 = _context8['catch'](14);
case 24:
_context8.prev = 24;
_context8.t0 = _context8['catch'](15);
ctx.body = _yapi2.default.commons.resReturn(null, 401, _context8.t0.message);
case 26:
case 27:
case 'end':
return _context8.stop();
}
}
}, _callee8, this, [[14, 23]]);
}, _callee8, this, [[15, 24]]);
}));
function reg(_x9) {
@ -868,25 +874,30 @@ var userController = function (_baseController) {
_context12.prev = 0;
params = ctx.request.body;
params = _yapi2.default.commons.handleParams(params, {
username: 'string',
email: 'string'
});
if (!(this.getRole() !== 'admin' && params.uid != this.getUid())) {
_context12.next = 4;
_context12.next = 5;
break;
}
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
case 4:
case 5:
userInst = _yapi2.default.getInst(_user2.default);
id = params.uid;
if (id) {
_context12.next = 8;
_context12.next = 9;
break;
}
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, 'uid不能为空'));
case 8:
case 9:
data = {
up_time: _yapi2.default.commons.time()
@ -899,46 +910,46 @@ var userController = function (_baseController) {
params.email && (data.email = params.email);
if (!data.email) {
_context12.next = 18;
_context12.next = 19;
break;
}
_context12.next = 15;
_context12.next = 16;
return userInst.checkRepeat(data.email);
case 15:
case 16:
checkRepeat = _context12.sent;
if (!(checkRepeat > 0)) {
_context12.next = 18;
_context12.next = 19;
break;
}
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '该email已经注册'));
case 18:
_context12.next = 20;
case 19:
_context12.next = 21;
return userInst.update(id, data);
case 20:
case 21:
result = _context12.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context12.next = 27;
_context12.next = 28;
break;
case 24:
_context12.prev = 24;
case 25:
_context12.prev = 25;
_context12.t0 = _context12['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context12.t0.message);
case 27:
case 28:
case 'end':
return _context12.stop();
}
}
}, _callee12, this, [[0, 24]]);
}, _callee12, this, [[0, 25]]);
}));
function update(_x13) {

View File

@ -34,7 +34,7 @@ module.exports = function () {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_yapi2.default.commons.log('mock Server running...');
_yapi2.default.commons.log('Server Recevie Request...');
hostname = ctx.hostname;
config = _yapi2.default.WEBCONFIG;
@ -55,28 +55,31 @@ module.exports = function () {
return _context.abrupt('return', true);
case 8:
_yapi2.default.commons.log('MockServer Running...');
projectInst = _yapi2.default.getInst(_project3.default), projects = void 0;
_context.prev = 9;
_context.next = 12;
_context.prev = 10;
_context.next = 13;
return projectInst.getByDomain(hostname);
case 12:
case 13:
projects = _context.sent;
_context.next = 18;
_context.next = 19;
break;
case 15:
_context.prev = 15;
_context.t0 = _context['catch'](9);
case 16:
_context.prev = 16;
_context.t0 = _context['catch'](10);
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 403, _context.t0.message));
case 18:
matchProject = false, maxBasepath = 0;
case 19:
matchProject = [], maxBasepath = 0;
for (i = 0, l = projects.length; i < l; i++) {
_project = projects[i];
if (ctx.path && ctx.path.indexOf(_project.basepath) === 0 && _project.basepath[_project.basepath.length - 1] === '/') {
if (ctx.path && ctx.path.indexOf(_project.basepath) === 0) {
matchProject.push(_project);
if (_project.basepath.length > maxBasepath) {
maxBasepath = _project.basepath.length;
@ -86,62 +89,62 @@ module.exports = function () {
}
if (!(matchProject === false)) {
_context.next = 22;
_context.next = 23;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '不存在的domain'));
case 22:
case 23:
project = matchProject, interfaceData = void 0;
interfaceInst = _yapi2.default.getInst(_interface2.default);
_context.prev = 24;
_context.next = 27;
_context.prev = 25;
_context.next = 28;
return interfaceInst.getByPath(project._id, ctx.path.substr(project.basepath.length));
case 27:
case 28:
interfaceData = _context.sent;
if (!(!interfaceData || interfaceData.length === 0)) {
_context.next = 30;
_context.next = 31;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 404, '不存在的api'));
case 30:
case 31:
if (!(interfaceData.length > 1)) {
_context.next = 32;
_context.next = 33;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '存在多个api请检查数据库'));
case 32:
case 33:
interfaceData = interfaceData[0];
if (!(interfaceData.res_body_type === 'json')) {
_context.next = 35;
_context.next = 36;
break;
}
return _context.abrupt('return', ctx.body = _mockjs2.default.mock(_yapi2.default.commons.json_parse(interfaceData.res_body)));
case 35:
case 36:
return _context.abrupt('return', ctx.body = interfaceData.res_body);
case 38:
_context.prev = 38;
_context.t1 = _context['catch'](24);
case 39:
_context.prev = 39;
_context.t1 = _context['catch'](25);
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 409, _context.t1.message));
case 41:
case 42:
case 'end':
return _context.stop();
}
}
}, _callee, undefined, [[9, 15], [24, 38]]);
}, _callee, undefined, [[10, 16], [25, 39]]);
}));
return function (_x, _x2) {

View File

@ -171,4 +171,44 @@ exports.verifyPath = function (path) {
} else {
return false;
}
};
function trim(str) {
if (!str) return str;
str = str + '';
return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ltrim(str) {
if (!str) return str;
str = str + '';
return str.replace(/(^\s*)/g, "");
}
function rtrim(str) {
if (!str) return str;
str = str + '';
return str.replace(/(\s*$)/g, "");
}
exports.trim = trim;
exports.ltrim = ltrim;
exports.rtrim = rtrim;
exports.handleParams = function (params, keys) {
if (!params || (typeof params === 'undefined' ? 'undefined' : (0, _typeof3.default)(params)) !== 'object' || !keys || (typeof keys === 'undefined' ? 'undefined' : (0, _typeof3.default)(keys)) !== 'object') return false;
for (var key in keys) {
var filter = keys[key];
if (params[key]) {
switch (filter) {
case 'string':
params[key] = trim(params[key] + '');break;
case 'number':
params[key] = parseInt(params[key], 10);break;
default:
params[key] = trim(params + '');
}
}
}
return params;
};

BIN
static/image/bg-img.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB