From 0375fd319c9f3b08d255c814cb0f8521d8ec641b Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期三, 18 八月 2021 11:11:24 +0800 Subject: [PATCH] !78 同步dev分支 Merge pull request !78 from 疯狂的狮子Li/dev --- ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java | 41 +++++++++++------------------------------ 1 files changed, 11 insertions(+), 30 deletions(-) diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageServiceImpl.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java similarity index 70% rename from ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageServiceImpl.java rename to ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java index f7b4d4e..ef22513 100644 --- a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageServiceImpl.java +++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java @@ -10,51 +10,37 @@ import com.ruoyi.oss.entity.UploadResult; import com.ruoyi.oss.enumd.CloudServiceEnumd; import com.ruoyi.oss.exception.OssException; -import com.ruoyi.oss.factory.OssFactory; import com.ruoyi.oss.properties.CloudStorageProperties; -import com.ruoyi.oss.properties.CloudStorageProperties.QiniuProperties; -import com.ruoyi.oss.service.abstractd.AbstractCloudStorageService; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; +import com.ruoyi.oss.service.abstractd.AbstractCloudStorageStrategy; import java.io.InputStream; /** - * 涓冪墰浜戝瓨鍌� + * 涓冪墰浜戝瓨鍌ㄧ瓥鐣� * * @author Lion Li */ -@Lazy -@Service -public class QiniuCloudStorageServiceImpl extends AbstractCloudStorageService implements InitializingBean { +public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy { private final UploadManager uploadManager; private final BucketManager bucketManager; private final String token; - private final QiniuProperties properties; - @Autowired - public QiniuCloudStorageServiceImpl(CloudStorageProperties properties) { - this.properties = properties.getQiniu(); + public QiniuCloudStorageStrategy(CloudStorageProperties cloudStorageProperties) { + properties = cloudStorageProperties; try { - Configuration config = new Configuration(getRegion(this.properties.getRegion())); + Configuration config = new Configuration(getRegion(properties.getRegion())); // https璁剧疆 config.useHttpsDomains = false; - if (this.properties.getIsHttps() != null) { - config.useHttpsDomains = this.properties.getIsHttps(); - } + config.useHttpsDomains = "Y".equals(properties.getIsHttps()); uploadManager = new UploadManager(config); - Auth auth = Auth.create( - this.properties.getAccessKey(), - this.properties.getSecretKey()); - String bucketName = this.properties.getBucketName(); + Auth auth = Auth.create(properties.getAccessKey(), properties.getSecretKey()); + String bucketName = properties.getBucketName(); token = auth.uploadToken(bucketName); bucketManager = new BucketManager(auth, config); if (!ArrayUtil.contains(bucketManager.buckets(), bucketName)) { - bucketManager.createBucket(bucketName, this.properties.getRegion()); + bucketManager.createBucket(bucketName, properties.getRegion()); } } catch (Exception e) { throw new IllegalArgumentException("涓冪墰浜戝瓨鍌ㄩ厤缃敊璇�! 璇锋鏌ョ郴缁熼厤缃�!"); @@ -116,13 +102,8 @@ } @Override - public void afterPropertiesSet() throws Exception { - OssFactory.register(getServiceType(),this); - } - - @Override public String getEndpointLink() { - return properties.getDomain(); + return properties.getEndpoint(); } private Region getRegion(String region) { -- Gitblit v1.9.3