fix(aiot): 改用COS公共URL+修复GlobalResponseAdvice排除byte[]

1. requestScreenshot直接返回COS公共URL(不再返回代理路径)
2. GlobalResponseAdvice排除byte[]类型响应,避免图片代理被包装成WVPResult
3. handleCallback先写缓存再complete Future(保留之前的竞态修复)

COS Bucket已开启公有读,无需签名URL,直接用公共地址即可在<img>中显示。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 15:16:29 +08:00
parent 83041e9490
commit 2b0a682b3f
2 changed files with 9 additions and 4 deletions

View File

@@ -56,7 +56,7 @@ public class AiScreenshotServiceImpl implements IAiScreenshotService {
try { try {
JSONObject cached = JSON.parseObject(cacheJson); JSONObject cached = JSON.parseObject(cacheJson);
result.put("status", "ok"); result.put("status", "ok");
result.put("url", "/api/ai/roi/snap/image?cameraCode=" + cameraCode); result.put("url", cached.getString("url"));
result.put("cached", true); result.put("cached", true);
log.info("[AI截图] 命中缓存: cameraCode={}", cameraCode); log.info("[AI截图] 命中缓存: cameraCode={}", cameraCode);
return result; return result;
@@ -101,7 +101,7 @@ public class AiScreenshotServiceImpl implements IAiScreenshotService {
String status = (String) callbackData.get("status"); String status = (String) callbackData.get("status");
result.put("status", status); result.put("status", status);
if ("ok".equals(status)) { if ("ok".equals(status)) {
result.put("url", "/api/ai/roi/snap/image?cameraCode=" + cameraCode); result.put("url", callbackData.get("url"));
} else { } else {
result.put("message", callbackData.get("message")); result.put("message", callbackData.get("message"));
} }
@@ -115,7 +115,7 @@ public class AiScreenshotServiceImpl implements IAiScreenshotService {
JSONObject res = JSON.parseObject(resultJson); JSONObject res = JSON.parseObject(resultJson);
result.put("status", res.getString("status")); result.put("status", res.getString("status"));
if ("ok".equals(res.getString("status"))) { if ("ok".equals(res.getString("status"))) {
result.put("url", "/api/ai/roi/snap/image?cameraCode=" + cameraCode); result.put("url", res.getString("url"));
// 降级成功,写入缓存 // 降级成功,写入缓存
writeCache(cameraCode, res.getString("url")); writeCache(cameraCode, res.getString("url"));
} else { } else {
@@ -135,7 +135,7 @@ public class AiScreenshotServiceImpl implements IAiScreenshotService {
try { try {
JSONObject cached = JSON.parseObject(staleCache); JSONObject cached = JSON.parseObject(staleCache);
result.put("status", "ok"); result.put("status", "ok");
result.put("url", "/api/ai/roi/snap/image?cameraCode=" + cameraCode); result.put("url", cached.getString("url"));
result.put("stale", true); result.put("stale", true);
return result; return result;
} catch (Exception ignored) { } catch (Exception ignored) {

View File

@@ -42,6 +42,11 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
return body; return body;
} }
// 排除二进制响应(如图片代理返回的 byte[]
if (body instanceof byte[]) {
return body;
}
if (body instanceof WVPResult) { if (body instanceof WVPResult) {
return body; return body;
} }