This commit is contained in:
mxd
2022-01-08 18:05:49 +08:00
parent 6485210596
commit da8b277dbe
4 changed files with 15 additions and 18 deletions

View File

@@ -12,6 +12,7 @@ import org.ssssssss.magicapi.utils.WebUtils;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
public class MagicBackupController extends MagicController implements MagicExceptionHandler{
@@ -26,12 +27,16 @@ public class MagicBackupController extends MagicController implements MagicExcep
@GetMapping("/backups")
@ResponseBody
public JsonBean<List<Backup>> backups(Long timestamp) {
if(service == null){
return new JsonBean<>(Collections.emptyList());
}
return new JsonBean<>(service.backupList(timestamp == null ? System.currentTimeMillis() : timestamp));
}
@GetMapping("/backup/rollback")
@ResponseBody
public JsonBean<Boolean> rollback(String id, Long timestamp) throws IOException {
notNull(service, BACKUP_NOT_ENABLED);
Backup backup = service.backupInfo(id, timestamp);
if("full".equals(id)){
service.doBackupAll("还原全量备份前,系统自动全量备份", WebUtils.currentUserName());
@@ -57,6 +62,7 @@ public class MagicBackupController extends MagicController implements MagicExcep
@GetMapping("/backup")
@ResponseBody
public JsonBean<String> backup(Long timestamp, String id) {
notNull(service, BACKUP_NOT_ENABLED);
notBlank(id, PARAMETER_INVALID);
notNull(timestamp, PARAMETER_INVALID);
Backup backup = service.backupInfo(id, timestamp);
@@ -67,6 +73,7 @@ public class MagicBackupController extends MagicController implements MagicExcep
@PostMapping("/backup/full")
@ResponseBody
public JsonBean<Boolean> doBackup() throws IOException {
notNull(service, BACKUP_NOT_ENABLED);
service.doBackupAll("主动全量备份", WebUtils.currentUserName());
return new JsonBean<>(true);
}

View File

@@ -77,7 +77,7 @@ public class MagicResourceController extends MagicController implements MagicExc
// 自动保存的代码,和旧版代码对比,如果一致,则不保存,直接返回。
if(entity.getId() != null && "1".equals(auto)){
MagicEntity oldInfo = service.file(entity.getId());
if(oldInfo != null && Objects.equals(oldInfo.getScript(), entity.getScript())){
if(oldInfo != null && Objects.equals(oldInfo, entity)){
return new JsonBean<>(entity.getId());
}
}

View File

@@ -6,6 +6,7 @@ import org.ssssssss.magicapi.config.MagicConfiguration;
import org.ssssssss.magicapi.utils.JsonUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* 接口信息
@@ -52,11 +53,6 @@ public class ApiInfo extends PathMagicEntity {
*/
private String description;
/**
* 接口选项json
*/
private transient JsonNode jsonNode;
/**
* 请求体属性
*/
@@ -100,16 +96,8 @@ public class ApiInfo extends PathMagicEntity {
}
public Map<String, String> options() {
Map<String, String> map = new HashMap<>();
if (this.jsonNode == null) {
return null;
} else if (this.jsonNode.isArray()) {
for (JsonNode node : this.jsonNode) {
map.put(node.get("name").asText(), node.get("value").asText());
}
} else {
this.jsonNode.fieldNames().forEachRemaining(it -> map.put(it, this.jsonNode.get(it).asText()));
}
Map<String, String> map = this.options.stream()
.collect(Collectors.toMap(BaseDefinition::getName, it -> String.valueOf(it.getValue()), (o, n) -> n));
MagicConfiguration.getMagicResourceService().getGroupsByFileId(this.groupId)
.stream()
.flatMap(it -> it.getOptions().stream())
@@ -229,7 +217,7 @@ public class ApiInfo extends PathMagicEntity {
@Override
public int hashCode() {
return Objects.hash(id, method, path, script, name, groupId, parameters, options, requestBody, headers, responseBody, description, requestBodyDefinition, responseBodyDefinition);
return Objects.hash(id, method, path, script, name, groupId, parameters, options, requestBody, headers, description, requestBodyDefinition, responseBodyDefinition);
}
@Override
@@ -238,8 +226,8 @@ public class ApiInfo extends PathMagicEntity {
copyTo(info);
info.setMethod(this.method);
info.setParameters(this.parameters);
info.jsonNode = this.jsonNode;
info.setRequestBody(this.requestBody);
info.setOption(this.options);
info.setHeaders(this.headers);
info.setResponseBody(this.responseBody);
info.setDescription(this.description);

View File

@@ -75,6 +75,8 @@ public interface JsonCodeConstants {
JsonCode SIGN_IS_INVALID = new JsonCode(0, "签名验证失败,请检查秘钥是否正确");
JsonCode BACKUP_NOT_ENABLED = new JsonCode(0, "未启用备份,无法操作");
JsonCode API_NOT_FOUND = new JsonCode(1001, "api not found");
default void notNull(Object value, JsonCode jsonCode) {