Browse Source

简化oss配置

test
smallchill 6 years ago
parent
commit
941ff0ea85
  1. 14
      blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/MinioBuilder.java
  2. 6
      blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/OssBuilder.java
  3. 14
      blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/QiniuBuilder.java
  4. 16
      blade-ops/blade-resource/src/main/java/org/springblade/resource/config/OssConfiguration.java
  5. 45
      blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssEnum.java
  6. 46
      blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssStatusEnum.java
  7. 53
      blade-ops/blade-resource/src/main/java/org/springblade/resource/props/OssProperties.java
  8. 2
      blade-ops/blade-resource/src/main/resources/application.yml

14
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);
}
}

6
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;

14
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);
}
}

16
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);
}

45
blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssEnum.java

@ -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;
}

46
blade-ops/blade-resource/src/main/java/org/springblade/resource/enums/OssStatusEnum.java

@ -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;
}

53
blade-ops/blade-resource/src/main/java/org/springblade/resource/props/OssProperties.java

@ -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;
}

2
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

Loading…
Cancel
Save