From 155aa3ba5ca5933fae9fa260c9abb85034b0f31b Mon Sep 17 00:00:00 2001
From: AprilWind <2100166581@qq.com>
Date: 星期一, 29 四月 2024 18:06:25 +0800
Subject: [PATCH] update 优化是否启用路径样式注释

---
 ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java |   29 +++++++++--------------------
 1 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java
index 6c402dc..5533297 100644
--- a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java
+++ b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java
@@ -34,7 +34,6 @@
 import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.time.Duration;
 
 /**
@@ -84,6 +83,9 @@
             StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider.create(
                 AwsBasicCredentials.create(properties.getAccessKey(), properties.getSecretKey()));
 
+            //MinIO 浣跨敤 HTTPS 闄愬埗浣跨敤鍩熷悕璁块棶锛岀珯鐐瑰~鍩熷悕銆傞渶瑕佸惎鐢ㄨ矾寰勬牱寮忚闂�
+            boolean isStyle = !StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE);
+
             //鍒涘缓AWS鍩轰簬 CRT 鐨� S3 瀹㈡埛绔�
             this.client = S3AsyncClient.crtBuilder()
                 .credentialsProvider(credentialsProvider)
@@ -92,15 +94,15 @@
                 .targetThroughputInGbps(20.0)
                 .minimumPartSizeInBytes(10 * 1025 * 1024L)
                 .checksumValidationEnabled(false)
+                .forcePathStyle(isStyle)
                 .build();
 
             //AWS鍩轰簬 CRT 鐨� S3 AsyncClient 瀹炰緥鐢ㄤ綔 S3 浼犺緭绠$悊鍣ㄧ殑搴曞眰瀹㈡埛绔�
             this.transferManager = S3TransferManager.builder().s3Client(this.client).build();
 
-            // 妫�鏌ユ槸鍚﹁繛鎺ュ埌 MinIO锛孧inIO 浣跨敤 HTTPS 闄愬埗浣跨敤鍩熷悕璁块棶锛岄渶瑕佸惎鐢ㄨ矾寰勬牱寮忚闂�
+            // 鍒涘缓 S3 閰嶇疆瀵硅薄
             S3Configuration config = S3Configuration.builder().chunkedEncodingEnabled(false)
-                // minio 浣跨敤https闄愬埗浣跨敤鍩熷悕璁块棶 闇�瑕佹閰嶇疆 绔欑偣濉煙鍚�
-                .pathStyleAccessEnabled(!StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE)).build();
+                .pathStyleAccessEnabled(isStyle).build();
 
             // 鍒涘缓 棰勭鍚� URL 鐨勭敓鎴愬櫒 瀹炰緥锛岀敤浜庣敓鎴� S3 棰勭鍚� URL
             this.presigner = S3Presigner.builder()
@@ -242,16 +244,13 @@
      * @throws OssException 濡傛灉涓嬭浇澶辫触锛屾姏鍑鸿嚜瀹氫箟寮傚父
      */
     public Path fileDownload(String path) {
-        // 浠庤矾寰勪腑绉婚櫎 URL 鍓嶇紑
-        String url = removeBaseUrl(path);
-
-        // 鏋勫缓涓存椂鏂囦欢璺緞 鏂囦欢鍚嶅繀椤绘槸鍞竴涓嶅瓨鍦ㄧ殑锛岃矾寰勫繀椤绘槸瀛樺湪鐨�
-        Path tempFilePath = Paths.get(extractFileName(url));
+        // 鏋勫缓涓存椂鏂囦欢
+        Path tempFilePath = FileUtils.createTempFile().toPath();
         // 浣跨敤 S3TransferManager 涓嬭浇鏂囦欢
         FileDownload downloadFile = transferManager.downloadFile(
             x -> x.getObjectRequest(
                     y -> y.bucket(properties.getBucketName())
-                        .key(url)
+                        .key(removeBaseUrl(path))
                         .build())
                 .addTransferListener(LoggingTransferListener.create())
                 .destination(tempFilePath)
@@ -449,16 +448,6 @@
      */
     public String removeBaseUrl(String path) {
         return path.replace(getUrl() + StringUtils.SLASH, "");
-    }
-
-    /**
-     * 浠庢枃浠惰矾寰勪腑鎻愬彇鏂囦欢鍚�
-     *
-     * @param path 鏂囦欢璺緞
-     * @return 鎻愬彇鐨勬枃浠跺悕鎴栭粯璁ゆ枃浠跺悕
-     */
-    public String extractFileName(String path) {
-        return FileUtils.getTmpDir() + StringUtils.SLASH + Paths.get(path).getFileName().toString();
     }
 
     /**

--
Gitblit v1.9.3