From 941ff0ea853413549cec6bb924d1c5e934d7083b Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 27 May 2019 16:38:44 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E7=AE=80=E5=8C=96oss=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/builder/MinioBuilder.java | 14 ++--- .../resource/builder/OssBuilder.java | 6 +-- .../resource/builder/QiniuBuilder.java | 14 ++--- .../resource/config/OssConfiguration.java | 16 ++---- .../springblade/resource/enums/OssEnum.java | 45 ---------------- .../resource/enums/OssStatusEnum.java | 46 ---------------- .../resource/props/OssProperties.java | 53 ------------------- .../src/main/resources/application.yml | 2 + 8 files changed, 22 insertions(+), 174 deletions(-) delete mode 100644 blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssEnum.java delete mode 100644 blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssStatusEnum.java delete mode 100644 blade-ops/blade-resource/src/main/java/org/springblade/resource/props/OssProperties.java diff --git a/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/MinioBuilder.java b/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/MinioBuilder.java index 4be083de..16e1d979 100644 --- a/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/MinioBuilder.java +++ b/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/MinioBuilder.java @@ -19,8 +19,8 @@ package org.springblade.resource.builder; import io.minio.MinioClient; import lombok.SneakyThrows; import org.springblade.core.minio.MinioTemplate; -import org.springblade.core.minio.props.MinioProperties; import org.springblade.core.oss.OssTemplate; +import org.springblade.core.oss.props.OssProperties; import org.springblade.core.oss.rule.OssRule; import org.springblade.resource.entity.Oss; @@ -34,12 +34,12 @@ public class MinioBuilder { @SneakyThrows public static OssTemplate template(Oss oss, OssRule ossRule) { MinioClient minioClient = new MinioClient(oss.getEndpoint(), oss.getAccessKey(), oss.getSecretKey()); - MinioProperties minioProperties = new MinioProperties(); - minioProperties.setEndpoint(oss.getEndpoint()); - minioProperties.setAccessKey(oss.getAccessKey()); - minioProperties.setSecretKey(oss.getSecretKey()); - minioProperties.setBucketName(oss.getBucketName()); - return new MinioTemplate(minioClient, ossRule, minioProperties); + OssProperties ossProperties = new OssProperties(); + ossProperties.setEndpoint(oss.getEndpoint()); + ossProperties.setAccessKey(oss.getAccessKey()); + ossProperties.setSecretKey(oss.getSecretKey()); + ossProperties.setBucketName(oss.getBucketName()); + return new MinioTemplate(minioClient, ossRule, ossProperties); } } diff --git a/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/OssBuilder.java b/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/OssBuilder.java index 1f4dd513..27a7b614 100644 --- a/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/OssBuilder.java +++ b/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/OssBuilder.java @@ -19,14 +19,14 @@ package org.springblade.resource.builder; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.springblade.core.cache.utils.CacheUtil; import org.springblade.core.oss.OssTemplate; +import org.springblade.core.oss.enums.OssEnum; +import org.springblade.core.oss.enums.OssStatusEnum; +import org.springblade.core.oss.props.OssProperties; import org.springblade.core.oss.rule.OssRule; import org.springblade.core.secure.utils.SecureUtil; import org.springblade.core.tool.utils.Func; import org.springblade.resource.entity.Oss; -import org.springblade.resource.enums.OssStatusEnum; -import org.springblade.resource.enums.OssEnum; import org.springblade.resource.mapper.OssMapper; -import org.springblade.resource.props.OssProperties; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/QiniuBuilder.java b/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/QiniuBuilder.java index 99ced98b..b5b88d81 100644 --- a/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/QiniuBuilder.java +++ b/blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/QiniuBuilder.java @@ -23,9 +23,9 @@ import com.qiniu.storage.UploadManager; import com.qiniu.util.Auth; import lombok.SneakyThrows; import org.springblade.core.oss.OssTemplate; +import org.springblade.core.oss.props.OssProperties; import org.springblade.core.oss.rule.OssRule; import org.springblade.core.qiniu.QiniuTemplate; -import org.springblade.core.qiniu.props.QiniuProperties; import org.springblade.resource.entity.Oss; /** @@ -41,12 +41,12 @@ public class QiniuBuilder { Auth auth = Auth.create(oss.getAccessKey(), oss.getSecretKey()); UploadManager uploadManager = new UploadManager(cfg); BucketManager bucketManager = new BucketManager(auth, cfg); - QiniuProperties qiniuProperties = new QiniuProperties(); - qiniuProperties.setEndpoint(oss.getEndpoint()); - qiniuProperties.setAccessKey(oss.getAccessKey()); - qiniuProperties.setSecretKey(oss.getSecretKey()); - qiniuProperties.setBucketName(oss.getBucketName()); - return new QiniuTemplate(auth, uploadManager, bucketManager, qiniuProperties, ossRule); + OssProperties ossProperties = new OssProperties(); + ossProperties.setEndpoint(oss.getEndpoint()); + ossProperties.setAccessKey(oss.getAccessKey()); + ossProperties.setSecretKey(oss.getSecretKey()); + ossProperties.setBucketName(oss.getBucketName()); + return new QiniuTemplate(auth, uploadManager, bucketManager, ossProperties, ossRule); } } diff --git a/blade-ops/blade-resource/src/main/java/org/springblade/resource/config/OssConfiguration.java b/blade-ops/blade-resource/src/main/java/org/springblade/resource/config/OssConfiguration.java index bb4c1daf..54439b4e 100644 --- a/blade-ops/blade-resource/src/main/java/org/springblade/resource/config/OssConfiguration.java +++ b/blade-ops/blade-resource/src/main/java/org/springblade/resource/config/OssConfiguration.java @@ -17,14 +17,10 @@ package org.springblade.resource.config; import lombok.AllArgsConstructor; -import org.springblade.core.minio.rule.BladeMinioRule; +import org.springblade.core.oss.props.OssProperties; import org.springblade.core.oss.rule.OssRule; import org.springblade.resource.builder.OssBuilder; import org.springblade.resource.mapper.OssMapper; -import org.springblade.resource.props.OssProperties; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -35,22 +31,16 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @AllArgsConstructor -@EnableConfigurationProperties(OssProperties.class) public class OssConfiguration { private OssProperties ossProperties; private OssMapper ossMapper; - @Bean - @ConditionalOnMissingBean(OssRule.class) - public OssRule ossRule() { - return new BladeMinioRule(true); - } + private OssRule ossRule; @Bean - @ConditionalOnBean(OssRule.class) - public OssBuilder ossBuilder(OssRule ossRule) { + public OssBuilder ossBuilder() { return new OssBuilder(ossProperties, ossMapper, ossRule); } diff --git a/blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssEnum.java b/blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssEnum.java deleted file mode 100644 index 7de98bd8..00000000 --- a/blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssEnum.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the dreamlu.net developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: Chill 庄骞 (smallchill@163.com) - */ -package org.springblade.resource.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * Oss枚举类 - * - * @author Chill - */ -@Getter -@AllArgsConstructor -public enum OssEnum { - - /** - * minio - */ - MINIO("minio", 1), - - /** - * qiniu - */ - QINIU("qiniu", 2), - ; - - final String name; - final int category; - -} diff --git a/blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssStatusEnum.java b/blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssStatusEnum.java deleted file mode 100644 index 79976a80..00000000 --- a/blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssStatusEnum.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the dreamlu.net developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: Chill 庄骞 (smallchill@163.com) - */ -package org.springblade.resource.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * Oss类型枚举 - * - * @author Chill - */ -@Getter -@AllArgsConstructor -public enum OssStatusEnum { - - /** - * 关闭 - */ - DISABLE(1), - /** - * 启用 - */ - ENABLE(2), - ; - - /** - * 类型编号 - */ - final int num; - -} diff --git a/blade-ops/blade-resource/src/main/java/org/springblade/resource/props/OssProperties.java b/blade-ops/blade-resource/src/main/java/org/springblade/resource/props/OssProperties.java deleted file mode 100644 index 00da9c41..00000000 --- a/blade-ops/blade-resource/src/main/java/org/springblade/resource/props/OssProperties.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the dreamlu.net developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: Chill 庄骞 (smallchill@163.com) - */ -package org.springblade.resource.props; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * Oss配置 - * - * @author Chill - */ -@Data -@ConfigurationProperties(prefix = "oss") -public class OssProperties { - /** - * 是否开启租户模式 - */ - private Boolean tenantMode; - /** - * 对象存储服务的URL - */ - private String endpoint; - - /** - * Access key就像用户ID,可以唯一标识你的账户 - */ - private String accessKey; - - /** - * Secret key是你账户的密码 - */ - private String secretKey; - - /** - * 默认的存储桶名称 - */ - private String bucketName; -} diff --git a/blade-ops/blade-resource/src/main/resources/application.yml b/blade-ops/blade-resource/src/main/resources/application.yml index d2c4aa2a..e5a5bb18 100644 --- a/blade-ops/blade-resource/src/main/resources/application.yml +++ b/blade-ops/blade-resource/src/main/resources/application.yml @@ -3,6 +3,8 @@ server: port: 8010 oss: + enable: true + name: qiniu tenant-mode: true endpoint: prt1thnw3.bkt.clouddn.com access-key: N_Loh1ngBqcJovwiAJqR91Ifj2vgOWHOf8AwBA_h