fix: contentType 不传时自动检测 JSON/HTML,不再写死为 html
This commit is contained in:
@@ -36,7 +36,7 @@ public class AccessResultController {
|
|||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
|
|
||||||
String configVersion = (String) payload.get("configVersion");
|
String configVersion = (String) payload.get("configVersion");
|
||||||
String contentType = (String) payload.getOrDefault("contentType", "html");
|
String contentType = (String) payload.getOrDefault("contentType", detectContentType(payload.get("content")));
|
||||||
String content = (String) payload.get("content");
|
String content = (String) payload.get("content");
|
||||||
String url = (String) payload.get("url");
|
String url = (String) payload.get("url");
|
||||||
Integer statusCode = payload.get("statusCode") instanceof Integer i ? i : null;
|
Integer statusCode = payload.get("statusCode") instanceof Integer i ? i : null;
|
||||||
@@ -149,4 +149,12 @@ public class AccessResultController {
|
|||||||
return ApiResponse.error(404, e.getMessage());
|
return ApiResponse.error(404, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String detectContentType(Object content) {
|
||||||
|
if (content instanceof String s) {
|
||||||
|
String t = s.trim();
|
||||||
|
if (t.startsWith("{") || t.startsWith("[")) return "json";
|
||||||
|
}
|
||||||
|
return "html";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user