mirror of
https://github.com/YMFE/yapi.git
synced 2025-04-06 15:00:26 +08:00
feat: /api/open/import_data 新增 url 参数,支持服务端 url 导入
This commit is contained in:
parent
b6dec5c07b
commit
ad92b1242e
@ -1,5 +1,6 @@
|
||||
### v1.5.3
|
||||
* cross-request 升级到 2.10
|
||||
* /api/open/import_data 新增 url 参数,支持服务端 url 导入
|
||||
|
||||
### v1.5.2
|
||||
* 新增 openapi `/api/project/get`,可获取项目基本信息
|
||||
|
@ -81,23 +81,25 @@ class openController extends baseController {
|
||||
return (ctx.body = yapi.commons.resReturn(null, 40022, '不存在的导入方式'));
|
||||
}
|
||||
|
||||
if (!content) {
|
||||
return (ctx.body = yapi.commons.resReturn(null, 40022, 'json 不能为空'));
|
||||
if (!content || !ctx.params.url) {
|
||||
return (ctx.body = yapi.commons.resReturn(null, 40022, 'json 或者 url 参数,不能都为空'));
|
||||
}
|
||||
try {
|
||||
if(content.indexOf('http://') === 0 || content.indexOf('https://') === 0){
|
||||
let request = require("request");// let Promise = require('Promise');
|
||||
let syncGet = function (url){
|
||||
return new Promise(function(resolve, reject){
|
||||
request.get({url : url}, function(error, response, body){
|
||||
if(error){
|
||||
reject(error);
|
||||
}else{
|
||||
resolve(body);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
let request = require("request");// let Promise = require('Promise');
|
||||
let syncGet = function (url){
|
||||
return new Promise(function(resolve, reject){
|
||||
request.get({url : url}, function(error, response, body){
|
||||
if(error){
|
||||
reject(error);
|
||||
}else{
|
||||
resolve(body);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
if(ctx.params.url){
|
||||
content = await syncGet(ctx.params.url);
|
||||
}else if(content.indexOf('http://') === 0 || content.indexOf('https://') === 0){
|
||||
content = await syncGet(content);
|
||||
}
|
||||
content = JSON.parse(content);
|
||||
|
Loading…
x
Reference in New Issue
Block a user