Parcourir la source

update 更新OSS模块 七牛云相关代码

疯狂的狮子li il y a 3 ans
Parent
commit
22fd00832d

+ 11 - 1
ruoyi-oss/src/main/java/com/ruoyi/oss/properties/CloudStorageProperties.java

@@ -143,7 +143,7 @@ public class CloudStorageProperties {
 	 */
 	@Data
 	@NoArgsConstructor
-	public class QiniuProperties {
+	public static class QiniuProperties {
 
 		/**
 		 * 七牛绑定的域名
@@ -170,6 +170,16 @@ public class CloudStorageProperties {
 		 */
 		private String bucketName;
 
+		/**
+		 * 七牛存储区域
+		 */
+		private String region;
+
+		/**
+		 * 七牛存储区域
+		 */
+		private Boolean isHttps;
+
 	}
 
 }

+ 27 - 4
ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ruoyi.oss.service.impl;
 
+import cn.hutool.core.util.ArrayUtil;
 import com.qiniu.http.Response;
 import com.qiniu.storage.BucketManager;
 import com.qiniu.storage.Configuration;
@@ -38,22 +39,27 @@ public class QiniuCloudStorageServiceImpl extends AbstractCloudStorageService im
 	public QiniuCloudStorageServiceImpl(CloudStorageProperties properties) {
 		this.properties = properties.getQiniu();
 		try {
-			// z0 z1 z2
-			Configuration config = new Configuration(Region.autoRegion());
-			// 默认不使用https
+			Configuration config = new Configuration(getRegion(this.properties.getRegion()));
+			// https设置
 			config.useHttpsDomains = false;
+			if (this.properties.getIsHttps() != null) {
+				config.useHttpsDomains = this.properties.getIsHttps();
+			}
 			uploadManager = new UploadManager(config);
 			Auth auth = Auth.create(
 				this.properties.getAccessKey(),
 				this.properties.getSecretKey());
 			token = auth.uploadToken(this.properties.getBucketName());
 			bucketManager = new BucketManager(auth, config);
+
+			if (!ArrayUtil.contains(bucketManager.buckets(), this.properties.getBucketName())) {
+				bucketManager.createBucket(this.properties.getBucketName(), this.properties.getRegion());
+			}
 		} catch (Exception e) {
 			throw new IllegalArgumentException("七牛云存储配置错误! 请检查系统配置!");
 		}
 	}
 
-
 	@Override
 	public String getServiceType() {
 		return CloudServiceEnumd.QINIU.getValue();
@@ -100,4 +106,21 @@ public class QiniuCloudStorageServiceImpl extends AbstractCloudStorageService im
 		OssFactory.register(getServiceType(),this);
 	}
 
+	private Region getRegion(String region) {
+		switch (region) {
+			case "z0":
+				return Region.region0();
+			case "z1":
+				return Region.region1();
+			case "z2":
+				return Region.region2();
+			case "na0":
+				return Region.regionNa0();
+			case "as0":
+				return Region.regionAs0();
+			default:
+				return Region.autoRegion();
+		}
+	}
+
 }