Преглед изворни кода

feat: 图片对比功能完善

WANGKANG пре 11 месеци
родитељ
комит
c46d8c2c34

+ 22 - 7
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/VideoStableController.java

@@ -8,6 +8,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import com.taais.biz.domain.VideoStable;
 import com.taais.biz.domain.bo.VideoStableStartResultBo;
 import jakarta.validation.Valid;
 import lombok.RequiredArgsConstructor;
@@ -45,14 +46,28 @@ public class VideoStableController extends BaseController {
     @Resource
     private IVideoStableService videoStableService;
 
-    @GetMapping("/compare/{task_name}/{idx}")
-    public ResponseEntity<Map<String, String>> getCompareImages(@PathVariable("task_name") String taskName, @PathVariable("idx") int idx) {
+    @GetMapping("/compare/{task_id}/{idx}")
+    public ResponseEntity<Map<String, String>> getCompareImages(@PathVariable("task_id") Long taskId, @PathVariable("idx") int idx) {
         try {
-            Path baseDir  = Paths.get(UPLOAD_DIR, taskName);
-            // 读取两张图片
-            System.out.println(baseDir.resolve("images/" + String.format("%05d", idx) + ".jpg").toString());
-            byte[] image1 = Files.readAllBytes(baseDir.resolve("images/" + String.format("%05d", idx) + ".jpg"));
-            byte[] image2 = Files.readAllBytes(baseDir.resolve("stable/" + String.format("%05d", idx) + ".jpg"));
+            VideoStable videoStable = videoStableService.getById(taskId);
+
+            Path inputPath = null;
+            Path outputPath = null;
+            String osName = System.getProperty("os.name");
+            // 判断是否是Windows环境
+            if (osName.toLowerCase().contains("windows")) {
+                inputPath = Paths.get("C:", videoStable.getInputPath());
+                outputPath = Paths.get("C:", videoStable.getOutputPath());
+            } else {
+                inputPath = Paths.get(videoStable.getInputPath());
+                outputPath = Paths.get(videoStable.getOutputPath());
+            }
+            System.out.println("inputPath: " + inputPath.toString());
+            System.out.println("outputPath: " + outputPath.toString());
+
+
+            byte[] image1 = Files.readAllBytes(inputPath.resolve(String.format("%05d", idx) + ".jpg"));
+            byte[] image2 = Files.readAllBytes(outputPath.resolve(String.format("%05d", idx) + ".jpg"));
 
             // 将图片编码成Base64字符串
             String base64Image1 = Base64.getEncoder().encodeToString(image1);