feat: optimize auth

This commit is contained in:
sean 2017-08-16 10:56:42 +08:00
parent 96626f5c6f
commit 5ae5fb8789
20 changed files with 355 additions and 133 deletions

View File

@ -42,7 +42,7 @@ class Interface extends Component {
<Tabs.TabPane tab="接口列表" key="list">
<InterfaceMenu projectId={this.props.match.params.id} />
</Tabs.TabPane>
<Tabs.TabPane tab="接口集合" key="col">
<Tabs.TabPane tab="接口集合" key="col" >
<InterfaceColMenu />
</Tabs.TabPane>
</Tabs>

View File

@ -23,6 +23,11 @@
.ant-tabs.ant-tabs-card > .ant-tabs-bar .ant-tabs-tab-active{
background-color: #efefef
}
.ant-tabs.ant-tabs-card > .ant-tabs-bar{
text-align: center;
line-height: 40px;
}
.interface-filter{
padding-left: 10px;

View File

@ -3,12 +3,14 @@ import yapi from '../yapi.js';
import baseController from './base.js';
import projectModel from '../models/project.js';
import userModel from '../models/user.js';
import interfaceModel from '../models/interface.js';
import interfaceColModel from '../models/interfaceCol.js';
import interfaceCaseModel from '../models/interfaceCase.js';
class groupController extends baseController {
constructor(ctx) {
super(ctx);
}
/**
* 添加项目分组
* @interface /group/get
@ -301,18 +303,21 @@ class groupController extends baseController {
try {
let groupInst = yapi.getInst(groupModel);
let projectInst = yapi.getInst(projectModel);
let interfaceInst = yapi.getInst(interfaceModel);
let interfaceColInst = yapi.getInst(interfaceColModel);
let interfaceCaseInst = yapi.getInst(interfaceCaseModel);
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) {
return ctx.body = yapi.commons.resReturn(null, 403, '请先删除该分组下的项目');
}
let projectList =await projectInst.list(id, true);
projectList.forEach(async (p) => {
await interfaceInst.delByProjectId(p._id)
await interfaceCaseInst.delByProjectId(p._id)
await interfaceColInst.delByProjectId(p._id)
})
await projectInst.delByGroupid(id);
let result = await groupInst.del(id);
ctx.body = yapi.commons.resReturn(result);
} catch (err) {

View File

@ -2,6 +2,7 @@ import interfaceModel from '../models/interface.js';
import baseController from './base.js';
import yapi from '../yapi.js';
class interfaceController extends baseController {
constructor(ctx) {
super(ctx);
@ -91,8 +92,11 @@ class interfaceController extends baseController {
if (params.req_body_form) {
data.req_body_form = params.req_body_form;
}
if (params.req_params) {
if (params.req_params && Array.isArray(params.req_params) && params.req_params.length > 0) {
data.type = 'var'
data.req_params = params.req_params;
} else {
data.type = 'static'
}
if (params.req_body_other) {
data.req_body_other = params.req_body_other;
@ -236,9 +240,13 @@ class interfaceController extends baseController {
if (params.req_body_form) {
data.req_body_form = params.req_body_form;
}
if (params.req_params) {
if (params.req_params && Array.isArray(params.req_params) && params.req_params.length > 0) {
data.type = 'var'
data.req_params = params.req_params;
} else {
data.type = 'static'
}
if (params.req_query) {
data.req_query = params.req_query;
}

View File

@ -338,15 +338,18 @@ class projectController extends baseController {
if (!id) {
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
}
let interfaceInst = yapi.getInst(interfaceModel);
let count = await interfaceInst.countByProjectId(id);
if (count > 0) {
return ctx.body = yapi.commons.resReturn(null, 400, '请先删除该项目下所有接口');
}
if (await this.checkAuth(id, 'project', 'danger') !== true) {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
let interfaceInst = yapi.getInst(interfaceModel);
let interfaceColInst = yapi.getInst(interfaceColModel);
let interfaceCaseInst = yapi.getInst(interfaceCaseModel);
await interfaceInst.delByProjectId(id)
await interfaceCaseInst.delByProjectId(id)
await interfaceColInst.delByProjectId(id)
let result = await this.Model.del(id);
ctx.body = yapi.commons.resReturn(result);
} catch (err) {

View File

@ -2,6 +2,24 @@ import yapi from '../yapi.js';
import projectModel from '../models/project.js';
import interfaceModel from '../models/interface.js';
import Mock from 'mockjs';
import _ from 'underscore';
function matchApi(apiPath, apiRule) {
let apiPaths = apiPath.split("/");
let apiRules = apiRule.split("/");
if (apiPaths.length !== apiRules.length) {
return false;
}
for (let i = 0; i < apiRules.length; i++) {
if (apiRules[i] && apiRules[i].indexOf(":") !== 0) {
if (apiRules[i] !== apiPaths[i]) {
return false;
}
}
}
return true;
}
module.exports = async (ctx, next) => {
yapi.commons.log('Server Recevie Request...');
@ -9,7 +27,7 @@ module.exports = async (ctx, next) => {
let hostname = ctx.hostname;
let config = yapi.WEBCONFIG;
let path = ctx.path;
if (path.indexOf('/mock/') !== 0) {
if (next) await next();
@ -20,7 +38,7 @@ module.exports = async (ctx, next) => {
let projectId = paths[2];
paths.splice(0, 3);
path = "/" + paths.join("/");
if(!projectId){
if (!projectId) {
return ctx.body = yapi.commons.resReturn(null, 400, 'projectId不能为空');
}
@ -35,20 +53,33 @@ module.exports = async (ctx, next) => {
if (project === false) {
return ctx.body = yapi.commons.resReturn(null, 400, '不存在的项目');
}
let interfaceData;
let interfaceData, newData, newpath;
let interfaceInst = yapi.getInst(interfaceModel);
try {
interfaceData = await interfaceInst.getByPath(project._id, path.substr(project.basepath.length), ctx.method);
newpath = path.substr(project.basepath.length);
interfaceData = await interfaceInst.getByPath(project._id, newpath, ctx.method);
if (!interfaceData || interfaceData.length === 0) {
//非正常跨域预检请求回应
if(ctx.method === 'OPTIONS'){
if (ctx.method === 'OPTIONS') {
ctx.set("Access-Control-Allow-Origin", "*")
ctx.set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE")
return ctx.body = 'ok'
}
return ctx.body = yapi.commons.resReturn(null, 404, '不存在的api');
let newData = await interfaceInst.getVar(project._id, ctx.method);
let findInterface = _.find(newData, (item) => {
return matchApi(newpath, item.path)
});
if (!findInterface) {
return ctx.body = yapi.commons.resReturn(null, 404, '不存在的api');
}
interfaceData = [
await interfaceInst.get(findInterface._id)
]
}
if (interfaceData.length > 1) {
@ -58,12 +89,12 @@ module.exports = async (ctx, next) => {
interfaceData = interfaceData[0];
ctx.set("Access-Control-Allow-Origin", "*")
if (interfaceData.res_body_type === 'json') {
try{
try {
const res = Mock.mock(
yapi.commons.json_parse(interfaceData.res_body)
);
return ctx.body = res;
}catch(e){
} catch (e) {
return ctx.body = {
errcode: 400,
errmsg: 'mock json数据格式有误',
@ -73,6 +104,7 @@ module.exports = async (ctx, next) => {
}
return ctx.body = interfaceData.res_body;
} catch (e) {
console.error(e)
return ctx.body = yapi.commons.resReturn(null, 409, e.message);
}
};

View File

@ -17,6 +17,7 @@ class interfaceModel extends baseModel {
desc: String,
add_time: Number,
up_time: Number,
type: {type: String, enum: ['static', 'var'], default:'static'},
req_query:[{
name: String, value: String, desc: String, required: {
type:String,
@ -67,6 +68,13 @@ class interfaceModel extends baseModel {
.exec();
}
getVar(project_id, method){
return this.model.find({
type: 'var',
method: method
}).select('_id path').exec()
}
getByPath(project_id, path, method) {
return this.model.find({
project_id: project_id,
@ -104,6 +112,12 @@ class interfaceModel extends baseModel {
});
}
delByProjectId(id){
return this.model.delete({
project_id: id
})
}
up(id, data) {
data.up_time = yapi.commons.time();
return this.model.update({

View File

@ -60,6 +60,12 @@ class interfaceCase extends baseModel {
});
}
delByProjectId(id){
return this.model.delete({
project_id: id
})
}
up(id, data) {
data.up_time = yapi.commons.time()
return this.model.update(

View File

@ -46,6 +46,12 @@ class interfaceCol extends baseModel {
});
}
delByProjectId(id){
return this.model.delete({
project_id: id
})
}
up(id, data) {
data.up_time = yapi.commons.time()
return this.model.update(

View File

@ -87,6 +87,12 @@ class projectModel extends baseModel {
});
}
delByGroupid(groupId){
return this.model.delete({
group_id: groupId
})
}
up(id, data) {
data.up_time = yapi.commons.time();
return this.model.update({

View File

@ -2,6 +2,7 @@ import fs from 'fs-extra';
import path from 'path';
import yapi from '../yapi.js';
import sha1 from 'sha1';
import json5 from 'json5'
exports.resReturn = (data, num, errmsg) => {
num = num || 0;
@ -89,7 +90,7 @@ exports.rand = (min, max) => {
exports.json_parse = (json) => {
try {
return JSON.parse(json);
return json5.parse(json);
} catch (e) {
return json;
}

View File

@ -52,6 +52,18 @@ var _user = require('../models/user.js');
var _user2 = _interopRequireDefault(_user);
var _interface = require('../models/interface.js');
var _interface2 = _interopRequireDefault(_interface);
var _interfaceCol = require('../models/interfaceCol.js');
var _interfaceCol2 = _interopRequireDefault(_interfaceCol);
var _interfaceCase = require('../models/interfaceCase.js');
var _interfaceCase2 = _interopRequireDefault(_interfaceCase);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var groupController = function (_baseController) {
@ -61,7 +73,6 @@ var groupController = function (_baseController) {
(0, _classCallCheck3.default)(this, groupController);
return (0, _possibleConstructorReturn3.default)(this, (groupController.__proto__ || (0, _getPrototypeOf2.default)(groupController)).call(this, ctx));
}
/**
* 添加项目分组
* @interface /group/get
@ -747,70 +758,100 @@ var groupController = function (_baseController) {
}, {
key: 'del',
value: function () {
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
var groupInst, projectInst, _id, count, result;
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
var _this2 = this;
return _regenerator2.default.wrap(function _callee9$(_context9) {
var groupInst, projectInst, interfaceInst, interfaceColInst, interfaceCaseInst, _id, projectList, result;
return _regenerator2.default.wrap(function _callee10$(_context10) {
while (1) {
switch (_context9.prev = _context9.next) {
switch (_context10.prev = _context10.next) {
case 0:
if (!(this.getRole() !== 'admin')) {
_context9.next = 2;
_context10.next = 2;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
case 2:
_context9.prev = 2;
_context10.prev = 2;
groupInst = _yapi2.default.getInst(_group2.default);
projectInst = _yapi2.default.getInst(_project2.default);
interfaceInst = _yapi2.default.getInst(_interface2.default);
interfaceColInst = _yapi2.default.getInst(_interfaceCol2.default);
interfaceCaseInst = _yapi2.default.getInst(_interfaceCase2.default);
_id = ctx.request.body.id;
if (_id) {
_context9.next = 8;
_context10.next = 11;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, 'id不能为空'));
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, 'id不能为空'));
case 8:
_context9.next = 10;
return projectInst.countByGroupId(_id);
case 10:
count = _context9.sent;
if (!(count > 0)) {
_context9.next = 13;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 403, '请先删除该分组下的项目'));
case 11:
_context10.next = 13;
return projectInst.list(_id, true);
case 13:
_context9.next = 15;
projectList = _context10.sent;
projectList.forEach(function () {
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(p) {
return _regenerator2.default.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
_context9.next = 2;
return interfaceInst.delByProjectId(p._id);
case 2:
_context9.next = 4;
return interfaceCaseInst.delByProjectId(p._id);
case 4:
_context9.next = 6;
return interfaceColInst.delByProjectId(p._id);
case 6:
case 'end':
return _context9.stop();
}
}
}, _callee9, _this2);
}));
return function (_x11) {
return _ref10.apply(this, arguments);
};
}());
_context10.next = 17;
return projectInst.delByGroupid(_id);
case 17:
_context10.next = 19;
return groupInst.del(_id);
case 15:
result = _context9.sent;
case 19:
result = _context10.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context9.next = 22;
_context10.next = 26;
break;
case 19:
_context9.prev = 19;
_context9.t0 = _context9['catch'](2);
case 23:
_context10.prev = 23;
_context10.t0 = _context10['catch'](2);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context9.t0.message);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context10.t0.message);
case 22:
case 26:
case 'end':
return _context9.stop();
return _context10.stop();
}
}
}, _callee9, this, [[2, 19]]);
}, _callee10, this, [[2, 23]]);
}));
function del(_x10) {
@ -836,28 +877,28 @@ var groupController = function (_baseController) {
}, {
key: 'up',
value: function () {
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(ctx) {
var groupInst, _id2, data, result;
return _regenerator2.default.wrap(function _callee10$(_context10) {
return _regenerator2.default.wrap(function _callee11$(_context11) {
while (1) {
switch (_context10.prev = _context10.next) {
switch (_context11.prev = _context11.next) {
case 0:
_context10.next = 2;
_context11.next = 2;
return this.checkAuth(id, 'group', 'danger');
case 2:
_context10.t0 = _context10.sent;
_context11.t0 = _context11.sent;
if (!(_context10.t0 !== true)) {
_context10.next = 5;
if (!(_context11.t0 !== true)) {
_context11.next = 5;
break;
}
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 5:
_context10.prev = 5;
_context11.prev = 5;
ctx.request.body = _yapi2.default.commons.handleParams(ctx.request.body, {
id: 'number',
@ -873,32 +914,32 @@ var groupController = function (_baseController) {
if ((0, _keys2.default)(data).length === 0) {
ctx.body = _yapi2.default.commons.resReturn(null, 404, '分组名和分组描述不能为空');
}
_context10.next = 15;
_context11.next = 15;
return groupInst.up(_id2, data);
case 15:
result = _context10.sent;
result = _context11.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context10.next = 22;
_context11.next = 22;
break;
case 19:
_context10.prev = 19;
_context10.t1 = _context10['catch'](5);
_context11.prev = 19;
_context11.t1 = _context11['catch'](5);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context10.t1.message);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context11.t1.message);
case 22:
case 'end':
return _context10.stop();
return _context11.stop();
}
}
}, _callee10, this, [[5, 19]]);
}, _callee11, this, [[5, 19]]);
}));
function up(_x11) {
return _ref10.apply(this, arguments);
function up(_x12) {
return _ref11.apply(this, arguments);
}
return up;

View File

@ -169,8 +169,11 @@ var interfaceController = function (_baseController) {
if (params.req_body_form) {
data.req_body_form = params.req_body_form;
}
if (params.req_params) {
if (params.req_params && Array.isArray(params.req_params) && params.req_params.length > 0) {
data.type = 'var';
data.req_params = params.req_params;
} else {
data.type = 'static';
}
if (params.req_body_other) {
data.req_body_other = params.req_body_other;
@ -447,9 +450,13 @@ var interfaceController = function (_baseController) {
if (params.req_body_form) {
data.req_body_form = params.req_body_form;
}
if (params.req_params) {
if (params.req_params && Array.isArray(params.req_params) && params.req_params.length > 0) {
data.type = 'var';
data.req_params = params.req_params;
} else {
data.type = 'static';
}
if (params.req_query) {
data.req_query = params.req_query;
}

View File

@ -782,7 +782,7 @@ var projectController = function (_baseController) {
key: 'del',
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
var _id, interfaceInst, count, result;
var _id, interfaceInst, interfaceColInst, interfaceCaseInst, result;
return _regenerator2.default.wrap(function _callee8$(_context8) {
while (1) {
@ -799,57 +799,57 @@ var projectController = function (_baseController) {
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
case 4:
interfaceInst = _yapi2.default.getInst(_interface2.default);
_context8.next = 7;
return interfaceInst.countByProjectId(_id);
case 7:
count = _context8.sent;
if (!(count > 0)) {
_context8.next = 10;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '请先删除该项目下所有接口'));
case 10:
_context8.next = 12;
_context8.next = 6;
return this.checkAuth(_id, 'project', 'danger');
case 12:
case 6:
_context8.t0 = _context8.sent;
if (!(_context8.t0 !== true)) {
_context8.next = 15;
_context8.next = 9;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 15:
_context8.next = 17;
case 9:
interfaceInst = _yapi2.default.getInst(_interface2.default);
interfaceColInst = _yapi2.default.getInst(interfaceColModel);
interfaceCaseInst = _yapi2.default.getInst(interfaceCaseModel);
_context8.next = 14;
return interfaceInst.delByProjectId(_id);
case 14:
_context8.next = 16;
return interfaceCaseInst.delByProjectId(_id);
case 16:
_context8.next = 18;
return interfaceColInst.delByProjectId(_id);
case 18:
_context8.next = 20;
return this.Model.del(_id);
case 17:
case 20:
result = _context8.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context8.next = 24;
_context8.next = 27;
break;
case 21:
_context8.prev = 21;
case 24:
_context8.prev = 24;
_context8.t1 = _context8['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t1.message);
case 24:
case 27:
case 'end':
return _context8.stop();
}
}
}, _callee8, this, [[0, 21]]);
}, _callee8, this, [[0, 24]]);
}));
function del(_x9) {

View File

@ -24,11 +24,32 @@ var _mockjs = require('mockjs');
var _mockjs2 = _interopRequireDefault(_mockjs);
var _underscore = require('underscore');
var _underscore2 = _interopRequireDefault(_underscore);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function matchApi(apiPath, apiRule) {
var apiPaths = apiPath.split("/");
var apiRules = apiRule.split("/");
if (apiPaths.length !== apiRules.length) {
return false;
}
for (var i = 0; i < apiRules.length; i++) {
if (apiRules[i] && apiRules[i].indexOf(":") !== 0) {
if (apiRules[i] !== apiPaths[i]) {
return false;
}
}
}
return true;
}
module.exports = function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx, next) {
var hostname, config, path, paths, projectId, projectInst, project, interfaceData, interfaceInst, res;
var hostname, config, path, paths, projectId, projectInst, project, interfaceData, newData, newpath, interfaceInst, _newData, findInterface, res;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
@ -96,22 +117,24 @@ module.exports = function () {
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '不存在的项目'));
case 28:
interfaceData = void 0;
interfaceData = void 0, newData = void 0, newpath = void 0;
interfaceInst = _yapi2.default.getInst(_interface2.default);
_context.prev = 30;
_context.next = 33;
return interfaceInst.getByPath(project._id, path.substr(project.basepath.length), ctx.method);
case 33:
newpath = path.substr(project.basepath.length);
_context.next = 34;
return interfaceInst.getByPath(project._id, newpath, ctx.method);
case 34:
interfaceData = _context.sent;
if (!(!interfaceData || interfaceData.length === 0)) {
_context.next = 40;
_context.next = 50;
break;
}
if (!(ctx.method === 'OPTIONS')) {
_context.next = 39;
_context.next = 40;
break;
}
@ -119,54 +142,78 @@ module.exports = function () {
ctx.set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
return _context.abrupt('return', ctx.body = 'ok');
case 39:
case 40:
_context.next = 42;
return interfaceInst.getVar(project._id, ctx.method);
case 42:
_newData = _context.sent;
findInterface = _underscore2.default.find(_newData, function (item) {
return matchApi(newpath, item.path);
});
if (findInterface) {
_context.next = 46;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 404, '不存在的api'));
case 40:
case 46:
_context.next = 48;
return interfaceInst.get(findInterface._id);
case 48:
_context.t1 = _context.sent;
interfaceData = [_context.t1];
case 50:
if (!(interfaceData.length > 1)) {
_context.next = 42;
_context.next = 52;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '存在多个api请检查数据库'));
case 42:
case 52:
interfaceData = interfaceData[0];
ctx.set("Access-Control-Allow-Origin", "*");
if (!(interfaceData.res_body_type === 'json')) {
_context.next = 53;
_context.next = 63;
break;
}
_context.prev = 45;
_context.prev = 55;
res = _mockjs2.default.mock(_yapi2.default.commons.json_parse(interfaceData.res_body));
return _context.abrupt('return', ctx.body = res);
case 50:
_context.prev = 50;
_context.t1 = _context['catch'](45);
case 60:
_context.prev = 60;
_context.t2 = _context['catch'](55);
return _context.abrupt('return', ctx.body = {
errcode: 400,
errmsg: 'mock json数据格式有误',
data: interfaceData.res_body
});
case 53:
case 63:
return _context.abrupt('return', ctx.body = interfaceData.res_body);
case 56:
_context.prev = 56;
_context.t2 = _context['catch'](30);
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 409, _context.t2.message));
case 66:
_context.prev = 66;
_context.t3 = _context['catch'](30);
case 59:
console.error(_context.t3);
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 409, _context.t3.message));
case 70:
case 'end':
return _context.stop();
}
}
}, _callee, undefined, [[17, 23], [30, 56], [45, 50]]);
}, _callee, undefined, [[17, 23], [30, 66], [55, 60]]);
}));
return function (_x, _x2) {

View File

@ -56,6 +56,7 @@ var interfaceModel = function (_baseModel) {
desc: String,
add_time: Number,
up_time: Number,
type: { type: String, enum: ['static', 'var'], default: 'static' },
req_query: [{
name: String, value: String, desc: String, required: {
type: String,
@ -106,6 +107,14 @@ var interfaceModel = function (_baseModel) {
_id: id
}).exec();
}
}, {
key: 'getVar',
value: function getVar(project_id, method) {
return this.model.find({
type: 'var',
method: method
}).select('_id path').exec();
}
}, {
key: 'getByPath',
value: function getByPath(project_id, path, method) {
@ -145,6 +154,13 @@ var interfaceModel = function (_baseModel) {
_id: id
});
}
}, {
key: 'delByProjectId',
value: function delByProjectId(id) {
return this.model.delete({
project_id: id
});
}
}, {
key: 'up',
value: function up(id, data) {

View File

@ -102,6 +102,13 @@ var interfaceCase = function (_baseModel) {
_id: id
});
}
}, {
key: 'delByProjectId',
value: function delByProjectId(id) {
return this.model.delete({
project_id: id
});
}
}, {
key: 'up',
value: function up(id, data) {

View File

@ -89,6 +89,13 @@ var interfaceCol = function (_baseModel) {
_id: id
});
}
}, {
key: 'delByProjectId',
value: function delByProjectId(id) {
return this.model.delete({
project_id: id
});
}
}, {
key: 'up',
value: function up(id, data) {

View File

@ -131,6 +131,13 @@ var projectModel = function (_baseModel) {
_id: id
});
}
}, {
key: 'delByGroupid',
value: function delByGroupid(groupId) {
return this.model.delete({
group_id: groupId
});
}
}, {
key: 'up',
value: function up(id, data) {

View File

@ -24,6 +24,10 @@ var _sha = require('sha1');
var _sha2 = _interopRequireDefault(_sha);
var _json = require('json5');
var _json2 = _interopRequireDefault(_json);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.resReturn = function (data, num, errmsg) {
@ -111,7 +115,7 @@ exports.rand = function (min, max) {
exports.json_parse = function (json) {
try {
return JSON.parse(json);
return _json2.default.parse(json);
} catch (e) {
return json;
}