update 增加OSS模块service自动激活
| | |
| | | package com.ruoyi.oss.enumd; |
| | | |
| | | import com.ruoyi.oss.service.impl.AliyunCloudStorageServiceImpl; |
| | | import com.ruoyi.oss.service.impl.MinioCloudStorageServiceImpl; |
| | | import com.ruoyi.oss.service.impl.QiniuCloudStorageServiceImpl; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | |
| | | /** |
| | | * 七牛云 |
| | | */ |
| | | QINIU("qiniu"), |
| | | QINIU("qiniu", QiniuCloudStorageServiceImpl.class), |
| | | |
| | | /** |
| | | * 阿里云 |
| | | */ |
| | | ALIYUN("aliyun"), |
| | | ALIYUN("aliyun", AliyunCloudStorageServiceImpl.class), |
| | | |
| | | /** |
| | | * 腾讯云 |
| | | */ |
| | | QCLOUD("qcloud"), |
| | | QCLOUD("qcloud", QiniuCloudStorageServiceImpl.class), |
| | | |
| | | /** |
| | | * minio |
| | | */ |
| | | MINIO("minio"); |
| | | MINIO("minio", MinioCloudStorageServiceImpl.class); |
| | | |
| | | private final String value; |
| | | |
| | | private final Class<?> serviceClass; |
| | | |
| | | public static Class<?> getServiceClass(String value) { |
| | | for (CloudServiceEnumd clazz : values()) { |
| | | if (clazz.getValue().equals(value)) { |
| | | return clazz.getServiceClass(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | |
| | | import cn.hutool.core.lang.Assert; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.oss.constant.CloudConstant; |
| | | import com.ruoyi.oss.enumd.CloudServiceEnumd; |
| | | import com.ruoyi.oss.service.ICloudStorageService; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | |
| | |
| | | |
| | | public static ICloudStorageService instance() { |
| | | String type = sysConfigService.selectConfigByKey(CloudConstant.CLOUD_STORAGE_CONFIG_KEY); |
| | | return SERVICES.get(type); |
| | | return instance(type); |
| | | } |
| | | |
| | | public static ICloudStorageService instance(String type) { |
| | | return SERVICES.get(type); |
| | | ICloudStorageService service = SERVICES.get(type); |
| | | if (service == null) { |
| | | service = (ICloudStorageService) SpringUtils.getBean(CloudServiceEnumd.getServiceClass(type)); |
| | | } |
| | | return service; |
| | | } |
| | | |
| | | public static void register(String type, ICloudStorageService iCloudStorageService) { |
| | |
| | | @Autowired |
| | | public AliyunCloudStorageServiceImpl(CloudStorageProperties properties) { |
| | | this.properties = properties.getAliyun(); |
| | | ClientConfiguration configuration = new ClientConfiguration(); |
| | | DefaultCredentialProvider credentialProvider = new DefaultCredentialProvider( |
| | | this.properties.getAccessKeyId(), |
| | | this.properties.getAccessKeySecret()); |
| | | client = new OSSClient(this.properties.getEndpoint(), credentialProvider, configuration); |
| | | try { |
| | | ClientConfiguration configuration = new ClientConfiguration(); |
| | | DefaultCredentialProvider credentialProvider = new DefaultCredentialProvider( |
| | | this.properties.getAccessKeyId(), |
| | | this.properties.getAccessKeySecret()); |
| | | client = new OSSClient(this.properties.getEndpoint(), credentialProvider, configuration); |
| | | } catch (Exception e) { |
| | | throw new IllegalArgumentException("阿里云存储配置错误! 请检查系统配置!"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Autowired |
| | | public MinioCloudStorageServiceImpl(CloudStorageProperties properties) { |
| | | this.properties = properties.getMinio(); |
| | | minioClient = MinioClient.builder() |
| | | .endpoint(this.properties.getEndpoint()) |
| | | .credentials(this.properties.getAccessKey(), this.properties.getSecretKey()) |
| | | .build(); |
| | | try { |
| | | minioClient = MinioClient.builder() |
| | | .endpoint(this.properties.getEndpoint()) |
| | | .credentials(this.properties.getAccessKey(), this.properties.getSecretKey()) |
| | | .build(); |
| | | } catch (Exception e) { |
| | | throw new IllegalArgumentException("Minio存储配置错误! 请检查系统配置!"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Autowired |
| | | public QcloudCloudStorageServiceImpl(CloudStorageProperties properties) { |
| | | this.properties = properties.getQcloud(); |
| | | COSCredentials credentials = new BasicCOSCredentials( |
| | | this.properties.getSecretId(), |
| | | this.properties.getSecretKey()); |
| | | // 初始化客户端配置 |
| | | ClientConfig clientConfig = new ClientConfig(); |
| | | // 设置bucket所在的区域,华南:gz 华北:tj 华东:sh |
| | | clientConfig.setRegion(new Region(this.properties.getRegion())); |
| | | client = new COSClient(credentials, clientConfig); |
| | | try { |
| | | COSCredentials credentials = new BasicCOSCredentials( |
| | | this.properties.getSecretId(), |
| | | this.properties.getSecretKey()); |
| | | // 初始化客户端配置 |
| | | ClientConfig clientConfig = new ClientConfig(); |
| | | // 设置bucket所在的区域,华南:gz 华北:tj 华东:sh |
| | | clientConfig.setRegion(new Region(this.properties.getRegion())); |
| | | client = new COSClient(credentials, clientConfig); |
| | | } catch (Exception e) { |
| | | throw new IllegalArgumentException("腾讯云存储配置错误! 请检查系统配置!"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Autowired |
| | | public QiniuCloudStorageServiceImpl(CloudStorageProperties properties) { |
| | | this.properties = properties.getQiniu(); |
| | | // z0 z1 z2 |
| | | Configuration config = new Configuration(Region.autoRegion()); |
| | | // 默认不使用https |
| | | config.useHttpsDomains = false; |
| | | 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); |
| | | try { |
| | | // z0 z1 z2 |
| | | Configuration config = new Configuration(Region.autoRegion()); |
| | | // 默认不使用https |
| | | config.useHttpsDomains = false; |
| | | 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); |
| | | } catch (Exception e) { |
| | | throw new IllegalArgumentException("七牛云存储配置错误! 请检查系统配置!"); |
| | | } |
| | | } |
| | | |
| | | |