Merge remote-tracking branch 'origin/prod/release_1.0' into prod/release_1.0
This commit is contained in:
@@ -543,20 +543,19 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
|
||||
try {
|
||||
log.info("开始调用换脸API - 源图片: {}, 目标图片: {}", imageUrls.get(0), imageUrls.get(1));
|
||||
|
||||
// 获取图片的预签名URL
|
||||
String inputFaceUrl = imageUrls.get(0);
|
||||
|
||||
String inputFaceUrl = imageUrls.get(1);
|
||||
|
||||
// 构建输入图片列表(从第二张图片开始作为目标图片列表)
|
||||
JSONArray inputImageList = new JSONArray();
|
||||
for (int i = 1; i < imageUrls.size(); i++) {
|
||||
inputImageList.add(imageUrls.get(i));
|
||||
}
|
||||
inputImageList.add(imageUrls.get(0));
|
||||
|
||||
// 构建请求体
|
||||
JSONObject requestBody = new JSONObject();
|
||||
requestBody.put("input_image_list", inputImageList);
|
||||
requestBody.put("input_face", inputFaceUrl);
|
||||
requestBody.put("threshold", 0.2);
|
||||
log.info("换脸API请求体: {}", requestBody);
|
||||
|
||||
// 调用换脸API
|
||||
String response = sendFaceSwapRequest(faceSwapConfig.getRefaceUrl(), requestBody.toString());
|
||||
@@ -640,7 +639,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
|
||||
try {
|
||||
log.info("开始处理换脸API响应: {}", response);
|
||||
|
||||
JSONObject jsonResponse = new JSONObject(response);
|
||||
com.alibaba.fastjson.JSONObject jsonResponse = com.alibaba.fastjson.JSON.parseObject(response);
|
||||
|
||||
// 处理新的响应格式: {"output":["lanecarford/refaced_image/refaced1761809361.530157.png"]}
|
||||
if (jsonResponse.containsKey("output")) {
|
||||
@@ -652,12 +651,10 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
|
||||
String imagePath = outputArray.getString(0);
|
||||
log.info("换脸成功,图片路径: {}", imagePath);
|
||||
|
||||
// 构建完整的图片URL(假设需要添加基础URL)
|
||||
String fullImageUrl = buildFullImageUrl(imagePath);
|
||||
log.info("完整图片URL: {}", fullImageUrl);
|
||||
|
||||
|
||||
// 下载图片并上传到MinIO
|
||||
return downloadAndUploadToMinio(fullImageUrl);
|
||||
return imagePath;
|
||||
} else {
|
||||
log.error("output数组为空");
|
||||
throw new BusinessException("Empty output array", "返回的图片数组为空", ResultEnum.ERROR.getCode());
|
||||
@@ -678,53 +675,6 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建完整的图片URL
|
||||
*/
|
||||
private String buildFullImageUrl(String imagePath) {
|
||||
// 如果imagePath已经是完整URL,直接返回
|
||||
if (imagePath.startsWith("http://") || imagePath.startsWith("https://")) {
|
||||
return imagePath;
|
||||
}
|
||||
|
||||
// 否则,使用换脸API的基础URL构建完整URL
|
||||
String baseUrl = faceSwapConfig.getBaseUrl();
|
||||
if (baseUrl.endsWith("/")) {
|
||||
baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
|
||||
}
|
||||
|
||||
if (!imagePath.startsWith("/")) {
|
||||
imagePath = "/" + imagePath;
|
||||
}
|
||||
|
||||
return baseUrl + imagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载图片并上传到MinIO
|
||||
*/
|
||||
private String downloadAndUploadToMinio(String imageUrl) {
|
||||
try {
|
||||
log.info("开始下载换脸结果图片: {}", imageUrl);
|
||||
|
||||
// 使用现有的下载方法
|
||||
byte[] imageData = downloadImageFromUrl(imageUrl);
|
||||
|
||||
// 生成对象名称
|
||||
String objectName = MinioFileConstants.TRY_ON_RESULT_DIR + "/" + "faceswap_" + System.currentTimeMillis() + ".jpg";
|
||||
|
||||
// 上传到MinIO
|
||||
String logicalUrl = minioUtil.uploadBytes(imageData, objectName, "image/jpeg", minioConfig.getBucketName());
|
||||
|
||||
log.info("换脸结果图片上传成功,逻辑URL: {}", logicalUrl);
|
||||
return logicalUrl;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("下载并上传换脸结果图片失败: {}", e.getMessage(), e);
|
||||
throw new BusinessException("Failed to download and upload result image", "下载并上传结果图片失败", ResultEnum.ERROR.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从URL下载图片数据
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user