From e680edf65d23cff712014e25a527b1b5bf84ad32 Mon Sep 17 00:00:00 2001 From: xuyuxiang Date: Thu, 2 Mar 2023 15:20:36 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E5=8D=87?= =?UTF-8?q?=E7=BA=A7MINIO=E7=89=88=E6=9C=AC=EF=BC=8C=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=B8=AD=E7=9A=84jar=E5=8C=85=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snowy-common/pom.xml | 33 ++++++++++ snowy-plugin-api/snowy-plugin-dev-api/pom.xml | 52 ++++++++++++++- .../modular/file/util/DevFileAliyunUtil.java | 2 +- .../modular/file/util/DevFileMinIoUtil.java | 66 ++++++++++++------- .../modular/file/util/DevFileTencentUtil.java | 2 +- snowy-web-app/pom.xml | 2 +- 6 files changed, 129 insertions(+), 28 deletions(-) diff --git a/snowy-common/pom.xml b/snowy-common/pom.xml index 5ced3e3f..abfacf38 100644 --- a/snowy-common/pom.xml +++ b/snowy-common/pom.xml @@ -94,6 +94,18 @@ io.springfox springfox-schema + + asm + org.ow2.asm + + + guava + com.google.guava + + + fastjson + com.alibaba + @@ -157,6 +169,20 @@ cn.afterturn easypoi-spring-boot-starter ${easypoi.version} + + + commons-compress + org.apache.commons + + + guava + com.google.guava + + + javassist + org.javassist + + @@ -165,5 +191,12 @@ sm-crypto ${smcrypto.version} + + + + com.squareup.okhttp3 + okhttp + ${okhttp3.version} + diff --git a/snowy-plugin-api/snowy-plugin-dev-api/pom.xml b/snowy-plugin-api/snowy-plugin-dev-api/pom.xml index e9036cbf..d4f12bbd 100644 --- a/snowy-plugin-api/snowy-plugin-dev-api/pom.xml +++ b/snowy-plugin-api/snowy-plugin-dev-api/pom.xml @@ -19,7 +19,7 @@ 3.1.455 3.1.455 3.14.0 - 3.0.12 + 8.5.2 1.6.2 3.3.1 3.1.0 @@ -40,6 +40,12 @@ com.qcloud cos_api ${ten.cos.version} + + + tencentcloud-sdk-java-common + com.tencentcloudapi + + @@ -54,6 +60,16 @@ io.minio minio ${minio.version} + + + okhttp + com.squareup.okhttp3 + + + bcprov-jdk15on + org.bouncycastle + + @@ -68,6 +84,12 @@ com.aliyun aliyun-java-sdk-dm ${aliyun.sdk.dm.version} + + + javax.mail + com.sun.mail + + @@ -75,6 +97,20 @@ com.tencentcloudapi tencentcloud-sdk-java-ses ${ten.sdk.ses.version} + + + okhttp + com.squareup.okhttp + + + logging-interceptor + com.squareup.okhttp + + + okio + com.squareup.okio + + @@ -82,6 +118,20 @@ com.aliyun dysmsapi20170525 ${aliyun.sdk.dysmsapi.version} + + + okhttp + com.squareup.okhttp3 + + + bcprov-jdk15on + org.bouncycastle + + + org.jacoco.agent + org.jacoco + + diff --git a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileAliyunUtil.java b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileAliyunUtil.java index 385a3f87..70a1e9ee 100644 --- a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileAliyunUtil.java +++ b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileAliyunUtil.java @@ -240,7 +240,7 @@ public class DevFileAliyunUtil { byteArrayInputStream = new ByteArrayInputStream(bytes); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentType(getFileContentType(key)); - client.putObject(bucketName, key, new ByteArrayInputStream(bytes), objectMetadata); + client.putObject(bucketName, key, byteArrayInputStream, objectMetadata); } catch (OSSException | ClientException e) { throw new CommonException(e.getMessage()); } finally { diff --git a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileMinIoUtil.java b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileMinIoUtil.java index bbc683b6..a54984ec 100644 --- a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileMinIoUtil.java +++ b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileMinIoUtil.java @@ -18,11 +18,11 @@ import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; -import io.minio.MinioClient; -import io.minio.errors.InvalidEndpointException; -import io.minio.errors.InvalidPortException; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import io.minio.*; import io.minio.http.Method; -import io.minio.policy.PolicyType; import lombok.extern.slf4j.Slf4j; import org.springframework.web.multipart.MultipartFile; import vip.xiaonuo.common.exception.CommonException; @@ -90,11 +90,7 @@ public class DevFileMinIoUtil { throw new CommonException("MINIO文件操作客户端未正确配置:defaultBucketName为空"); } - try { - client = new MinioClient(endpoint, accessKey, secretKey); - } catch (InvalidEndpointException | InvalidPortException e) { - throw new CommonException(e.getMessage()); - } + client = MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build(); } /** @@ -139,7 +135,8 @@ public class DevFileMinIoUtil { public static boolean doesBucketExist(String bucketName) { try { initClient(); - client.bucketExists(bucketName); + BucketExistsArgs bucketExistsArgs = BucketExistsArgs.builder().bucket(bucketName).build(); + client.bucketExists(bucketExistsArgs); } catch (Exception e) { throw new CommonException(e.getMessage()); } @@ -170,7 +167,8 @@ public class DevFileMinIoUtil { public static boolean isExistingFile(String bucketName, String key) { try { initClient(); - InputStream object = client.getObject(bucketName, key); + GetObjectArgs getObjectArgs = GetObjectArgs.builder().bucket(bucketName).object(key).build(); + InputStream object = client.getObject(getObjectArgs); return !ObjectUtil.isEmpty(object); } catch (Exception e) { return false; @@ -229,7 +227,9 @@ public class DevFileMinIoUtil { try { initClient(); byteArrayInputStream = new ByteArrayInputStream(bytes); - client.putObject(bucketName, key, new ByteArrayInputStream(bytes), bytes.length, getFileContentType(key)); + PutObjectArgs putObjectArgs = PutObjectArgs.builder().bucket(bucketName).object(key) + .contentType(getFileContentType(key)).stream(byteArrayInputStream, bytes.length, -1).build(); + client.putObject(putObjectArgs); } catch (Exception e) { throw new CommonException(e.getMessage()); } finally { @@ -249,7 +249,9 @@ public class DevFileMinIoUtil { public static void storageFile(String bucketName, String key, InputStream inputStream) { try { initClient(); - client.putObject(bucketName, key, inputStream, inputStream.available(), getFileContentType(key)); + PutObjectArgs putObjectArgs = PutObjectArgs.builder().bucket(bucketName).object(key) + .contentType(getFileContentType(key)).stream(inputStream, inputStream.available(), -1).build(); + client.putObject(putObjectArgs); } catch (Exception e) { throw new CommonException(e.getMessage()); } finally { @@ -328,7 +330,8 @@ public class DevFileMinIoUtil { public static byte[] getFileBytes(String bucketName, String key) { try { initClient(); - InputStream inputStream = client.getObject(bucketName, key); + GetObjectArgs getObjectArgs = GetObjectArgs.builder().bucket(bucketName).object(key).build(); + InputStream inputStream = client.getObject(getObjectArgs); return IoUtil.readBytes(inputStream); } catch (Exception e) { throw new CommonException(e.getMessage()); @@ -339,20 +342,30 @@ public class DevFileMinIoUtil { * 设置文件访问权限管理 * * @param bucketName 桶名称 - * @param key 唯一标示id,例如a.txt, doc/a.txt + * @param key 唯一标示id,例如a.txt, doc/a.txt * @param devFileBucketAuthEnum 文件权限 * @author xuyuxiang * @date 2022/1/5 23:24 */ public static void setFileAcl(String bucketName, String key, DevFileBucketAuthEnum devFileBucketAuthEnum) { try { - if (devFileBucketAuthEnum.equals(DevFileBucketAuthEnum.PRIVATE)) { - client.setBucketPolicy(bucketName, key, PolicyType.NONE); - } else if (devFileBucketAuthEnum.equals(DevFileBucketAuthEnum.PUBLIC_READ)) { - client.setBucketPolicy(bucketName, key, PolicyType.READ_ONLY); - } else if (devFileBucketAuthEnum.equals(DevFileBucketAuthEnum.PUBLIC_READ_WRITE)) { - client.setBucketPolicy(bucketName, key, PolicyType.READ_WRITE); + JSONObject configObject = JSONUtil.createObj().set("Version", "2012-10-17"); + JSONArray statementArray = JSONUtil.createArray(); + JSONArray actionArray = JSONUtil.createArray(); + if (devFileBucketAuthEnum.equals(DevFileBucketAuthEnum.PUBLIC_READ)) { + actionArray.put("s3:GetObject"); + } else { + actionArray.put("s3:GetObject"); + actionArray.put("s3:PutObject"); } + JSONObject statementObject = JSONUtil.createObj(); + statementObject.set("Effect", "Allow").set("Principal", JSONUtil.createObj().set("AWS", JSONUtil.createArray().put("*"))) + .set("Action", actionArray).set("Resource", JSONUtil.createArray().put("arn:aws:s3:::" + bucketName + "/*")); + statementArray.put(statementObject); + configObject.set("Statement", statementArray); + String config = JSONUtil.toJsonStr(configObject); + SetBucketPolicyArgs setBucketPolicyArgs = SetBucketPolicyArgs.builder().bucket(bucketName).config(config).build(); + client.setBucketPolicy(setBucketPolicyArgs); } catch (Exception e) { throw new CommonException(e.getMessage()); } @@ -371,7 +384,9 @@ public class DevFileMinIoUtil { public static void copyFile(String originBucketName, String originFileKey, String newBucketName, String newFileKey) { try { initClient(); - client.copyObject(originBucketName, originFileKey, newBucketName, newFileKey); + CopySource copySource = CopySource.builder().bucket(originBucketName).object(originFileKey).build(); + CopyObjectArgs copyObjectArgs = CopyObjectArgs.builder().source(copySource).bucket(newBucketName).object(newFileKey).build(); + client.copyObject(copyObjectArgs); } catch (Exception e) { throw new CommonException(e.getMessage()); } @@ -389,7 +404,9 @@ public class DevFileMinIoUtil { public static String getFileAuthUrl(String bucketName, String key, Long timeoutMillis) { try { initClient(); - return client.getPresignedObjectUrl(Method.GET, bucketName, key, timeoutMillis.intValue(), null); + GetPresignedObjectUrlArgs getPresignedObjectUrlArgs = GetPresignedObjectUrlArgs.builder().bucket(bucketName) + .object(key).method(Method.GET).expiry(timeoutMillis.intValue()).build(); + return client.getPresignedObjectUrl(getPresignedObjectUrlArgs); } catch (Exception e) { throw new CommonException(e.getMessage()); } @@ -423,7 +440,8 @@ public class DevFileMinIoUtil { */ public static void deleteFile(String bucketName, String key) { try { - client.removeObject(bucketName, key); + RemoveObjectArgs removeObjectArgs = RemoveObjectArgs.builder().bucket(bucketName).object(key).build(); + client.removeObject(removeObjectArgs); } catch (Exception e) { throw new CommonException(e.getMessage()); } diff --git a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileTencentUtil.java b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileTencentUtil.java index 7cbaf8da..d3a6c882 100644 --- a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileTencentUtil.java +++ b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/file/util/DevFileTencentUtil.java @@ -271,7 +271,7 @@ public class DevFileTencentUtil { byteArrayInputStream = new ByteArrayInputStream(bytes); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentType(getFileContentType(key)); - client.putObject(bucketName, key, new ByteArrayInputStream(bytes), objectMetadata); + client.putObject(bucketName, key, byteArrayInputStream, objectMetadata); } catch (CosClientException e) { throw new CommonException(e.getMessage()); } finally { diff --git a/snowy-web-app/pom.xml b/snowy-web-app/pom.xml index 72cdcbbf..e67d9dc7 100644 --- a/snowy-web-app/pom.xml +++ b/snowy-web-app/pom.xml @@ -15,8 +15,8 @@ 主启动模块 + 4.9.3 4.13.2 - 1.18.22 3.5.1 8.0.28 21.5.0.0