소스 검색

feat(storage): 添加Google Storage工具类支持自定义内容类型并集成工作流结果存储服务

- 在GoogleStorageUtil中添加contentType参数支持自定义文件类型
- 为WorkflowTaskResultHandler注入WorkflowResultStorageService依赖
- 修改handleSuccess方法使用工作流结果存储服务转移图像URL
- 更新视频URL处理逻辑通过工作流结果存储服务转移视频URL
- 实现对上传文件的内容类型设置功能
- 统一通过存储服务管理工作流结果的媒体文件链接
ChenYu 7 달 전
부모
커밋
cf719a8761
2개의 변경된 파일과 16개의 추가작업 그리고 6개의 파일을 삭제
  1. 7 2
      src/main/java/com/aitori/service/WorkflowTaskResultHandler.java
  2. 9 4
      src/main/java/com/aitori/utils/GoogleStorageUtil.java

+ 7 - 2
src/main/java/com/aitori/service/WorkflowTaskResultHandler.java

@@ -33,6 +33,7 @@ public class WorkflowTaskResultHandler {
     private final TAiAlbumService aiAlbumService;
     private final TAiStyleService aiStyleService;
     private final TUserMessageService userMessageService;
+    private final WorkflowResultStorageService workflowResultStorageService;
     private final ObjectMapper objectMapper;
 
     /**
@@ -94,7 +95,10 @@ public class WorkflowTaskResultHandler {
     }
 
     private void handleSuccess(String taskId, TAiOrderV2 order, WorkflowTaskMessage.TaskData data) {
-        String imagesArrayJson = buildImagesArrayJson(data != null ? data.getImages() : null);
+        List<String> storedImageUrls = workflowResultStorageService.transferImageUrls(
+                data != null ? data.getImages() : null
+        );
+        String imagesArrayJson = buildImagesArrayJson(storedImageUrls);
         String videosArrayJson = buildVideosArrayJson(data != null ? data.getVideos() : null);
 
         String resultJson = assembleResultJson(imagesArrayJson, videosArrayJson);
@@ -148,8 +152,9 @@ public class WorkflowTaskResultHandler {
 
         List<Map<String, String>> videoItems = new ArrayList<>();
         for (String videoUrl : videoUrls) {
+            String storedVideoUrl = workflowResultStorageService.transferVideoUrl(videoUrl);
             Map<String, String> item = new HashMap<>();
-            item.put("url", videoUrl);
+            item.put("url", storedVideoUrl);
 
             String thumbnailUrl = VideoThumbnailUtil.extractAndUpload(videoUrl);
             if (thumbnailUrl != null) {

+ 9 - 4
src/main/java/com/aitori/utils/GoogleStorageUtil.java

@@ -34,6 +34,10 @@ public class GoogleStorageUtil {
             "}";
 
     public static String upload(byte[] bytes, String objectName) {
+        return upload(bytes, objectName, null);
+    }
+
+    public static String upload(byte[] bytes, String objectName, String contentType) {
         try {
             InputStream inputStream = new ByteArrayInputStream(json.getBytes());
 
@@ -42,10 +46,11 @@ public class GoogleStorageUtil {
 
             // 上传文件
             BlobId blobId = BlobId.of(bucketName, objectName);
-            BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
-            Blob blob = storage.create(blobInfo, bytes);
-            //修改已经上传的文件类型为 image/jpg
-            blob.toBuilder().build().update();
+            BlobInfo.Builder blobInfoBuilder = BlobInfo.newBuilder(blobId);
+            if (contentType != null && !contentType.isBlank()) {
+                blobInfoBuilder.setContentType(contentType);
+            }
+            storage.create(blobInfoBuilder.build(), bytes);
 
             // 返回文件访问链接
             return "https://storage.googleapis.com/" + bucketName + "/" + objectName;