Merge remote-tracking branch 'origin/dev/3.1_release_merge' into dev/3.1_release_merge
This commit is contained in:
@@ -125,11 +125,11 @@ public class PythonController {
|
||||
@CrossOrigin
|
||||
@Operation(summary = "Seg Anything 转发接口")
|
||||
@PostMapping("/segAnything")
|
||||
public Response<JSONObject> segAnything(@RequestBody Map<String, Object> payload) {
|
||||
public Response<String> segAnything(@RequestBody Map<String, Object> payload) {
|
||||
// 将前端传来的 Map 转为 fastjson JSONObject 并转发给 python 服务
|
||||
JSONObject requestJson = (JSONObject) JSON.toJSON(payload);
|
||||
JSONObject result = pythonService.segAnything(requestJson);
|
||||
return Response.success(result);
|
||||
String url = pythonService.segAnything(requestJson);
|
||||
return Response.success(url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4114,7 +4114,7 @@ public class PythonService {
|
||||
* 转发 seg_anything 请求到 python 服务
|
||||
* 请求 body 由调用方组装(包含 user_id, image_path, type, points, labels, box 等)
|
||||
*/
|
||||
public JSONObject segAnything(JSONObject content) {
|
||||
public String segAnything(JSONObject content) {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)
|
||||
@@ -4147,7 +4147,32 @@ public class PythonService {
|
||||
String responseBody = response.body().string();
|
||||
JSONObject responseObject = JSON.parseObject(responseBody);
|
||||
log.info("PythonService##segAnything response###{}", responseObject);
|
||||
return responseObject;
|
||||
// Extract nested output path and convert to presigned MinIO URL for frontend, return as String
|
||||
try {
|
||||
if (responseObject != null) {
|
||||
JSONObject dataObj = responseObject.getJSONObject("data");
|
||||
if (dataObj != null) {
|
||||
JSONObject inner = dataObj.getJSONObject("data");
|
||||
if (inner != null) {
|
||||
String output = inner.getString("output");
|
||||
if (!StringUtil.isNullOrEmpty(output)) {
|
||||
try {
|
||||
String presigned = minioUtil.getPreSignedUrl(output, 24 * 60);
|
||||
return presigned;
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to generate presigned url for {}: {}", output, e.getMessage());
|
||||
throw new BusinessException("segAnything.presign.failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("PythonService##segAnything post-process error###{}", ex.getMessage());
|
||||
throw new BusinessException("segAnything.interface.exception");
|
||||
}
|
||||
|
||||
throw new BusinessException("segAnything.missing.output");
|
||||
}
|
||||
throw new BusinessException("segAnything.interface.exception");
|
||||
} catch (IOException | JSONException e) {
|
||||
|
||||
Reference in New Issue
Block a user