瀏覽代碼

add FileStorageTemplate getInternalEndpoint

xiewj 1 年之前
父節點
當前提交
5c94f3aacc

+ 1 - 1
4dkankan-utils-filestorage/src/main/java/com/fdkankan/filestorage/FileStorageTemplate.java

@@ -101,7 +101,7 @@ public interface FileStorageTemplate {
 
     Long getSpace(String bucket, String key);
     Long getSpace( String key);
+    String getInternalEndpoint(String bucket ,String key);
     String getInternalEndpoint(String key);
-    String getInternalEndpoint();
 
 }

+ 14 - 4
4dkankan-utils-filestorage/src/main/java/com/fdkankan/filestorage/aliyun/AliyunOssTemplate.java

@@ -11,6 +11,7 @@ import com.fdkankan.filestorage.InnerUtils;
 import com.fdkankan.filestorage.FileStorageTemplate;
 import com.fdkankan.filestorage.properties.AliyunOssProperties;
 import lombok.Getter;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.stereotype.Service;
@@ -19,6 +20,7 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import java.io.*;
+import java.net.URI;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
@@ -394,13 +396,21 @@ public class AliyunOssTemplate implements FileStorageTemplate {
         return  getSpace(ossProperties.getBucket(), key);
     }
 
+    @SneakyThrows
     @Override
-    public String getInternalEndpoint(String key) {
-        return ossProperties.getInternalEndpoint()+"/"+key;
+    public String getInternalEndpoint(String bucket ,String key) {
+        URI uri = new URI(ossProperties.getInternalEndpoint());
+        String host = uri.getHost();
+        host=bucket+"."+host;
+        return new URI(uri.getScheme(), host, uri.getPath()+"/"+key, uri.getFragment()).toString();
     }
 
     @Override
-    public String getInternalEndpoint() {
-        return ossProperties.getInternalEndpoint()+"/";
+    @SneakyThrows
+    public String getInternalEndpoint(String key) {
+        URI uri = new URI(ossProperties.getInternalEndpoint());
+        String host = uri.getHost();
+        host=this.getBucket()+"."+host;
+        return new URI(uri.getScheme(), host, uri.getPath()+"/"+key, uri.getFragment()).toString();
     }
 }

+ 14 - 4
4dkankan-utils-filestorage/src/main/java/com/fdkankan/filestorage/aws/AwsTemplate.java

@@ -15,12 +15,14 @@ import com.fdkankan.filestorage.InnerUtils;
 import com.fdkankan.filestorage.FileStorageTemplate;
 import com.fdkankan.filestorage.properties.AwsProperties;
 import lombok.Getter;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Base64Utils;
 
 import java.io.*;
+import java.net.URI;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
@@ -444,13 +446,21 @@ public class AwsTemplate implements FileStorageTemplate {
     public Long getSpace(String key) {
         return  getSpace(awsProperties.getBucket(), key);
     }
+    @SneakyThrows
     @Override
-    public String getInternalEndpoint(String key) {
-        return awsProperties.getInternalEndpoint()+"/"+key;
+    public String getInternalEndpoint(String bucket ,String key) {
+        URI uri = new URI(awsProperties.getInternalEndpoint());
+        String host = uri.getHost();
+        host=bucket+"."+host;
+        return new URI(uri.getScheme(), host, uri.getPath()+"/"+key, uri.getFragment()).toString();
     }
 
     @Override
-    public String getInternalEndpoint() {
-        return awsProperties.getInternalEndpoint()+"/";
+    @SneakyThrows
+    public String getInternalEndpoint(String key) {
+        URI uri = new URI(awsProperties.getInternalEndpoint());
+        String host = uri.getHost();
+        host=this.getBucket()+"."+host;
+        return new URI(uri.getScheme(), host, uri.getPath()+"/"+key, uri.getFragment()).toString();
     }
 }

+ 14 - 4
4dkankan-utils-filestorage/src/main/java/com/fdkankan/filestorage/cos/CosTemplate.java

@@ -10,6 +10,7 @@ import com.fdkankan.filestorage.properties.CosProperties;
 import com.qcloud.cos.COSClient;
 import com.qcloud.cos.model.*;
 import lombok.Getter;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.stereotype.Service;
@@ -17,6 +18,7 @@ import org.springframework.util.Base64Utils;
 import org.springframework.util.CollectionUtils;
 
 import java.io.*;
+import java.net.URI;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
@@ -403,13 +405,21 @@ public class CosTemplate implements FileStorageTemplate {
     public Long getSpace(String key) {
         return  getSpace(cosProperties.getBucket(), key);
     }
+    @SneakyThrows
     @Override
-    public String getInternalEndpoint(String key) {
-        return cosProperties.getInternalEndpoint()+"/"+key;
+    public String getInternalEndpoint(String bucket ,String key) {
+        URI uri = new URI(cosProperties.getInternalEndpoint());
+        String host = uri.getHost();
+        host=bucket+"."+host;
+        return new URI(uri.getScheme(), host, uri.getPath()+"/"+key, uri.getFragment()).toString();
     }
 
     @Override
-    public String getInternalEndpoint() {
-        return cosProperties.getInternalEndpoint()+"/";
+    @SneakyThrows
+    public String getInternalEndpoint(String key) {
+        URI uri = new URI(cosProperties.getInternalEndpoint());
+        String host = uri.getHost();
+        host=this.getBucket()+"."+host;
+        return new URI(uri.getScheme(), host, uri.getPath()+"/"+key, uri.getFragment()).toString();
     }
 }

+ 14 - 4
4dkankan-utils-filestorage/src/main/java/com/fdkankan/filestorage/minio/MinioTemplate.java

@@ -18,12 +18,14 @@ import io.minio.*;
 import io.minio.errors.*;
 import io.minio.messages.Item;
 import lombok.Getter;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Base64Utils;
 
 import java.io.*;
+import java.net.URI;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -447,13 +449,21 @@ public class MinioTemplate implements FileStorageTemplate {
     public Long getSpace(String key) {
         return  getSpace(minioProperties.getBucket(), key);
     }
+    @SneakyThrows
     @Override
-    public String getInternalEndpoint(String key) {
-        return minioProperties.getInternalEndpoint()+"/"+key;
+    public String getInternalEndpoint(String bucket ,String key) {
+        URI uri = new URI(minioProperties.getInternalEndpoint());
+        String host = uri.getHost();
+        host=bucket+"."+host;
+        return new URI(uri.getScheme(), host, uri.getPath()+"/"+key, uri.getFragment()).toString();
     }
 
     @Override
-    public String getInternalEndpoint() {
-        return minioProperties.getInternalEndpoint()+"/";
+    @SneakyThrows
+    public String getInternalEndpoint(String key) {
+        URI uri = new URI(minioProperties.getInternalEndpoint());
+        String host = uri.getHost();
+        host=this.getBucket()+"."+host;
+        return new URI(uri.getScheme(), host, uri.getPath()+"/"+key, uri.getFragment()).toString();
     }
 }

+ 1 - 0
pom.xml

@@ -30,6 +30,7 @@
         <module>4dkankan-utils-elasticsearch</module>
         <module>4dkankan-utils-reg</module>
         <module>4dkankan-utils-filestorage</module>
+        <module>4dkankan-utils-disruptormq</module>
     </modules>
 
     <groupId>com.fdkankan</groupId>