From 9b2eedb85d53ca32610c32c6e50b5230ab3b16cf Mon Sep 17 00:00:00 2001
From: sean.zhou <sean.zhou@dji.com>
Date: Fri, 22 Jul 2022 20:16:03 +0800
Subject: [PATCH] V1.1.0 for dock

---
 src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java |   54 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java b/src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java
index 76d4e5d..633c35f 100644
--- a/src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java
+++ b/src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java
@@ -1,6 +1,7 @@
 package com.dji.sample.component.oss.service.impl;
 
-import com.dji.sample.component.oss.model.MinIOConfiguration;
+import com.dji.sample.component.oss.model.OssConfiguration;
+import com.dji.sample.component.oss.model.enums.OssTypeEnum;
 import com.dji.sample.component.oss.service.IOssService;
 import com.dji.sample.media.model.CredentialsDTO;
 import io.minio.GetPresignedObjectUrlArgs;
@@ -26,16 +27,21 @@
 @Slf4j
 public class MinIOServiceImpl implements IOssService {
 
-    @Autowired(required = false)
-    private MinioClient client;
+    @Autowired
+    private OssConfiguration configuration;
+
+    @Override
+    public String getOssType() {
+        return OssTypeEnum.MINIO.getType();
+    }
 
     @Override
     public CredentialsDTO getCredentials() {
         try {
-            AssumeRoleProvider provider = new AssumeRoleProvider(MinIOConfiguration.endpoint, MinIOConfiguration.accessKey,
-                    MinIOConfiguration.secretKey, MinIOConfiguration.expire,
-                    null, null, null, null, null, null);
-            return new CredentialsDTO(provider.fetch(), MinIOConfiguration.expire);
+            AssumeRoleProvider provider = new AssumeRoleProvider(configuration.getEndpoint(), configuration.getAccessKey(),
+                    configuration.getSecretKey(), Math.toIntExact(configuration.getExpire()),
+                    null, configuration.getRegion(), null, null, null, null);
+            return new CredentialsDTO(provider.fetch(), Math.toIntExact(configuration.getExpire()));
         } catch (NoSuchAlgorithmException e) {
             log.debug("Failed to obtain sts.");
             e.printStackTrace();
@@ -47,20 +53,38 @@
     public URL getObjectUrl(String bucket, String objectKey) {
         try {
             return new URL(
-                    client.getPresignedObjectUrl(
-                            GetPresignedObjectUrlArgs.builder()
-                                    .method(Method.GET)
-                                    .bucket(bucket)
-                                    .object(objectKey)
-                                    .expiry(MinIOConfiguration.expire)
-                                    .build()));
+                    this.createClient()
+                            .getPresignedObjectUrl(
+                                    GetPresignedObjectUrlArgs.builder()
+                                            .method(Method.GET)
+                                            .bucket(bucket)
+                                            .object(objectKey)
+                                            .expiry(Math.toIntExact(configuration.getExpire()))
+                                            .build()));
         } catch (ErrorResponseException | InsufficientDataException | InternalException |
                 InvalidKeyException | InvalidResponseException | IOException |
                 NoSuchAlgorithmException | XmlParserException | ServerException e) {
-            log.error("The file does not exist on the oss.");
+            log.error("The file does not exist on the OssConfiguration.");
             e.printStackTrace();
         }
         return null;
     }
 
+    @Override
+    public Boolean deleteObject(String bucket, String objectKey) {
+        return null;
+    }
+
+    @Override
+    public byte[] getObject(String bucket, String objectKey) {
+        return new byte[0];
+    }
+
+    private MinioClient createClient() {
+        return MinioClient.builder()
+                .endpoint(configuration.getEndpoint())
+                .credentials(configuration.getAccessKey(), configuration.getSecretKey())
+                .region(configuration.getRegion())
+                .build();
+    }
 }

--
Gitblit v1.9.3