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
26760a6a4e
@ -37,6 +37,7 @@ module.exports = {
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"strict": 0
|
||||
"strict": 0,
|
||||
"comma-dangle": ["error", "never"]
|
||||
}
|
||||
};
|
@ -2,7 +2,7 @@
|
||||
@import '../../styles/mixin.scss';
|
||||
|
||||
.footer{
|
||||
// max-width: 12rem;
|
||||
@include wrap-width-limit;
|
||||
margin: 0px auto;
|
||||
clear: both;
|
||||
font-size: 12px;
|
||||
|
@ -16,10 +16,10 @@ const MenuUser = (props) => (
|
||||
"boxShadow":"0 1px 6px rgba(0, 0, 0, 0.3)"
|
||||
}}
|
||||
>
|
||||
<Menu.Item key="0" style={{"fontSize": ".14rem"}}>
|
||||
<Menu.Item key="0">
|
||||
<Link to={`/user/profile/${props.uid}`} onClick={props.relieveLink}><Icon type="user"/>个人中心</Link>
|
||||
</Menu.Item>
|
||||
<Menu.Item key="1" style={{"fontSize": ".14rem"}}>
|
||||
<Menu.Item key="1">
|
||||
<a onClick={props.logout}><Icon type="logout" />退出</a>
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
@ -150,8 +150,11 @@ export default class HeaderCom extends Component {
|
||||
'background': 'url(./image/header-bg-img.jpg) no-repeat',
|
||||
'backgroundSize':'100% 100%'
|
||||
};
|
||||
const headerShadeStyle = login?{}:{
|
||||
'background': 'linear-gradient(to bottom,rgba(0,0,0,0.6),rgba(0,0,0,0.5))'
|
||||
const headerShadeStyle = login? {
|
||||
'padding':'0'
|
||||
}: {
|
||||
'background': 'linear-gradient(to bottom,rgba(0,0,0,0.6),rgba(0,0,0,0.5))',
|
||||
'padding':'0'
|
||||
};
|
||||
return (
|
||||
<acticle className={`header-box`} style={headerImgStyle}>
|
||||
@ -192,4 +195,4 @@ export default class HeaderCom extends Component {
|
||||
</acticle>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ $color-black-light : #404040;
|
||||
display: block;
|
||||
font-size: 0.14rem;
|
||||
z-index: 99;
|
||||
// 内容宽度
|
||||
@include wrap-width-limit;
|
||||
.content {
|
||||
@include row-width-limit;
|
||||
margin: 0 auto;
|
||||
|
@ -52,6 +52,8 @@ $color-white: #fff;
|
||||
}
|
||||
}
|
||||
.img-container{
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
padding-right: .15rem;
|
||||
//background-image: url("#{$imgUrl}demo-img.png");
|
||||
img{
|
||||
|
@ -12,9 +12,10 @@ $color-black-lighter: #404040;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
.main-one{
|
||||
@include wrap-width-limit;
|
||||
.home-des{
|
||||
color: $color-blue-grey-lighter;
|
||||
padding: .5rem 0 0;
|
||||
padding: .4rem 0 0;
|
||||
.title{
|
||||
font-size: .6rem;
|
||||
}
|
||||
@ -26,7 +27,7 @@ $color-black-lighter: #404040;
|
||||
color: $color-white;
|
||||
}
|
||||
.img-container{
|
||||
margin-bottom: -.2rem;
|
||||
margin-bottom: -.3rem;
|
||||
img{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
@ -75,6 +76,7 @@ $color-black-lighter: #404040;
|
||||
.main-part{
|
||||
padding: .9rem .5rem;
|
||||
height: 5.8rem;
|
||||
@include wrap-width-limit;
|
||||
&:nth-child(odd){
|
||||
background-color: $color-blue-lighter;
|
||||
}
|
||||
@ -83,6 +85,7 @@ $color-black-lighter: #404040;
|
||||
}
|
||||
}
|
||||
.feat-part{
|
||||
@include wrap-width-limit;
|
||||
padding: .9rem .5rem;
|
||||
background-color: $color-white;
|
||||
p{
|
||||
|
@ -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;
|
||||
|
@ -2,3 +2,7 @@
|
||||
max-width: 11.7rem;
|
||||
min-width: 9.7rem;
|
||||
}
|
||||
|
||||
@mixin wrap-width-limit {
|
||||
min-width: 10.7rem;
|
||||
}
|
||||
|
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"
|
||||
}
|
||||
}
|
||||
}
|
21
config_example.json
Normal file
21
config_example.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"port": "3000",
|
||||
"webhost": "yapi.local.qunar.com",
|
||||
"adminAccount": "admin@admin.com",
|
||||
"db": {
|
||||
"servername": "127.0.0.1",
|
||||
"DATABASE": "yapi",
|
||||
"port": 27017,
|
||||
"user": "test1",
|
||||
"pass": "test1"
|
||||
},
|
||||
"mail": {
|
||||
"host": "smtp.163.com",
|
||||
"port": 465,
|
||||
"from": "***@163.com",
|
||||
"auth": {
|
||||
"user": "***@163.com",
|
||||
"pass": "*****"
|
||||
}
|
||||
}
|
||||
}
|
32
gulpfile.js
32
gulpfile.js
@ -12,14 +12,14 @@ const SRC = 'server/**/*.js';
|
||||
|
||||
function generateBabel(status) {
|
||||
const babelProcess = babel({
|
||||
presets: ['es2015', "stage-3"],
|
||||
presets: ['es2015', 'stage-3'],
|
||||
plugins: ['transform-runtime']
|
||||
});
|
||||
|
||||
babelProcess.on('error', function (e) {
|
||||
const restart = status ? status.count < 2 : true;
|
||||
|
||||
console.error(e);
|
||||
console.error(e); // eslint-disable-line
|
||||
output('error', 'babel 编译失败!', restart);
|
||||
|
||||
if (status) {
|
||||
@ -39,7 +39,13 @@ function excuteCmd(cmd, args, opts) {
|
||||
});
|
||||
|
||||
command.stderr.on('data', data => {
|
||||
output('log', `${NAME} ${data.toString()}`, true);
|
||||
const message = data.toString();
|
||||
|
||||
output('log', `${NAME} ${message}`, true);
|
||||
|
||||
if (~message.indexOf('building complete')) {
|
||||
waitingSpinner();
|
||||
}
|
||||
});
|
||||
|
||||
return command;
|
||||
@ -50,12 +56,12 @@ function output(type, message, restart = false) {
|
||||
|
||||
if (type === 'success') {
|
||||
message = '✔ ' + message;
|
||||
console.log(chalk.green(message));
|
||||
console.log(chalk.green(message)); // eslint-disable-line
|
||||
} else if (type === 'error') {
|
||||
message = '✖ ' + message;
|
||||
console.log(chalk.red(message));
|
||||
console.log(chalk.red(message)); // eslint-disable-line
|
||||
} else {
|
||||
console.log(message);
|
||||
console.log(message); // eslint-disable-line
|
||||
}
|
||||
if (restart) {
|
||||
spinner.start();
|
||||
@ -63,6 +69,7 @@ function output(type, message, restart = false) {
|
||||
}
|
||||
|
||||
function waitingSpinner() {
|
||||
spinner.stop();
|
||||
spinner = ora({
|
||||
text: '等待文件变更...',
|
||||
spinner: 'circleQuarters',
|
||||
@ -71,7 +78,7 @@ function waitingSpinner() {
|
||||
}
|
||||
|
||||
gulp.task('removeDist', [], function () {
|
||||
return fs.removeSync(DIST)
|
||||
return fs.removeSync(DIST);
|
||||
});
|
||||
|
||||
gulp.task('initialBuild', ['removeDist'], () => {
|
||||
@ -95,9 +102,14 @@ gulp.task('initialBuild', ['removeDist'], () => {
|
||||
});
|
||||
|
||||
gulp.task('default', ['initialBuild'], () => {
|
||||
gulp.watch(SRC, (event) => {
|
||||
let originFilePath = path.relative(path.join(__dirname, 'server'), event.path)
|
||||
let distPath = path.resolve(DIST, path.join(originFilePath))
|
||||
gulp.watch('client/**/*', event => {
|
||||
spinner.stop();
|
||||
spinner = ora(`正在编译 ${event.path}`).start();
|
||||
});
|
||||
|
||||
gulp.watch(SRC, event => {
|
||||
let originFilePath = path.relative(path.join(__dirname, 'server'), event.path);
|
||||
let distPath = path.resolve(DIST, path.join(originFilePath));
|
||||
spinner.text = `正在编译 ${event.path}...`;
|
||||
|
||||
gulp.src(event.path).pipe(generateBabel())
|
||||
|
16
package.json
16
package.json
@ -25,6 +25,7 @@
|
||||
"copy-webpack-plugin": "^4.0.1",
|
||||
"core-decorators": "^0.17.0",
|
||||
"cross-request": "^1.0.1",
|
||||
"eslint-loader": "^1.9.0",
|
||||
"fast-sass-loader": "^1.2.5",
|
||||
"fs-extra": "^3.0.1",
|
||||
"json2html": "0.0.8",
|
||||
@ -61,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",
|
||||
@ -88,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",
|
||||
@ -105,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,27 +0,0 @@
|
||||
/**
|
||||
* config.js是用来第一次安装初始化网站配置,如果不用默认的runtime_path,可以直接修改runtime_path路径
|
||||
*/
|
||||
let config = {
|
||||
"port": 80,
|
||||
"runtime_path": '',
|
||||
"webhost": "yapi.local.qunar.com",
|
||||
"adminAccount": "admin@admin.com",
|
||||
"db": {
|
||||
"servername": "127.0.0.1",
|
||||
"DATABASE": "yapi",
|
||||
"port": 27017
|
||||
},
|
||||
"mail": {
|
||||
"host": "smtp.mail.com",
|
||||
"from": "****@mail.com",
|
||||
"port": 4652,
|
||||
"auth": {
|
||||
"user": "****@mail.com",
|
||||
"pass": "**********"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = config
|
||||
|
||||
|
@ -1,20 +1,19 @@
|
||||
import yapi from '../yapi.js'
|
||||
import projectModel from '../models/project.js'
|
||||
import userModel from '../models/user.js'
|
||||
import yapi from '../yapi.js';
|
||||
import projectModel from '../models/project.js';
|
||||
import userModel from '../models/user.js';
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
|
||||
class baseController{
|
||||
constructor(ctx){
|
||||
class baseController {
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
//网站上线后,role对象key是不能修改的,value可以修改
|
||||
this.roles = {
|
||||
admin: 'Admin',
|
||||
member: '网站会员'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async init(ctx){
|
||||
async init(ctx) {
|
||||
this.$user = null;
|
||||
let ignoreRouter = [
|
||||
'/user/login_by_token',
|
||||
@ -22,73 +21,93 @@ class baseController{
|
||||
'/user/reg',
|
||||
'/user/status',
|
||||
'/user/logout'
|
||||
]
|
||||
if(ignoreRouter.indexOf(ctx.path) > -1){
|
||||
];
|
||||
if (ignoreRouter.indexOf(ctx.path) > -1) {
|
||||
this.$auth = true;
|
||||
}else{
|
||||
await this.checkLogin(ctx)
|
||||
} else {
|
||||
await this.checkLogin(ctx);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
getUid(ctx){
|
||||
getUid() {
|
||||
return parseInt(this.$uid, 10);
|
||||
}
|
||||
|
||||
async checkLogin(ctx){
|
||||
async checkLogin(ctx) {
|
||||
let token = ctx.cookies.get('_yapi_token');
|
||||
let uid = ctx.cookies.get('_yapi_uid');
|
||||
try{
|
||||
if(!token || !uid) return false;
|
||||
let uid = ctx.cookies.get('_yapi_uid');
|
||||
|
||||
try {
|
||||
if (!token || !uid) return false;
|
||||
let userInst = yapi.getInst(userModel); //创建user实体
|
||||
let result = await userInst.findById(uid);
|
||||
let decoded = jwt.verify(token, result.passsalt)
|
||||
if(decoded.uid == uid){
|
||||
let decoded = jwt.verify(token, result.passsalt);
|
||||
|
||||
if (decoded.uid == uid) {
|
||||
this.$uid = uid;
|
||||
this.$auth = true;
|
||||
this.$user = result;
|
||||
this.$user = result;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async getLoginStatus(ctx){
|
||||
if(await this.checkLogin(ctx) === true){
|
||||
return ctx.body = yapi.commons.resReturn(yapi.commons.fieldSelect(this.$user,['_id','username','email', 'up_time', 'add_time']));
|
||||
async getLoginStatus(ctx) {
|
||||
if (await this.checkLogin(ctx) === true) {
|
||||
return ctx.body = yapi.commons.resReturn(yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time']));
|
||||
}
|
||||
return ctx.body = yapi.commons.resReturn(null, 300 , 'Please login.');
|
||||
|
||||
return ctx.body = yapi.commons.resReturn(null, 300, 'Please login.');
|
||||
}
|
||||
|
||||
getRole(){
|
||||
getRole() {
|
||||
return this.$user.role;
|
||||
}
|
||||
|
||||
async jungeProjectAuth(id){
|
||||
async jungeProjectAuth(id) {
|
||||
let model = yapi.getInst(projectModel);
|
||||
if(this.getRole() === 'admin') return true;
|
||||
if(!id) return false;
|
||||
let result = await model.get(id);
|
||||
if(result.uid === this.getUid()){
|
||||
|
||||
if (this.getRole() === 'admin') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let result = await model.get(id);
|
||||
|
||||
if (result.uid === this.getUid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async jungeMemberAuth(id, member_uid){
|
||||
async jungeMemberAuth(id, member_uid) {
|
||||
let model = yapi.getInst(projectModel);
|
||||
if(this.getRole() === 'admin') return true;
|
||||
if(!id || !member_uid) return false;
|
||||
let result = await model.checkMemberRepeat(id, member_uid);
|
||||
if(result > 0){
|
||||
|
||||
if (this.getRole() === 'admin') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!id || !member_uid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let result = await model.checkMemberRepeat(id, member_uid);
|
||||
|
||||
if (result > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = baseController
|
||||
module.exports = baseController;
|
@ -1,14 +1,12 @@
|
||||
import groupModel from '../models/group.js'
|
||||
import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
import projectModel from '../models/project.js'
|
||||
import groupModel from '../models/group.js';
|
||||
import yapi from '../yapi.js';
|
||||
import baseController from './base.js';
|
||||
import projectModel from '../models/project.js';
|
||||
|
||||
//
|
||||
class groupController extends baseController{
|
||||
constructor(ctx){
|
||||
super(ctx)
|
||||
class groupController extends baseController {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
@ -23,37 +21,45 @@ 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,'没有权限');
|
||||
});
|
||||
|
||||
if (this.getRole() !== 'admin') {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '没有权限');
|
||||
}
|
||||
if(!params.group_name){
|
||||
|
||||
if (!params.group_name) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组名不能为空');
|
||||
}
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
|
||||
var checkRepeat = await groupInst.checkRepeat(params.group_name);
|
||||
if(checkRepeat > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '项目分组名已存在');
|
||||
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
|
||||
let checkRepeat = await groupInst.checkRepeat(params.group_name);
|
||||
|
||||
if (checkRepeat > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '项目分组名已存在');
|
||||
}
|
||||
|
||||
let data = {
|
||||
group_name: params.group_name,
|
||||
group_desc: params.group_desc,
|
||||
uid: this.getUid(),
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
try{
|
||||
};
|
||||
|
||||
try {
|
||||
let result = await groupInst.save(data);
|
||||
|
||||
result = yapi.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,14 +71,13 @@ class groupController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/group/list.json
|
||||
*/
|
||||
|
||||
async list(ctx) {
|
||||
try{
|
||||
try {
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
let result = await groupInst.list();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,27 +91,30 @@ class groupController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/group/del.json
|
||||
*/
|
||||
async del(ctx) {
|
||||
if (this.getRole() !== 'admin') {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '没有权限');
|
||||
}
|
||||
|
||||
async del(ctx){
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
}
|
||||
try{
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
var projectInst = yapi.getInst(projectModel);
|
||||
let id = ctx.request.body.id;
|
||||
if(!id){
|
||||
try {
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
let projectInst = yapi.getInst(projectModel);
|
||||
let id = ctx.request.body.id;
|
||||
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, 'id不能为空');
|
||||
}
|
||||
let count = await projectInst.countByGroupId(id);
|
||||
if(count > 0){
|
||||
|
||||
let count = await projectInst.countByGroupId(id);
|
||||
|
||||
if (count > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 403, '请先删除该分组下的项目');
|
||||
}
|
||||
|
||||
let result = await groupInst.del(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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,33 +130,32 @@ class groupController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/group/up.json
|
||||
*/
|
||||
|
||||
async up(ctx){
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
async up(ctx) {
|
||||
if (this.getRole() !== 'admin') {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '没有权限');
|
||||
}
|
||||
try{
|
||||
|
||||
|
||||
try {
|
||||
|
||||
ctx.request.body = yapi.commons.handleParams(ctx.request.body, {
|
||||
id: 'number',
|
||||
group_name: 'string',
|
||||
group_desc: 'string'
|
||||
})
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
});
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
let id = ctx.request.body.id;
|
||||
let data = {};
|
||||
ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name)
|
||||
ctx.request.body.group_desc && (data.group_desc = ctx.request.body.group_desc)
|
||||
if(Object.keys(data).length === 0 ){
|
||||
ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name);
|
||||
ctx.request.body.group_desc && (data.group_desc = ctx.request.body.group_desc);
|
||||
if (Object.keys(data).length === 0) {
|
||||
ctx.body = yapi.commons.resReturn(null, 404, '分组名和分组描述不能为空');
|
||||
}
|
||||
let result = await groupInst.up(id, data);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = groupController
|
||||
module.exports = groupController;
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import fs from 'fs-extra';
|
||||
import initConfig from './utils/initConfig.js'
|
||||
import yapi from './yapi.js';
|
||||
import commons from './utils/commons';
|
||||
import dbModule from './utils/db.js';
|
||||
|
@ -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
|
||||
};
|
@ -1,22 +1,17 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import nodemailer from 'nodemailer';
|
||||
import config from '../runtime/config.json';
|
||||
import config from '../../config.json';
|
||||
|
||||
let insts = new Map();
|
||||
let mail;
|
||||
|
||||
if(!config.runtime_path){
|
||||
config.runtime_path = path.join(path.resolve(__dirname, '../'), 'runtime')
|
||||
}
|
||||
|
||||
const WEBROOT = path.resolve(__dirname, '..'); //路径
|
||||
const WEBROOT_SERVER = __dirname;
|
||||
const WEBROOT_RUNTIME = config.runtime_path;
|
||||
const WEBROOT_RUNTIME = path.resolve(__dirname, '../..');
|
||||
const WEBROOT_LOG = path.join(WEBROOT_RUNTIME, 'log');
|
||||
const WEBCONFIG = config;
|
||||
|
||||
fs.ensureDirSync(WEBROOT_RUNTIME);
|
||||
fs.ensureDirSync(WEBROOT_LOG);
|
||||
|
||||
if (WEBCONFIG.mail) {
|
||||
|
@ -1,27 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* config.js是用来第一次安装初始化网站配置,如果不用默认的runtime_path,可以直接修改runtime_path路径
|
||||
*/
|
||||
var config = {
|
||||
"port": 80,
|
||||
"runtime_path": '',
|
||||
"webhost": "yapi.local.qunar.com",
|
||||
"adminAccount": "admin@admin.com",
|
||||
"db": {
|
||||
"servername": "127.0.0.1",
|
||||
"DATABASE": "yapi",
|
||||
"port": 27017
|
||||
},
|
||||
"mail": {
|
||||
"host": "smtp.mail.com",
|
||||
"from": "****@mail.com",
|
||||
"port": 4652,
|
||||
"auth": {
|
||||
"user": "****@mail.com",
|
||||
"pass": "**********"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config;
|
@ -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;
|
||||
|
@ -4,10 +4,6 @@ var _fsExtra = require('fs-extra');
|
||||
|
||||
var _fsExtra2 = _interopRequireDefault(_fsExtra);
|
||||
|
||||
var _initConfig = require('./utils/initConfig.js');
|
||||
|
||||
var _initConfig2 = _interopRequireDefault(_initConfig);
|
||||
|
||||
var _yapi = require('./yapi.js');
|
||||
|
||||
var _yapi2 = _interopRequireDefault(_yapi);
|
||||
|
@ -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');
|
||||
|
@ -16,7 +16,7 @@ var _nodemailer = require('nodemailer');
|
||||
|
||||
var _nodemailer2 = _interopRequireDefault(_nodemailer);
|
||||
|
||||
var _config = require('../runtime/config.json');
|
||||
var _config = require('../../config.json');
|
||||
|
||||
var _config2 = _interopRequireDefault(_config);
|
||||
|
||||
@ -25,17 +25,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
||||
var insts = new _map2.default();
|
||||
var mail = void 0;
|
||||
|
||||
if (!_config2.default.runtime_path) {
|
||||
_config2.default.runtime_path = _path2.default.join(_path2.default.resolve(__dirname, '../'), 'runtime');
|
||||
}
|
||||
|
||||
var WEBROOT = _path2.default.resolve(__dirname, '..'); //路径
|
||||
var WEBROOT_SERVER = __dirname;
|
||||
var WEBROOT_RUNTIME = _config2.default.runtime_path;
|
||||
var WEBROOT_RUNTIME = _path2.default.resolve(__dirname, '../..');
|
||||
var WEBROOT_LOG = _path2.default.join(WEBROOT_RUNTIME, 'log');
|
||||
var WEBCONFIG = _config2.default;
|
||||
|
||||
_fsExtra2.default.ensureDirSync(WEBROOT_RUNTIME);
|
||||
_fsExtra2.default.ensureDirSync(WEBROOT_LOG);
|
||||
|
||||
if (WEBCONFIG.mail) {
|
||||
|
Loading…
Reference in New Issue
Block a user