mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
feat: 增加后端导入接口
This commit is contained in:
parent
9cfd1b88a8
commit
ed7924efa8
@ -552,7 +552,7 @@ export default class Run extends Component {
|
||||
<div>
|
||||
<a
|
||||
target="blank"
|
||||
href="/attachment/cross-request-v2.0.1.zip"
|
||||
href="/api/interface/download_crx"
|
||||
> [手动下载] </a>
|
||||
<span> zip 文件解压后将 crx 文件拖入到 chrome://extensions/ </span>
|
||||
<a
|
||||
|
@ -1 +1 @@
|
||||
module.exports = {}
|
||||
module.exports = {qsso : require('plugins/yapi-plugin-qsso/client.js')}
|
@ -255,6 +255,14 @@ class interfaceController extends baseController {
|
||||
}
|
||||
}
|
||||
|
||||
async downloadCrx(ctx){
|
||||
let filename = 'crossRequest.zip';
|
||||
let dataBuffer = yapi.fs.readFileSync(yapi.path.join(yapi.WEBROOT, 'static/attachment/cross-request-v2.0.1.zip'));
|
||||
ctx.set('Content-disposition', 'attachment; filename=' + filename);
|
||||
ctx.set('Content-Type', 'application/zip');
|
||||
ctx.body = dataBuffer;
|
||||
}
|
||||
|
||||
async listByCat(ctx) {
|
||||
let catid = ctx.request.query.catid;
|
||||
if (!catid) {
|
||||
|
@ -236,6 +236,66 @@ class interfaceColController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
async addCaseList(ctx){
|
||||
try{
|
||||
let params = ctx.request.body;
|
||||
params = yapi.commons.handleParams(params, {
|
||||
project_id: 'number',
|
||||
col_id: 'number'
|
||||
});
|
||||
if(!params.interface_list || !Array.isArray(params.interface_list)){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, 'interface_list 参数有误');
|
||||
}
|
||||
|
||||
if (!params.project_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
|
||||
let auth = await this.checkAuth(params.project_id, 'project', 'edit');
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
|
||||
|
||||
if (!params.col_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口集id不能为空');
|
||||
}
|
||||
|
||||
let data = {
|
||||
uid: this.getUid(),
|
||||
index: 0,
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time(),
|
||||
project_id: params.project_id,
|
||||
col_id: params.col_id
|
||||
}
|
||||
|
||||
for(let i=0; i<params.interface_list.length; i++){
|
||||
let interfaceData = await this.interfaceModel.getBaseinfo(params.interface_list[i]);
|
||||
data.interface_id = params.interface_list[i];
|
||||
data.casename = interfaceData.title;
|
||||
await this.caseModel.save(data);
|
||||
let username = this.getUsername();
|
||||
this.colModel.get(params.col_id).then((col)=>{
|
||||
yapi.commons.saveLog({
|
||||
content: `用户 "${username}" 在接口集 "${col.name}" 下导入了接口 ${data.casename}`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: params.project_id
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
this.projectModel.up(params.project_id,{up_time: new Date().getTime()}).then();
|
||||
|
||||
ctx.body = yapi.commons.resReturn('ok');
|
||||
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新一个接口用例
|
||||
* @interface /col/up_case
|
||||
|
@ -244,6 +244,11 @@ let routerConfig = {
|
||||
"path": "add",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "downloadCrx",
|
||||
"path" : "download_crx",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "getCatMenu",
|
||||
"path": "getCatMenu",
|
||||
@ -320,6 +325,11 @@ let routerConfig = {
|
||||
action: "addCol",
|
||||
path: "add_col",
|
||||
method: "post"
|
||||
},{
|
||||
action: 'addCaseList',
|
||||
path: 'add_case_list',
|
||||
method: 'post'
|
||||
|
||||
}, {
|
||||
action: "list",
|
||||
path: "list",
|
||||
|
Loading…
Reference in New Issue
Block a user