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:
@@ -56,7 +56,7 @@ public class AiScreenshotServiceImpl implements IAiScreenshotService {
|
||||
try {
|
||||
JSONObject cached = JSON.parseObject(cacheJson);
|
||||
result.put("status", "ok");
|
||||
result.put("url", "/api/ai/roi/snap/image?cameraCode=" + cameraCode);
|
||||
result.put("url", cached.getString("url"));
|
||||
result.put("cached", true);
|
||||
log.info("[AI截图] 命中缓存: cameraCode={}", cameraCode);
|
||||
return result;
|
||||
@@ -101,7 +101,7 @@ public class AiScreenshotServiceImpl implements IAiScreenshotService {
|
||||
String status = (String) callbackData.get("status");
|
||||
result.put("status", status);
|
||||
if ("ok".equals(status)) {
|
||||
result.put("url", "/api/ai/roi/snap/image?cameraCode=" + cameraCode);
|
||||
result.put("url", callbackData.get("url"));
|
||||
} else {
|
||||
result.put("message", callbackData.get("message"));
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class AiScreenshotServiceImpl implements IAiScreenshotService {
|
||||
JSONObject res = JSON.parseObject(resultJson);
|
||||
result.put("status", 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"));
|
||||
} else {
|
||||
@@ -135,7 +135,7 @@ public class AiScreenshotServiceImpl implements IAiScreenshotService {
|
||||
try {
|
||||
JSONObject cached = JSON.parseObject(staleCache);
|
||||
result.put("status", "ok");
|
||||
result.put("url", "/api/ai/roi/snap/image?cameraCode=" + cameraCode);
|
||||
result.put("url", cached.getString("url"));
|
||||
result.put("stale", true);
|
||||
return result;
|
||||
} catch (Exception ignored) {
|
||||
|
||||
@@ -42,6 +42,11 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
|
||||
return body;
|
||||
}
|
||||
|
||||
// 排除二进制响应(如图片代理返回的 byte[])
|
||||
if (body instanceof byte[]) {
|
||||
return body;
|
||||
}
|
||||
|
||||
if (body instanceof WVPResult) {
|
||||
return body;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user