Skip to content

Commit

Permalink
fix: pom bug
Browse files Browse the repository at this point in the history
feat: 资源相应的调整
  • Loading branch information
fuhouyu committed Oct 30, 2024
1 parent 13a2c43 commit dd27b5d
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
import com.aliyun.oss.common.auth.STSAssumeRoleSessionCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.fuhouyu.framework.common.utils.LoggerUtil;
import com.fuhouyu.framework.resource.properties.AliYunOssProperties;
import com.fuhouyu.framework.resource.properties.BaseOssResourceProperties;
import com.fuhouyu.framework.resource.properties.ResourceProperties;
import com.fuhouyu.framework.resource.service.ResourceService;
import com.fuhouyu.framework.resource.service.impl.AliYunOssServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -48,8 +46,9 @@
@ConditionalOnClass(OSS.class)
@RequiredArgsConstructor
@Slf4j
@EnableConfigurationProperties(AliYunOssProperties.class)
@Configuration
@ConditionalOnProperty(prefix = ResourceProperties.PREFIX,
name = "upload-type", havingValue = "ali")
public class AliYunOssAutoConfiguration implements InitializingBean {

private final ResourceProperties resourceProperties;
Expand All @@ -62,7 +61,7 @@ public class AliYunOssAutoConfiguration implements InitializingBean {
*/
@Bean
public OSS ossClient() {
AliYunOssProperties ossConfig = resourceProperties.getAliOssConfig();
ResourceProperties.AliYunOssProperties ossConfig = resourceProperties.getAliyunOss();

if (ossConfig.isEnableSts()) {
STSAssumeRoleSessionCredentialsProvider credentialsProvider;
Expand Down Expand Up @@ -96,8 +95,8 @@ public ResourceService resourceService(OSS oss) {

@Override
public void afterPropertiesSet() throws Exception {
BaseOssResourceProperties ossConfig = resourceProperties.getAliOssConfig();
if (Objects.isNull(ossConfig)) {
ResourceProperties.AliYunOssProperties aliOssConfig = resourceProperties.getAliyunOss();
if (Objects.isNull(aliOssConfig)) {
throw new IllegalArgumentException("阿里云oss未设置相应的ak/sk");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@

package com.fuhouyu.framework.resource;

import com.fuhouyu.framework.common.utils.LoggerUtil;
import com.fuhouyu.framework.resource.properties.ResourceProperties;
import com.fuhouyu.framework.resource.service.ResourceService;
import com.fuhouyu.framework.resource.service.impl.LocalFileServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Objects;

/**
* <p>
* 本地文件资源自动装配类
Expand All @@ -31,8 +38,13 @@
* @since 2024/8/18 17:28
*/
@Configuration(proxyBeanMethods = false)
public class LocalFileResourceAutoConfiguration {
@RequiredArgsConstructor
@Slf4j
@ConditionalOnProperty(prefix = ResourceProperties.PREFIX,
name = "upload-type", havingValue = "local")
public class LocalFileResourceConfiguration {

private final ResourceProperties resourceProperties;

/**
* 本地资源文件bean
Expand All @@ -42,6 +54,14 @@ public class LocalFileResourceAutoConfiguration {
@Bean
@ConditionalOnMissingBean(ResourceService.class)
public ResourceService localFileResourceService() {
return new LocalFileServiceImpl();
String basePath;
if (Objects.isNull(resourceProperties.getLocalResource()) ||
Objects.isNull(resourceProperties.getLocalResource().getBasePath())) {
basePath = System.getProperty("java.io.tmpdir");
LoggerUtil.warn(log, "本地路径不存在,获取系统tmp路径:{}", basePath);
} else {
basePath = resourceProperties.getLocalResource().getBasePath();
}
return new LocalFileServiceImpl(basePath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @author fuhouyu
* @since 2024/8/16 18:36
*/
@Import({AliYunOssAutoConfiguration.class, LocalFileResourceAutoConfiguration.class})
@Import({AliYunOssAutoConfiguration.class, LocalFileResourceConfiguration.class})
@EnableConfigurationProperties(ResourceProperties.class)
@Configuration
public class ResourceAutoConfiguration {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,77 @@ public class ResourceProperties {
/**
* 文件资源配置基类
*/
private AliYunOssProperties aliOssConfig;
private AliYunOssProperties aliyunOss;

/**
* 本地配置
*/
private LocalResourceProperties localResource;

@Getter
@Setter
@ToString
public static class LocalResourceProperties {
/**
* 根路径
*/
private String basePath;
}

@Getter
@Setter
@ToString
public static class CloudResourceProperties {
/**
* endpoint
*/
private String endpoint;

/**
* ak
*/
private String accessKey;

/**
* sk
*/
private String secretKey;
}


@Getter
@Setter
@ToString(callSuper = true)
public static class AliYunOssProperties extends CloudResourceProperties {
/**
* 区域.
*/
private String region;

/**
* 是否启用sts,默认为false
*/
private boolean enableSts;

/**
* sts相关配置,获取webToken必须要有该值.
*/
private StsConfig sts;

/**
* stsConfig.
*/
@ToString
@Getter
@Setter
public static class StsConfig {

private String endpoint;

private String roleArn;

private Integer expire;

}
}
}
Loading

0 comments on commit dd27b5d

Please sign in to comment.