|
|
@@ -197,6 +197,29 @@ public class AppBuildQueryImpl implements AppBuildQuery {
|
|
|
BuildLog buildLog = buildLogRepository.findByBuildLogId(buildLogId);
|
|
|
String logPath = buildLog.getLogPath();
|
|
|
String logContent = textFile.readFile(logPath);
|
|
|
- return logContent;
|
|
|
+ return ansiToHtml(logContent);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将包含 ANSI 颜色代码的原始日志转换为带有 HTML span 标签的文本
|
|
|
+ */
|
|
|
+ private String ansiToHtml(String rawLog) {
|
|
|
+ if (rawLog == null) return "";
|
|
|
+
|
|
|
+ // 简单的 HTML 转义,防止 XSS
|
|
|
+ String html = rawLog.replace("&", "&")
|
|
|
+ .replace("<", "<")
|
|
|
+ .replace(">", ">");
|
|
|
+
|
|
|
+ // 替换常见的 ANSI 颜色代码
|
|
|
+ // [31m -> Red, [32m -> Green, [33m -> Yellow, [36m -> Cyan, [0m -> Reset
|
|
|
+ html = html.replaceAll("\\u001b\\[31m", "<span style='color: #F56C6C;'>") // Red
|
|
|
+ .replaceAll("\\u001b\\[32m", "<span style='color: #67C23A;'>") // Green
|
|
|
+ .replaceAll("\\u001b\\[33m", "<span style='color: #E6A23C;'>") // Yellow
|
|
|
+ .replaceAll("\\u001b\\[36m", "<span style='color: #409EFF;'>") // Cyan
|
|
|
+ .replaceAll("\\u001b\\[0m", "</span>"); // Reset
|
|
|
+
|
|
|
+ // 处理换行符
|
|
|
+ return html.replace("\n", "<br/>");
|
|
|
}
|
|
|
}
|