|
|
@@ -4,8 +4,54 @@ use Think\Controller;
|
|
|
class ImportController extends BaseController {
|
|
|
|
|
|
|
|
|
+ //自动检测导入的文件类型从而选择不同的控制器方法
|
|
|
+ public function auto(){
|
|
|
+ set_time_limit(100);
|
|
|
+ ini_set('memory_limit','200M');
|
|
|
+ $login_user = $this->checkLogin();
|
|
|
+ $filename = $_FILES["file"]["name"] ;
|
|
|
+ $file = $_FILES["file"]["tmp_name"] ;
|
|
|
+ //文件后缀
|
|
|
+ $tail = substr(strrchr($filename, '.'), 1);
|
|
|
+
|
|
|
+ if ($tail == 'zip') {
|
|
|
+ $zipArc = new \ZipArchive();
|
|
|
+ $ret = $zipArc->open($file, \ZipArchive::CREATE);
|
|
|
+ $info = $zipArc->getFromName(DIRECTORY_SEPARATOR."info.json") ;
|
|
|
+ if ($info) {
|
|
|
+ $info_array = json_decode($info ,1 );
|
|
|
+ if ($info_array) {
|
|
|
+ $this->markdown($info_array);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($tail == 'json') {
|
|
|
+ $json = file_get_contents($file) ;
|
|
|
+ $json_array = json_decode($json ,1 );
|
|
|
+ unset($json);
|
|
|
+ if ($json_array['swagger'] && $json_array['info']) {
|
|
|
+ R("ImportSwagger/import");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if ($json_array['id']) {
|
|
|
+ R("ImportPostman/import");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if ($json_array['info']) {
|
|
|
+ R("ImportPostman/import");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->sendError(10101);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
//导入markdown压缩包
|
|
|
- public function markdown(){
|
|
|
+ public function markdown($info_array){
|
|
|
set_time_limit(100);
|
|
|
ini_set('memory_limit','200M');
|
|
|
|
|
|
@@ -14,11 +60,13 @@ class ImportController extends BaseController {
|
|
|
$file = $_FILES["file"]["tmp_name"] ;
|
|
|
//$file = "../Public/markdown.zip" ; //test
|
|
|
|
|
|
- $zipArc = new \ZipArchive();
|
|
|
- $ret = $zipArc->open($file, \ZipArchive::CREATE);
|
|
|
- $info = $zipArc->getFromName(DIRECTORY_SEPARATOR."info.json") ;
|
|
|
- $info_array = json_decode($info ,1 );
|
|
|
- unset($info);
|
|
|
+ if (!$info_array) {
|
|
|
+ $zipArc = new \ZipArchive();
|
|
|
+ $ret = $zipArc->open($file, \ZipArchive::CREATE);
|
|
|
+ $info = $zipArc->getFromName(DIRECTORY_SEPARATOR."info.json") ;
|
|
|
+ $info_array = json_decode($info ,1 );
|
|
|
+ unset($info);
|
|
|
+ }
|
|
|
|
|
|
if ($info_array) {
|
|
|
|