mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-15 05:10:47 +08:00
Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
c155996e48
@ -37,6 +37,7 @@ module.exports = {
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"strict": 0
|
||||
"strict": 0,
|
||||
"comma-dangle": ["error", "never"]
|
||||
}
|
||||
};
|
@ -195,4 +195,4 @@ export default class HeaderCom extends Component {
|
||||
</acticle>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -205,6 +205,11 @@ export default class InterfaceTest extends Component {
|
||||
<div className="interface-name">{interfaceName}</div>
|
||||
<div className="req-part">
|
||||
<div className="req-row href">
|
||||
<InputGroup compact style={{display: 'inline-block', width: 680, border: 0, background: '#fff', marginBottom: -4}}>
|
||||
<Input value="Method" disabled style={{display: 'inline-block', width: 80, border: 0, background: '#fff'}} />
|
||||
<Input value="Domain" disabled style={{display: 'inline-block', width: 300, border: 0, background: '#fff'}} />
|
||||
<Input value="Basepath + Url + [Query]" disabled style={{display: 'inline-block', width: 300, border: 0, background: '#fff'}} />
|
||||
</InputGroup>
|
||||
<InputGroup compact style={{display: 'inline-block', width: 680}}>
|
||||
<Input value={method} disabled style={{display: 'inline-block', width: 80}} />
|
||||
<Select defaultValue="prd" style={{display: 'inline-block', width: 300}} onChange={this.changeDomain}>
|
||||
|
@ -1,13 +1,12 @@
|
||||
import React, { Component } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { connect } from 'react-redux'
|
||||
import { Button, Icon, Modal, Input, message, Menu, Row, Col } from 'antd'
|
||||
import { Button, Icon, Popconfirm, Modal, Input, message, Menu, Row, Col } from 'antd'
|
||||
import { autobind } from 'core-decorators';
|
||||
import axios from 'axios';
|
||||
import { withRouter } from 'react-router';
|
||||
const { TextArea } = Input;
|
||||
const Search = Input.Search;
|
||||
const confirm = Modal.confirm;
|
||||
const TYPE_EDIT = 'edit';
|
||||
|
||||
import {
|
||||
@ -164,21 +163,15 @@ export default class GroupList extends Component {
|
||||
deleteGroup() {
|
||||
const self = this;
|
||||
const { currGroup } = self.props;
|
||||
confirm({
|
||||
title: `你确定要删除分组 ${currGroup.group_name}?`,
|
||||
content: `分组简介:${currGroup.group_desc}`,
|
||||
onOk() {
|
||||
axios.post('/group/del', {id: currGroup._id}).then(res => {
|
||||
if (res.data.errcode) {
|
||||
message.error(res.data.errmsg);
|
||||
} else {
|
||||
message.success('删除成功');
|
||||
self.props.fetchGroupList().then(() => {
|
||||
const currGroup = self.props.groupList[0] || { group_name: '', group_desc: '' };
|
||||
self.setState({groupList: self.props.groupList});
|
||||
self.props.setCurrGroup(currGroup)
|
||||
});
|
||||
}
|
||||
axios.post('/group/del', {id: currGroup._id}).then(res => {
|
||||
if (res.data.errcode) {
|
||||
message.error(res.data.errmsg);
|
||||
} else {
|
||||
message.success('删除成功');
|
||||
self.props.fetchGroupList().then(() => {
|
||||
const currGroup = self.props.groupList[0] || { group_name: '', group_desc: '' };
|
||||
self.setState({groupList: self.props.groupList});
|
||||
self.props.setCurrGroup(currGroup)
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -205,7 +198,9 @@ export default class GroupList extends Component {
|
||||
<div className="curr-group-name">
|
||||
<div className="text" title={currGroup.group_name}>{currGroup.group_name}</div>
|
||||
<Icon className="edit-group" type="edit" title="编辑分组" onClick={() => this.showModal(TYPE_EDIT)}/>
|
||||
<Icon className="delete-group" type="delete" title="删除分组" onClick={this.deleteGroup}/>
|
||||
<Popconfirm title={`你确定要删除分组 ${currGroup.group_name}?`} onConfirm={this.deleteGroup}>
|
||||
<Icon className="delete-group" type="delete" title="删除分组"/>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
<div className="curr-group-desc" title={currGroup.group_desc}>简介:{currGroup.group_desc}</div>
|
||||
</div>
|
||||
|
@ -66,7 +66,7 @@ const getColumns = (data, props) => {
|
||||
<span>
|
||||
<a onClick={() => changeUpdateModal(true, index)}>修改</a>
|
||||
<span className="ant-divider" />
|
||||
<Popconfirm title="你确定要删除项目吗?" onConfirm={deleteConfirm(id, props)} okText="删除" cancelText="取消">
|
||||
<Popconfirm title="你确定要删除项目吗?" onConfirm={deleteConfirm(id, props)} okText="确定" cancelText="取消">
|
||||
<a href="#">删除</a>
|
||||
</Popconfirm>
|
||||
</span>
|
||||
|
@ -1,9 +1,8 @@
|
||||
.m-container{
|
||||
background-color: #fff;
|
||||
padding: 16px 24px;
|
||||
padding: 24px;
|
||||
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20);
|
||||
border-radius: 4px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.m-table {
|
||||
|
@ -83,7 +83,7 @@ class LeftMenu extends Component {
|
||||
const { dataSource } = this.state;
|
||||
return (<div className="user-list">
|
||||
<div className='cur-user'>
|
||||
<div className='user-name'><span>用户名 : </span>{`${this.props.curUserName}`}</div>
|
||||
<div className='user-name'><span>用户名 :</span>{`${this.props.curUserName}`}</div>
|
||||
</div>
|
||||
<Row type="flex" justify="start" className="search">
|
||||
<Col span="24">
|
||||
|
@ -108,7 +108,7 @@ class List extends Component {
|
||||
<span>
|
||||
<Link to={"/user/profile/" + item._id} >查看</Link>
|
||||
<span className="ant-divider" />
|
||||
<Popconfirm placement="leftTop" title="确认删除此用户?" onConfirm={() => {this.confirm(item._id)}} okText="Yes" cancelText="No">
|
||||
<Popconfirm title="确认删除此用户?" onConfirm={() => {this.confirm(item._id)}} okText="确定" cancelText="取消">
|
||||
<a href="#">删除</a>
|
||||
</Popconfirm>
|
||||
</span>
|
||||
|
@ -132,14 +132,14 @@ class Profile extends Component {
|
||||
userNameEditHtml = <div >
|
||||
<span className="text">{userinfo.username}</span>
|
||||
{/*<span className="text-button" onClick={() => { this.handleEdit('usernameEdit', true) }}><Icon type="edit" />修改</span>*/}
|
||||
<Button size={'small'} icon="edit" onClick={() => { this.handleEdit('usernameEdit', true) }}>修改</Button>
|
||||
<Button icon="edit" onClick={() => { this.handleEdit('usernameEdit', true) }}>修改</Button>
|
||||
</div>
|
||||
} else {
|
||||
userNameEditHtml = <div>
|
||||
<Input value={_userinfo.username} name="username" onChange={this.changeUserinfo} placeholder="用户名" />
|
||||
<ButtonGroup className="edit-buttons" >
|
||||
<Button size={'small'} className="edit-button" onClick={() => { this.handleEdit('usernameEdit', false) }} >Cancel</Button>
|
||||
<Button size={'small'} className="edit-button" onClick={ () => { this.updateUserinfo('username')} } type="primary">OK</Button>
|
||||
<Button className="edit-button" onClick={() => { this.handleEdit('usernameEdit', false) }} >Cancel</Button>
|
||||
<Button className="edit-button" onClick={ () => { this.updateUserinfo('username')} } type="primary">OK</Button>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
}
|
||||
@ -148,14 +148,14 @@ class Profile extends Component {
|
||||
emailEditHtml = <div >
|
||||
<span className="text">{userinfo.email}</span>
|
||||
{/*<span className="text-button" onClick={() => { this.handleEdit('emailEdit', true) }} ><Icon type="edit" />修改</span>*/}
|
||||
<Button size={'small'} icon="edit" onClick={() => { this.handleEdit('emailEdit', true) }}>修改</Button>
|
||||
<Button icon="edit" onClick={() => { this.handleEdit('emailEdit', true) }}>修改</Button>
|
||||
</div>
|
||||
} else {
|
||||
emailEditHtml = <div>
|
||||
<Input placeholder="Email" value={_userinfo.email} name="email" onChange={this.changeUserinfo} />
|
||||
<ButtonGroup className="edit-buttons" >
|
||||
<Button size={'small'} className="edit-button" onClick={() => { this.handleEdit('emailEdit', false) }} >Cancel</Button>
|
||||
<Button size={'small'} className="edit-button" type="primary" onClick={ () => { this.updateUserinfo('email')} }>OK</Button>
|
||||
<Button className="edit-button" onClick={() => { this.handleEdit('emailEdit', false) }} >Cancel</Button>
|
||||
<Button className="edit-button" type="primary" onClick={ () => { this.updateUserinfo('email')} }>OK</Button>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
}
|
||||
@ -164,7 +164,7 @@ class Profile extends Component {
|
||||
roleEditHtml = <div>
|
||||
<span className="text">{roles[userinfo.role]}</span>
|
||||
{/*<span className="text-button" onClick={() => { this.handleEdit('roleEdit', true) }} ><Icon type="edit" />修改</span>*/}
|
||||
<Button size={'small'} icon="edit" onClick={() => { this.handleEdit('roleEdit', true) }}>修改</Button>
|
||||
<Button icon="edit" onClick={() => { this.handleEdit('roleEdit', true) }}>修改</Button>
|
||||
</div>
|
||||
} else {
|
||||
roleEditHtml = <Select defaultValue={_userinfo.role} onChange={ this.changeRole} style={{ width: 150 }} >
|
||||
@ -175,15 +175,15 @@ class Profile extends Component {
|
||||
}
|
||||
|
||||
if (this.state.secureEdit === false) {
|
||||
secureEditHtml = <Button size={'small'} icon="edit" onClick={() => { this.handleEdit('secureEdit', true) }}>修改</Button>
|
||||
secureEditHtml = <Button icon="edit" onClick={() => { this.handleEdit('secureEdit', true) }}>修改</Button>
|
||||
} else {
|
||||
secureEditHtml = <div>
|
||||
<Input style={{display: this.state.userinfo.role === 'admin' ? 'none': ''}} placeholder="旧的密码" type="password" name="old_password" id="old_password" />
|
||||
<Input placeholder="新的密码" type="password" name="password" id="password" />
|
||||
<Input placeholder="确认密码" type="password" name="verify_pass" id="verify_pass" />
|
||||
<ButtonGroup className="edit-buttons" >
|
||||
<Button size={'small'} className="edit-button" onClick={() => { this.handleEdit('secureEdit', false) }}>Cancel</Button>
|
||||
<Button size={'small'} className="edit-button" onClick={this.updatePassword} type="primary">OK</Button>
|
||||
<Button className="edit-button" onClick={() => { this.handleEdit('secureEdit', false) }}>Cancel</Button>
|
||||
<Button className="edit-button" onClick={this.updatePassword} type="primary">OK</Button>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import LeftMenu from './LeftMenu.js'
|
||||
import List from './List.js'
|
||||
import PropTypes from 'prop-types'
|
||||
import Profile from './Profile.js'
|
||||
import { Row, Col } from 'antd';
|
||||
|
||||
@connect()
|
||||
class User extends Component {
|
||||
@ -22,19 +23,22 @@ class User extends Component {
|
||||
}
|
||||
|
||||
render () {
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<section className="user-box">
|
||||
|
||||
<LeftMenu />
|
||||
<Route path={this.props.match.path + '/list'} component={List} />
|
||||
<Route path={this.props.match.path + '/profile/:uid'} component={Profile} />
|
||||
</section>
|
||||
<div className="g-doc">
|
||||
<Row gutter={16} className="user-box">
|
||||
<Col span={6}>
|
||||
<LeftMenu />
|
||||
</Col>
|
||||
<Col span={18}>
|
||||
<Route path={this.props.match.path + '/list'} component={List} />
|
||||
<Route path={this.props.match.path + '/profile/:uid'} component={Profile} />
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default User
|
||||
export default User
|
||||
|
@ -1,5 +1,9 @@
|
||||
@import '../../styles/mixin.scss';
|
||||
|
||||
.g-doc {
|
||||
margin: .24rem auto;
|
||||
}
|
||||
|
||||
/* .user-box.css */
|
||||
.user-box {
|
||||
@include row-width-limit;
|
||||
@ -15,7 +19,6 @@
|
||||
|
||||
|
||||
.user-list {
|
||||
width: 216px;
|
||||
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20);
|
||||
background: #FFF;
|
||||
border-radius:5px;
|
||||
@ -30,15 +33,15 @@
|
||||
}
|
||||
}
|
||||
.user-name{
|
||||
padding: 24px 0px;
|
||||
text-align: center;
|
||||
padding: 24px 10px;
|
||||
// text-align: center;
|
||||
background-color: #34495e;
|
||||
color: white;
|
||||
font-size: 16px;
|
||||
border-top-left-radius:5px;
|
||||
border-top-right-radius: 5px;
|
||||
span{
|
||||
margin-right: 10px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
.router-content{
|
||||
@ -70,9 +73,6 @@
|
||||
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20);
|
||||
background: #FFF;
|
||||
border-radius:5px;
|
||||
.ant-btn-group{
|
||||
margin-top: 12px;
|
||||
}
|
||||
.user-item {
|
||||
min-height:35px;
|
||||
line-height:35px;
|
||||
@ -87,8 +87,14 @@
|
||||
#old_password{
|
||||
margin-top: 0px;
|
||||
}
|
||||
.ant-col-12{
|
||||
.ant-input{
|
||||
width: 70%;
|
||||
margin-right: 24px;
|
||||
}
|
||||
}
|
||||
.ant-col-4{
|
||||
color: black;
|
||||
color: rgba(0,0,0,0.85);
|
||||
padding: 0px 10px;
|
||||
text-indent: .7em;
|
||||
// background-color: #f1f3f6;
|
||||
|
20
config.json
Normal file
20
config.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"port": "3000",
|
||||
"webhost": "yapi.local.qunar.com",
|
||||
"adminAccount": "admin@admin.com",
|
||||
"db": {
|
||||
"servername": "10.86.40.194",
|
||||
"DATABASE": "yapi",
|
||||
"port": 27017,
|
||||
"user": "test1",
|
||||
"pass": "test1"
|
||||
},
|
||||
"mail": {
|
||||
"host": "smtp.163.com",
|
||||
"port": 465,
|
||||
"auth": {
|
||||
"user": "hellosean1025@163.com",
|
||||
"pass": "helloqunar123"
|
||||
}
|
||||
}
|
||||
}
|
15
package.json
15
package.json
@ -62,9 +62,7 @@
|
||||
"url": "^0.11.0",
|
||||
"wangeditor": "^3.0.4",
|
||||
"ykit-config-antd": "^0.1.3",
|
||||
"ykit-config-react": "^0.4.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ykit-config-react": "^0.4.4",
|
||||
"axios": "^0.16.2",
|
||||
"babel": "^6.5.2",
|
||||
"babel-cli": "^6.24.1",
|
||||
@ -89,12 +87,11 @@
|
||||
"extract-text-webpack-plugin": "^1.0.1",
|
||||
"fast-sass-loader": "^1.2.5",
|
||||
"fs-extra": "^3.0.1",
|
||||
"ghooks": "^2.0.0",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-babel": "^6.1.2",
|
||||
"gulp-watch": "^4.3.11",
|
||||
"node-sass": "^4.5.3",
|
||||
"nodemon": "^1.11.0",
|
||||
|
||||
"ora": "^1.3.0",
|
||||
"prop-types": "^15.5.10",
|
||||
"react": "^15.6.1",
|
||||
@ -106,9 +103,13 @@
|
||||
"sass-loader": "^6.0.6",
|
||||
"scss-loader": "0.0.1",
|
||||
"style-loader": "^0.18.2",
|
||||
"validate-commit-msg": "^2.12.2",
|
||||
"validate-commit-msg": "^2.12.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^1.11.0",
|
||||
"webpack": "^2.0.0",
|
||||
"webpack-node-externals": "^1.6.0"
|
||||
"webpack-node-externals": "^1.6.0",
|
||||
"ghooks": "^2.0.0"
|
||||
},
|
||||
"config": {
|
||||
"ghooks": {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import interfaceModel from '../models/interface.js'
|
||||
import baseController from './base.js'
|
||||
import yapi from '../yapi.js'
|
||||
import interfaceModel from '../models/interface.js';
|
||||
import baseController from './base.js';
|
||||
import yapi from '../yapi.js';
|
||||
|
||||
class interfaceController extends baseController{
|
||||
constructor(ctx){
|
||||
super(ctx)
|
||||
class interfaceController extends baseController {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
this.Model = yapi.getInst(interfaceModel);
|
||||
}
|
||||
|
||||
@ -35,37 +35,39 @@ class interfaceController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/add.json
|
||||
*/
|
||||
async add(ctx){
|
||||
async add(ctx) {
|
||||
let params = ctx.request.body;
|
||||
|
||||
params = yapi.commons.handleParams(params, {
|
||||
project_id: 'number',
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
method: 'string',
|
||||
desc: 'string'
|
||||
})
|
||||
});
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase()
|
||||
params.method = params.method.toUpperCase();
|
||||
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
|
||||
if(!params.project_id){
|
||||
|
||||
if (!params.project_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
|
||||
if(!params.path){
|
||||
if (!params.path) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口请求路径不能为空');
|
||||
}
|
||||
|
||||
if(!yapi.commons.verifyPath(params.path)){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/')
|
||||
if (!yapi.commons.verifyPath(params.path)) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/');
|
||||
}
|
||||
|
||||
|
||||
let checkRepeat = await this.Model.checkRepeat(params.project_id, params.path, params.method);
|
||||
|
||||
if(checkRepeat > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
|
||||
}
|
||||
if (checkRepeat > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
let data = {
|
||||
project_id: params.project_id,
|
||||
title: params.title,
|
||||
@ -74,20 +76,24 @@ class interfaceController extends baseController{
|
||||
method: params.method,
|
||||
req_headers: params.req_headers,
|
||||
req_params_type: params.req_params_type,
|
||||
res_body: params.res_body,
|
||||
res_body: params.res_body,
|
||||
res_body_type: params.res_body_type,
|
||||
uid: this.getUid(),
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
let result = await this.Model.save(data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,16 +107,18 @@ class interfaceController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/get.json
|
||||
*/
|
||||
async get(ctx){
|
||||
async get(ctx) {
|
||||
let params = ctx.request.query;
|
||||
if(!params.id){
|
||||
|
||||
if (!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
|
||||
}
|
||||
try{
|
||||
|
||||
try {
|
||||
let result = await this.Model.get(params.id);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,17 +132,18 @@ class interfaceController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/list.json
|
||||
*/
|
||||
|
||||
async list(ctx){
|
||||
async list(ctx) {
|
||||
let project_id = ctx.request.query.project_id;
|
||||
if(!project_id){
|
||||
|
||||
if (!project_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
try{
|
||||
|
||||
try {
|
||||
let result = await this.Model.list(project_id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,55 +174,76 @@ class interfaceController extends baseController{
|
||||
* @example ./api/interface/up.json
|
||||
*/
|
||||
|
||||
async up(ctx){
|
||||
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()
|
||||
params.method = params.method.toUpperCase();
|
||||
|
||||
let id = ctx.request.body.id;
|
||||
if(!id){
|
||||
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
|
||||
}
|
||||
let interfaceData = await this.Model.get(id);
|
||||
|
||||
if(params.path && !yapi.commons.verifyPath(params.path)){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/')
|
||||
if (params.path && !yapi.commons.verifyPath(params.path)) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/');
|
||||
}
|
||||
|
||||
if(params.path && params.path !== interfaceData.path && params.method !== interfaceData.method){
|
||||
let checkRepeat = await this.Model.checkRepeat(interfaceData.project_id,params.path, params.method);
|
||||
if(checkRepeat > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
|
||||
|
||||
if (params.path && params.path !== interfaceData.path && params.method !== interfaceData.method) {
|
||||
let checkRepeat = await this.Model.checkRepeat(interfaceData.project_id, params.path, params.method);
|
||||
if (checkRepeat > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let data = {
|
||||
up_time: yapi.commons.time()
|
||||
};
|
||||
|
||||
if (params.path) {
|
||||
data.path = params.path;
|
||||
}
|
||||
if (params.title) {
|
||||
data.title = params.title;
|
||||
}
|
||||
if (params.desc) {
|
||||
data.desc = params.desc;
|
||||
}
|
||||
if (params.method) {
|
||||
data.method = params.method;
|
||||
}
|
||||
|
||||
if(params.path) data.path = params.path;
|
||||
if(params.title) data.title = params.title;
|
||||
if(params.desc) data.desc = params.desc;
|
||||
if(params.method) data.method = params.method;
|
||||
if (params.req_headers) {
|
||||
data.req_headers = params.req_headers;
|
||||
}
|
||||
|
||||
if(params.req_headers) data.req_headers = params.req_headers;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if(params.res_body_type) data.res_body_type = params.res_body_type;
|
||||
if(params.res_body) data.res_body = params.res_body;
|
||||
if (params.res_body_type) {
|
||||
data.res_body_type = params.res_body_type;
|
||||
}
|
||||
if (params.res_body) {
|
||||
data.res_body = params.res_body;
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
let result = await this.Model.up(id, data);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
|
||||
}
|
||||
@ -229,27 +259,27 @@ class interfaceController extends baseController{
|
||||
* @example ./api/interface/del.json
|
||||
*/
|
||||
|
||||
async del(ctx){
|
||||
try{
|
||||
let id = ctx.request.body.id;
|
||||
|
||||
if(!id){
|
||||
async del(ctx) {
|
||||
try {
|
||||
let id = ctx.request.body.id;
|
||||
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
|
||||
}
|
||||
|
||||
let data = await this.Model.get(ctx.request.body.id);
|
||||
|
||||
if(data.uid != this.getUid()){
|
||||
if(await this.jungeProjectAuth(data.project_id) !== true){
|
||||
if (data.uid != this.getUid()) {
|
||||
if (await this.jungeProjectAuth(data.project_id) !== true) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let result = await this.Model.del(id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,10 +82,11 @@ class interfaceModel extends baseModel {
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
||||
up(id, data) {
|
||||
data.up_time = yapi.commons.time();
|
||||
return this.model.update({
|
||||
_id: id,
|
||||
_id: id
|
||||
}, data, { runValidators: true });
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,18 @@ exports.log = (msg, type) => {
|
||||
let f;
|
||||
|
||||
switch (type) {
|
||||
case 'log': f = console.log; break;
|
||||
case 'warn': f = console.warn; break;
|
||||
case 'error': f = console.error; break;
|
||||
default: f = console.log; break;
|
||||
case 'log':
|
||||
f = console.log;
|
||||
break;
|
||||
case 'warn':
|
||||
f = console.warn;
|
||||
break;
|
||||
case 'error':
|
||||
f = console.error;
|
||||
break;
|
||||
default:
|
||||
f = console.log;
|
||||
break;
|
||||
}
|
||||
|
||||
f(type + ':', msg);
|
||||
@ -204,8 +212,10 @@ exports.handleParams = (params, 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;
|
||||
case 'string': params[key] = trim(params[key] + '');
|
||||
break;
|
||||
case 'number': params[key] = parseInt(params[key], 10);
|
||||
break;
|
||||
default: params[key] = trim(params + '');
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ import mongoose from 'mongoose';
|
||||
import yapi from '../yapi.js';
|
||||
import autoIncrement from 'mongoose-auto-increment';
|
||||
|
||||
function model(model, schema){
|
||||
if(schema instanceof mongoose.Schema === false){
|
||||
function model(model, schema) {
|
||||
if (schema instanceof mongoose.Schema === false) {
|
||||
schema = new mongoose.Schema(schema);
|
||||
}
|
||||
|
||||
@ -12,20 +12,20 @@ function model(model, schema){
|
||||
return yapi.connect.model(model, schema, model);
|
||||
}
|
||||
|
||||
function connect(){
|
||||
function connect() {
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
let config = yapi.WEBCONFIG;
|
||||
let options = {};
|
||||
|
||||
if(config.user){
|
||||
options.user = config.db.user,
|
||||
if (config.user) {
|
||||
options.user = config.db.user;
|
||||
options.pass = config.db.pass;
|
||||
}
|
||||
|
||||
|
||||
let db = mongoose.connect(`mongodb://${config.db.servername}:${config.db.port}/${config.db.DATABASE}`, options);
|
||||
|
||||
db.then(function (res) {
|
||||
db.then(function () {
|
||||
yapi.commons.log('mongodb load success...');
|
||||
}, function (err) {
|
||||
yapi.commons.log(err, 'Mongo connect error');
|
||||
@ -37,7 +37,7 @@ function connect(){
|
||||
|
||||
yapi.db = model;
|
||||
|
||||
module.exports = {
|
||||
module.exports = {
|
||||
model: model,
|
||||
connect: connect
|
||||
};
|
@ -85,7 +85,7 @@ var baseController = function () {
|
||||
}()
|
||||
}, {
|
||||
key: 'getUid',
|
||||
value: function getUid(ctx) {
|
||||
value: function getUid() {
|
||||
return parseInt(this.$uid, 10);
|
||||
}
|
||||
}, {
|
||||
|
@ -50,7 +50,6 @@ var _project2 = _interopRequireDefault(_project);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
//
|
||||
var groupController = function (_baseController) {
|
||||
(0, _inherits3.default)(groupController, _baseController);
|
||||
|
||||
@ -83,6 +82,7 @@ var groupController = function (_baseController) {
|
||||
case 0:
|
||||
params = ctx.request.body;
|
||||
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
group_name: 'string',
|
||||
group_desc: 'string'
|
||||
@ -133,6 +133,7 @@ var groupController = function (_baseController) {
|
||||
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 = 24;
|
||||
@ -280,7 +281,7 @@ var groupController = function (_baseController) {
|
||||
_context3.prev = 19;
|
||||
_context3.t0 = _context3['catch'](2);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t0.message);
|
||||
|
||||
case 22:
|
||||
case 'end':
|
||||
@ -358,7 +359,7 @@ var groupController = function (_baseController) {
|
||||
_context4.prev = 16;
|
||||
_context4.t0 = _context4['catch'](2);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
|
||||
|
||||
case 19:
|
||||
case 'end':
|
||||
|
@ -94,6 +94,7 @@ var interfaceController = function (_baseController) {
|
||||
case 0:
|
||||
params = ctx.request.body;
|
||||
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
project_id: 'number',
|
||||
title: 'string',
|
||||
@ -160,8 +161,12 @@ 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;
|
||||
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 = 22;
|
||||
return this.Model.save(data);
|
||||
@ -301,7 +306,7 @@ var interfaceController = function (_baseController) {
|
||||
_context3.prev = 10;
|
||||
_context3.t0 = _context3['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t0.message);
|
||||
|
||||
case 13:
|
||||
case 'end':
|
||||
@ -356,6 +361,7 @@ var interfaceController = function (_baseController) {
|
||||
case 0:
|
||||
params = ctx.request.body;
|
||||
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
@ -364,6 +370,7 @@ var interfaceController = function (_baseController) {
|
||||
});
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase();
|
||||
|
||||
id = ctx.request.body.id;
|
||||
|
||||
if (id) {
|
||||
@ -412,18 +419,36 @@ var interfaceController = function (_baseController) {
|
||||
};
|
||||
|
||||
|
||||
if (params.path) data.path = params.path;
|
||||
if (params.title) data.title = params.title;
|
||||
if (params.desc) data.desc = params.desc;
|
||||
if (params.method) data.method = params.method;
|
||||
if (params.path) {
|
||||
data.path = params.path;
|
||||
}
|
||||
if (params.title) {
|
||||
data.title = params.title;
|
||||
}
|
||||
if (params.desc) {
|
||||
data.desc = params.desc;
|
||||
}
|
||||
if (params.method) {
|
||||
data.method = params.method;
|
||||
}
|
||||
|
||||
if (params.req_headers) data.req_headers = params.req_headers;
|
||||
if (params.req_headers) {
|
||||
data.req_headers = params.req_headers;
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
if (params.res_body_type) data.res_body_type = params.res_body_type;
|
||||
if (params.res_body) data.res_body = params.res_body;
|
||||
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 = 28;
|
||||
_context4.next = 31;
|
||||
|
@ -47,13 +47,17 @@ exports.log = function (msg, type) {
|
||||
|
||||
switch (type) {
|
||||
case 'log':
|
||||
f = console.log;break;
|
||||
f = console.log;
|
||||
break;
|
||||
case 'warn':
|
||||
f = console.warn;break;
|
||||
f = console.warn;
|
||||
break;
|
||||
case 'error':
|
||||
f = console.error;break;
|
||||
f = console.error;
|
||||
break;
|
||||
default:
|
||||
f = console.log;break;
|
||||
f = console.log;
|
||||
break;
|
||||
}
|
||||
|
||||
f(type + ':', msg);
|
||||
@ -231,9 +235,11 @@ exports.handleParams = function (params, keys) {
|
||||
if (params[key]) {
|
||||
switch (filter) {
|
||||
case 'string':
|
||||
params[key] = trim(params[key] + '');break;
|
||||
params[key] = trim(params[key] + '');
|
||||
break;
|
||||
case 'number':
|
||||
params[key] = parseInt(params[key], 10);break;
|
||||
params[key] = parseInt(params[key], 10);
|
||||
break;
|
||||
default:
|
||||
params[key] = trim(params + '');
|
||||
}
|
||||
|
@ -31,12 +31,13 @@ function connect() {
|
||||
var options = {};
|
||||
|
||||
if (config.user) {
|
||||
options.user = config.db.user, options.pass = config.db.pass;
|
||||
options.user = config.db.user;
|
||||
options.pass = config.db.pass;
|
||||
}
|
||||
|
||||
var db = _mongoose2.default.connect('mongodb://' + config.db.servername + ':' + config.db.port + '/' + config.db.DATABASE, options);
|
||||
|
||||
db.then(function (res) {
|
||||
db.then(function () {
|
||||
_yapi2.default.commons.log('mongodb load success...');
|
||||
}, function (err) {
|
||||
_yapi2.default.commons.log(err, 'Mongo connect error');
|
||||
|
Loading…
Reference in New Issue
Block a user