mxd 4 years ago
parent
commit
cb321cf55e

+ 1 - 1
README.md

@@ -37,7 +37,7 @@
 <dependency>
 	<groupId>org.ssssssss</groupId>
 	<artifactId>magic-api-spring-boot-starter</artifactId>
-    <version>0.2.2</version>
+    <version>0.3.0</version>
 </dependency>
 ```
 ## 修改application.properties

File diff suppressed because it is too large
+ 31 - 19
db/magic-api.sql


+ 22 - 0
db/v0.2.x-v0.3.sql

@@ -0,0 +1,22 @@
+SET NAMES utf8mb4;
+SET FOREIGN_KEY_CHECKS = 0;
+
+ALTER TABLE `magic_api_info` ADD COLUMN `api_group_prefix` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '分组前缀' AFTER `api_group_name`;
+ALTER TABLE `magic_api_info` ADD COLUMN `api_output` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '输出结果' AFTER `api_group_prefix`;
+-- ----------------------------
+-- Table structure for magic_api_info_his
+-- ----------------------------
+CREATE TABLE `magic_api_info_his`  (
+  `id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'api_id',
+  `api_method` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求方法',
+  `api_path` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求路径',
+  `api_script` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '接口脚本',
+  `api_parameter` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '接口参数',
+  `api_option` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '接口选项',
+  `api_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '接口名称',
+  `api_group_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '接口分组',
+  `api_group_prefix` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '分组前缀',
+  `api_output` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '输出结果',
+  `api_create_time` bigint(20) NULL DEFAULT NULL COMMENT '创建时间',
+  `api_update_time` bigint(20) NULL DEFAULT NULL COMMENT '修改时间'
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'MagicAPI接口历史记录' ROW_FORMAT = Dynamic;

+ 1 - 1
pom.xml

@@ -11,7 +11,7 @@
     </parent>
     <groupId>org.ssssssss</groupId>
     <artifactId>magic-api</artifactId>
-    <version>0.2.2</version>
+    <version>0.3.0</version>
     <packaging>jar</packaging>
     <name>magic-api</name>
     <description>auto generate http api</description>

+ 7 - 5
src/main/java/org/ssssssss/magicapi/config/WebUIController.java

@@ -7,7 +7,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 import org.springframework.core.io.InputStreamSource;
-import org.springframework.http.HttpHeaders;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -296,7 +295,7 @@ public class WebUIController {
 				if (sessionId != null) {
 					context.setId(sessionId.toString());
 					context.onComplete(() -> MagicLoggerContext.remove(sessionId.toString()));
-					logger.info("Start Console Session : {},{}", sessionId, this.getClass().getClassLoader().getClass().getName());
+					logger.info("Start Console Session : {}", sessionId);
 					context.onStart(() -> MDC.put(MagicLoggerContext.MAGIC_CONSOLE_SESSION, sessionId.toString()));
 				}
 				Object result = MagicScriptEngine.execute(MagicScriptCompiler.compile(script.toString()), context);
@@ -313,6 +312,9 @@ public class WebUIController {
 							response.addHeader("MA-" + key, value);
 						}
 					}
+					if(entity.getHeaders().isEmpty()){
+						return ResponseEntity.ok(new JsonBean<>(entity.getBody()));
+					}
 					return ResponseEntity.ok(new JsonBean<>(convertToBase64(entity.getBody())));
 				}
 				return new JsonBean<>(resultProvider.buildResult(result));
@@ -347,7 +349,7 @@ public class WebUIController {
 		do {
 			if (parent instanceof MagicScriptAssertException) {
 				MagicScriptAssertException sae = (MagicScriptAssertException) parent;
-				return new JsonBean<>(sae.getCode(), sae.getMessage(), resultProvider.buildResult(sae.getCode(), sae.getMessage()));
+				return new JsonBean<>(resultProvider.buildResult(sae.getCode(), sae.getMessage()));
 			}
 			if (parent instanceof MagicScriptException) {
 				se = (MagicScriptException) parent;
@@ -422,13 +424,13 @@ public class WebUIController {
 			}
 			if (StringUtils.isBlank(info.getId())) {
 				// 先判断接口是否存在
-				if (magicApiService.exists(info.getMethod(), info.getPath())) {
+				if (magicApiService.exists(info.getGroupPrefix(), info.getMethod(), info.getPath())) {
 					return new JsonBean<>(0, String.format("接口%s:%s已存在", info.getMethod(), info.getPath()));
 				}
 				magicApiService.insert(info);
 			} else {
 				// 先判断接口是否存在
-				if (magicApiService.existsWithoutId(info.getMethod(), info.getPath(), info.getId())) {
+				if (magicApiService.existsWithoutId(info.getGroupPrefix(), info.getMethod(), info.getPath(), info.getId())) {
 					return new JsonBean<>(0, String.format("接口%s:%s已存在", info.getMethod(), info.getPath()));
 				}
 				magicApiService.update(info);

+ 4 - 3
src/main/java/org/ssssssss/magicapi/provider/ApiServiceProvider.java

@@ -40,11 +40,11 @@ public interface ApiServiceProvider {
 
 	/**
 	 * 判断接口是否存在
-	 *
+	 * @param groupPrefix 分组前缀
 	 * @param method 请求方法
 	 * @param path   请求路径
 	 */
-	boolean exists(String method, String path);
+	boolean exists(String groupPrefix, String method, String path);
 
 	/**
 	 * 修改分组信息
@@ -57,12 +57,13 @@ public interface ApiServiceProvider {
 	/**
 	 * 判断接口是否存在
 	 *
+	 * @param groupPrefix 分组前缀
 	 * @param method 请求方法
 	 * @param path   请求路径
 	 * @param id     排除接口
 	 * @return
 	 */
-	boolean existsWithoutId(String method, String path, String id);
+	boolean existsWithoutId(String groupPrefix, String method, String path, String id);
 
 	/**
 	 * 添加接口信息

+ 8 - 8
src/main/java/org/ssssssss/magicapi/provider/impl/DefaultApiServiceProvider.java

@@ -64,9 +64,9 @@ public class DefaultApiServiceProvider implements ApiServiceProvider {
 		return info;
 	}
 
-	public boolean exists(String method, String path) {
-		String exists = "select count(*) from magic_api_info where api_method = ? and api_path = ?";
-		return template.queryForObject(exists, Integer.class, method, path) > 0;
+	public boolean exists(String groupPrefix, String method, String path) {
+		String exists = "select count(*) from magic_api_info where api_method = ? and api_path = ? and api_group_prefix = ?";
+		return template.queryForObject(exists, Integer.class, method, path, groupPrefix) > 0;
 	}
 
 	@Override
@@ -75,9 +75,9 @@ public class DefaultApiServiceProvider implements ApiServiceProvider {
 		return template.update(updateGroup, groupName, groupPrefix, System.currentTimeMillis(), oldGroupName) > 0;
 	}
 
-	public boolean existsWithoutId(String method, String path, String id) {
-		String existsWithoutId = "select count(*) from magic_api_info where api_method = ? and api_path = ? and id !=?";
-		return template.queryForObject(existsWithoutId, Integer.class, method, path, id) > 0;
+	public boolean existsWithoutId(String groupPrefix, String method, String path, String id) {
+		String existsWithoutId = "select count(*) from magic_api_info where api_method = ? and api_path = ? and api_group_prefix = ? and id !=?";
+		return template.queryForObject(existsWithoutId, Integer.class, method, path, groupPrefix, id) > 0;
 	}
 
 	public boolean insert(ApiInfo info) {
@@ -102,13 +102,13 @@ public class DefaultApiServiceProvider implements ApiServiceProvider {
 
 	@Override
 	public List<Long> backupList(String apiId) {
-		return template.queryForList("select api_update_time from magic_api_info_his where id = ? order by api_update_time desc",Long.class,apiId);
+		return template.queryForList("select api_update_time from magic_api_info_his where id = ? order by api_update_time desc", Long.class, apiId);
 	}
 
 	@Override
 	public ApiInfo backupInfo(String apiId, Long timestamp) {
 		String selectOne = "select " + COMMON_COLUMNS + "," + SCRIPT_COLUMNS + " from magic_api_info_his where id = ? and api_update_time = ? limit 1";
-		ApiInfo info = template.queryForObject(selectOne, rowMapper, apiId,timestamp);
+		ApiInfo info = template.queryForObject(selectOne, rowMapper, apiId, timestamp);
 		unwrap(info);
 		return info;
 	}

+ 3 - 3
src/main/resources/magicapi-support/index.html

@@ -2,7 +2,7 @@
 <html>
 <head>
 	<meta charset="UTF-8">
-	<title>MagicAPI v0.2.2 - Powered by ssssssss-team</title>
+	<title>MagicAPI v0.3.0 - Powered by ssssssss-team</title>
 	<link rel="icon" href="images/favicon.png" />
 	<style type="text/css">.loading-wrapper{position:fixed;top:0;bottom:0;left:0;right:0;z-index:2147483647;text-align:center;background:#fff}.loading{position:absolute;top:50%;left:50%;width:500px;height:100px;margin-left:-250px;margin-top:-50px;text-align:center}.loading .title{font-size:0;color:#0075ff;letter-spacing:0}.loading .title label{font-size:36px;display:inline-block;margin-top:5px;vertical-align:top}.loading .title span{font-size:72px;display:inline-block;padding:0 3px;animation:stretch 1s infinite}.loading .title span:nth-child(1){animation-delay:calc(1s / 8 * 0 / 2)}.loading .title span:nth-child(2){animation-delay:calc(1s / 8 * 1 / 2)}.loading .title span:nth-child(3){animation-delay:calc(1s / 8 * 2 / 2)}.loading .title span:nth-child(4){animation-delay:calc(1s / 8 * 3 / 2)}.loading .title span:nth-child(5){animation-delay:calc(1s / 8 * 4 / 2)}.loading .title span:nth-child(6){animation-delay:calc(1s / 8 * 5 / 2)}.loading .title span:nth-child(7){animation-delay:calc(1s / 8 * 6 / 2)}.loading .title span:nth-child(8){animation-delay:calc(1s / 8 * 7 / 2)}.loading .loading-text{text-align:center;font-weight:bolder;font-style:italic;color:#889aa4;font-size:32px;animation:blink-loading 2s ease-in infinite}@keyframes stretch{0%{transform:scale(1)}25%{transform:scale(1.2)}50%{transform:scale(1)}100%{transform:scale(1)}}@keyframes blink-loading{0%{opacity:100%}50%{opacity:50%}100%{opacity:100%}}</style>
 	<link rel="stylesheet" href="css/index.css" />
@@ -25,7 +25,7 @@
 			<span>A</span>
 			<span>P</span>
 			<span>I</span>
-			<label>v0.2.2</label>
+			<label>v0.3.0</label>
 		</div>
 		<div class="loading-text">Loading...</div>
 	</div>
@@ -34,7 +34,7 @@
 	<div class="header">
 		<img src="images/logo.png"/>
 		<label>magic-api</label>
-		<label class="version">v0.2.2</label>
+		<label class="version">v0.3.0</label>
 	</div>
 	<span class="button-run" title="运行(Ctrl+Q)"><i class="iconfont icon-run"></i></span>
 	<span class="button-save" title="保存(Ctrl+S)"><i class="iconfont icon-save"></i></span>

+ 3 - 3
src/main/resources/magicapi-support/js/index.js

@@ -634,7 +634,7 @@ var MagicEditor = {
                     })
                 }
                 _this.setStatusBar('保存成功!');
-                _this.renderApiList();
+                _this.loadAPI();
             }
         })
     },
@@ -700,7 +700,7 @@ var MagicEditor = {
             a.href = window.URL.createObjectURL(new Blob([u8arr]));
             a.click();
             MagicEditor.report('output_blob');
-        }else if(contentType.indexOf('image') == 0){    //image开头
+        }else if(contentType && contentType.indexOf('image') == 0){    //image开头
             outputJson = this.formatJson(json.data);
             this.createDialog({
                 title : '图片结果',
@@ -773,7 +773,7 @@ var MagicEditor = {
             url : 'https://img.shields.io/maven-central/v/org.ssssssss/magic-api.json',
             dataType : 'json',
             success : function(data){
-                if(data.value != 'v0.2.2'){
+                if(data.value != 'v0.3.0'){
                     if(ignoreVersion != data.value){
                         _this.createDialog({
                             title : '更新提示',

Some files were not shown because too many files changed in this diff