fix changelog

This commit is contained in:
bwcx_jzy 2023-03-31 10:13:36 +08:00
parent 4a06856864
commit 76d5621678
No known key found for this signature in database
GPG Key ID: 5E48E9372088B9E5
6 changed files with 33 additions and 80 deletions

View File

@ -93,6 +93,7 @@
<directory>../../</directory>
<includes>
<include>CHANGELOG.md</include>
<include>CHANGELOG-BETA.md</include>
<include>LICENSE</include>
</includes>
</resource>

View File

@ -22,6 +22,7 @@
*/
package io.jpom.controller.system;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ResourceUtil;
@ -100,9 +101,11 @@ public class SystemUpdateController extends BaseAgentController {
}
@PostMapping(value = "change_log", produces = MediaType.APPLICATION_JSON_VALUE)
public JsonMessage<String> changeLog() {
public JsonMessage<String> changeLog(String beta) {
//
URL resource = ResourceUtil.getResource("CHANGELOG.md");
boolean betaBool = Convert.toBool(beta, false);
boolean betaRelease = RemoteVersion.betaRelease();
URL resource = ResourceUtil.getResource((betaRelease || betaBool) ? "CHANGELOG-BETA.md" : "CHANGELOG.md");
String log = StrUtil.EMPTY;
if (resource != null) {
InputStream stream = URLUtil.getStream(resource);

View File

@ -143,6 +143,7 @@
<directory>../../</directory>
<includes>
<include>CHANGELOG.md</include>
<include>CHANGELOG-BETA.md</include>
<include>LICENSE</include>
</includes>
</resource>

View File

@ -77,15 +77,15 @@ public abstract class BaseServerController extends BaseJpomController {
return nodeService.getByKey(nodeId);
}
protected <T> JsonMessage<T> tryRequestNode(String machineId, HttpServletRequest request, NodeUrl nodeUrl) {
protected <T> JsonMessage<T> tryRequestNode(String machineId, HttpServletRequest request, NodeUrl nodeUrl, String... pars) {
NodeModel nodeModel = tryGetNode();
if (nodeModel != null) {
return NodeForward.request(nodeModel, request, nodeUrl);
return NodeForward.request(nodeModel, request, nodeUrl, new String[]{}, pars);
}
if (StrUtil.isNotEmpty(machineId)) {
MachineNodeModel model = machineNodeServer.getByKey(machineId);
Assert.notNull(model, "没有找到对应的机器");
return NodeForward.request(model, request, nodeUrl);
return NodeForward.request(model, request, nodeUrl, new String[]{}, pars);
}
return null;
}

View File

@ -186,28 +186,6 @@ public class NodeForward {
return header;
}
// /**
// * 普通消息转发
// *
// * @param nodeInfo 节点信息
// * @param request 请求
// * @param nodeUrl 节点的url
// * @param <T> 泛型
// * @return JSON
// */
// private static <T> JsonMessage<T> request(INodeInfo nodeInfo, HttpServletRequest request, NodeUrl nodeUrl, String... removeKeys) {
// Map<String, String> map = Optional.ofNullable(request)
// .map(ServletUtil::getParamMap)
// .map(map1 -> MapUtil.removeAny(map1, removeKeys))
// .orElse(null);
// TypeReference<JsonMessage<T>> tTypeReference = new TypeReference<JsonMessage<T>>() {
// };
// return createUrlItem(nodeInfo, StrUtil.EMPTY, nodeUrl,
// (nodeInfo1, urlItem) ->
// TransportServerFactory.get().executeToType(nodeInfo1, urlItem, map, tTypeReference)
// );
// }
/**
* 普通消息转发
*
@ -260,9 +238,28 @@ public class NodeForward {
* @return JSON
*/
public static <T> JsonMessage<T> request(MachineNodeModel machineNodeModel, HttpServletRequest request, NodeUrl nodeUrl, String... removeKeys) {
return request(machineNodeModel, request, nodeUrl, removeKeys, new String[]{});
}
/**
* 普通消息转发
*
* @param machineNodeModel 机器
* @param request 请求
* @param nodeUrl 节点的url
* @param <T> 泛型
* @return JSON
*/
public static <T> JsonMessage<T> request(MachineNodeModel machineNodeModel, HttpServletRequest request, NodeUrl nodeUrl, String[] removeKeys, String... appendData) {
Map<String, String> map = Optional.ofNullable(request)
.map(ServletUtil::getParamMap)
.map(map1 -> MapUtil.removeAny(map1, removeKeys))
.map(map2 -> {
for (int i = 0; i < appendData.length; i += 2) {
map2.put(appendData[i], appendData[i + 1]);
}
return map2;
})
.orElse(null);
TypeReference<JsonMessage<T>> tTypeReference = new TypeReference<JsonMessage<T>>() {
};
@ -302,20 +299,6 @@ public class NodeForward {
return createUrlItem(nodeInfo, StrUtil.EMPTY, nodeUrl, (nodeInfo1, urlItem) -> TransportServerFactory.get().executeToType(nodeInfo1, urlItem, jsonObject, typeReference));
}
// /**
// * 普通消息转发
// *
// * @param nodeInfo 节点
// * @param nodeUrl 节点的url
// * @param jsonObject 数据
// * @return JSON
// */
// private static <T> JsonMessage<T> request(INodeInfo nodeInfo, NodeUrl nodeUrl, JSONObject jsonObject) {
// TypeReference<JsonMessage<T>> typeReference = new TypeReference<JsonMessage<T>>() {
// };
// return createUrlItem(nodeInfo, StrUtil.EMPTY, nodeUrl, (nodeInfo1, urlItem) -> TransportServerFactory.get().executeToType(nodeInfo1, urlItem, jsonObject, typeReference));
// }
/**
* 普通消息转发
*
@ -643,45 +626,8 @@ public class NodeForward {
});
return null;
});
}
// /**
// * 获取节点socket 信息
// *
// * @param nodeModel 节点信息
// * @param nodeUrl url
// * @return url
// */
// public static String getSocketUrl(NodeModel nodeModel, NodeUrl nodeUrl, UserModel userInfo, Object... parameters) {
// INodeInfo nodeInfo = parseNodeInfo(nodeModel);
// String ws;
// if ("https".equalsIgnoreCase(nodeInfo.scheme())) {
// ws = "wss";
// } else {
// ws = "ws";
// }
// UrlQuery urlQuery = new UrlQuery();
// urlQuery.add(Const.JPOM_AGENT_AUTHORIZE, nodeInfo.authorize());
// //
// String optUser = userInfo.getId();
// optUser = URLUtil.encode(optUser);
// urlQuery.add("optUser", optUser);
// if (ArrayUtil.isNotEmpty(parameters)) {
// for (int i = 0; i < parameters.length; i += 2) {
// Object parameter = parameters[i + 1];
// String value = Convert.toStr(parameter, StrUtil.EMPTY);
// urlQuery.add(parameters[i].toString(), URLUtil.encode(value));
// }
// }
// // 兼容旧版本-节点升级 @author jzy
// //urlQuery.add("name", URLUtil.encode(nodeModel.getLoginName()));
// //urlQuery.add("password", URLUtil.encode(nodeModel.getLoginPwd()));
// String format = StrUtil.format("{}://{}{}?{}", ws, nodeInfo.url(), nodeUrl.getUrl(), urlQuery.toString());
// log.debug("web socket url:{}", format);
// return format;
// }
public static <T> T toJsonMessage(String body, TypeReference<T> tTypeReference) {
if (StrUtil.isEmpty(body)) {
throw new AgentException("agent 端响应内容为空");

View File

@ -128,12 +128,14 @@ public class SystemUpdateController extends BaseServerController implements ILoa
*/
@PostMapping(value = "change_log", produces = MediaType.APPLICATION_JSON_VALUE)
public JsonMessage<String> changeLog(HttpServletRequest request, String machineId) {
JsonMessage<String> message = this.tryRequestNode(machineId, request, NodeUrl.CHANGE_LOG);
boolean betaRelease = RemoteVersion.betaRelease();
JsonMessage<String> message = this.tryRequestNode(machineId, request, NodeUrl.CHANGE_LOG, "beta", String.valueOf(betaRelease));
if (message != null) {
return message;
}
//
URL resource = ResourceUtil.getResource("CHANGELOG.md");
URL resource = ResourceUtil.getResource(betaRelease ? "CHANGELOG-BETA.md" : "CHANGELOG.md");
String log = StrUtil.EMPTY;
if (resource != null) {
InputStream stream = URLUtil.getStream(resource);