Skip to content

Commit

Permalink
Merge pull request #26 from lunasaw/3.1.9-SNAPSHOT
Browse files Browse the repository at this point in the history
3.1.9 snapshot
  • Loading branch information
lunasaw committed Apr 22, 2023
2 parents 4aea608 + aec1b48 commit 09fef27
Show file tree
Hide file tree
Showing 46 changed files with 218 additions and 200 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ luna-fans-api-fans 基于各个开放平台的api整合优化,大部分采用

[![Maven Central](https://img.shields.io/maven-central/v/io.github.lunasaw/luna-fans-api)](https://mvnrepository.com/artifact/io.github.lunasaw/luna-fans-api)
[![GitHub license](https://img.shields.io/badge/MIT_License-blue.svg)](https://raw.githubusercontent.com/lunasaw/luna-fans-api/master/LICENSE)
[![Build Status](https://github.com/lunasaw/luna-fans-api/actions/workflows/maven-publish.yml/badge.svg?branch=master)](https://github.com/lunasaw/luna-fans-api/actions)
[![Build Status](https://github.com/lunasaw/luna-fans-api/actions/workflows/publish-javadoc.yml/badge.svg?branch=master)](https://github.com/lunasaw/luna-fans-api/actions)

<!-- PROJECT LOGO -->
<br />
Expand All @@ -29,6 +29,7 @@ luna-fans-api-fans 基于各个开放平台的api整合优化,大部分采用

## 日志

- 2023.0422 升级httpClient5.2 支持更优秀的异步请求方式
- 2023.0414 自助github action Java doc打包📦部署
- 2023.04.09 升级SpringBoot 2.7.10, 精简maven, 拆分Tencent的微信支付模块,和aliPay的支付模块,新增支付测试controller
- 2022.10.03 增加阿里Oss平台,升级SpringBoot 2.7.0
Expand Down
2 changes: 1 addition & 1 deletion ali-pay-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.lunasaw</groupId>
<artifactId>luna-fans-api</artifactId>
<version>3.1.8</version>
<version>3.1.9</version>
</parent>

<artifactId>ali-pay-spring-boot-starter</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ali-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>luna-fans-api</artifactId>
<groupId>io.github.lunasaw</groupId>
<version>3.1.8</version>
<version>3.1.9</version>
</parent>
<artifactId>ali-spring-boot-starter</artifactId>
<version>${luna-fans-api.version}</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ public class AliConfigProperties {
*/
private Boolean enableCname;

/**
* 连接超时时间
*/
public Integer connectTimeout;

/**
* 最大连接数
*/
public Integer maxIdleConns;

/**
* 读取超时时间
*/
public Integer readTimeout;
/**
* 创建OSSClient实例
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,4 @@ public class AliOssAutoConfiguration {
public AliOssAutoConfiguration(final AliConfigProperties aliConfigProperties) {
this.aliConfigProperties = aliConfigProperties;
}

@Bean
@ConditionalOnMissingBean
public AliOssUploadApi aliOssUploadApi() {
return new AliOssUploadApi(aliConfigProperties.getInstanceClient());
}

@Bean
@ConditionalOnMissingBean
public AliOssDownloadApi aliOssDownloadApi() {
return new AliOssDownloadApi(aliConfigProperties.getInstanceClient());
}

@Bean
@ConditionalOnMissingBean
public AliOssBucketApi aliOssBucketApi() {
return new AliOssBucketApi(aliConfigProperties.getInstanceClient());
}

@Bean
@ConditionalOnMissingBean
public AliOssUploadGoOnApi aliOssUploadGoOnApi() {
return new AliOssUploadGoOnApi(aliConfigProperties.getInstanceClient());
}

@Bean
@ConditionalOnMissingBean
public AliOssWebApi aliOssWebApi() {
return new AliOssWebApi(aliConfigProperties.getInstanceClient());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class AliFaceBodyClientSupport implements InitializingBean {

private RuntimeOptions runtimeOptions;


public com.aliyun.teaopenapi.Client getClient(FaceTypeEnum faceType) {
if (FaceTypeEnum.FACE_DETECTION.equals(faceType)) {
return faceClient.getFaceBodyClient();
Expand Down Expand Up @@ -63,6 +62,9 @@ public void createClient(String accessKeyId, String accessKeySecret) {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret)
.setConnectTimeout(aliConfigProperties.getConnectTimeout())
.setMaxIdleConns(aliConfigProperties.getMaxIdleConns())
.setReadTimeout(aliConfigProperties.getReadTimeout())
.setEndpoint(AliAccessConstant.FACE_BODY_HOST);
faceClient = new FaceClient();
faceClient.setFaceCheckClient(new com.aliyun.facebody20191230.Client(config));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.luna.ali.oss;

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.luna.ali.config.AliConfigProperties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
* @author weidian
* @description
* @date 2023/4/16
*/
@Component
public class AliOssClientSupport implements InitializingBean {

@Autowired
private AliConfigProperties aliConfigProperties;

/**
* 创建OSSClient实例
*/
private OSS client;

public OSS getInstanceClient() {
synchronized (AliOssClientSupport.class){
if (aliConfigProperties.getEnableCname() && StringUtils.isNotEmpty(aliConfigProperties.getDomain())) {
ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
// 设置是否支持CNAME。CNAME是指将自定义域名绑定到存储空间上。
conf.setSupportCname(true);
return new OSSClientBuilder().build(aliConfigProperties.getDomain(), aliConfigProperties.getAccessKey(),
aliConfigProperties.getSecretKey(), conf);
}
if (client == null) {
this.client = new OSSClientBuilder().build(aliConfigProperties.getEndpoint(), aliConfigProperties.getAccessKey(),
aliConfigProperties.getSecretKey());
}
}
return client;
}

@Override
public void afterPropertiesSet() {
client = getInstanceClient();
}

@PreDestroy
public void destroy() {
this.client.shutdown();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.luna.ali.oss;
package com.luna.ali.oss.api;

import java.util.Date;
import java.util.Iterator;
Expand All @@ -7,24 +7,25 @@

import com.aliyun.oss.OSS;
import com.aliyun.oss.model.*;
import com.luna.ali.oss.AliOssClientSupport;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
* @author Luna@win10
* @date 2020/4/20 11:46
*/
@Component
@Slf4j
public class AliOssBucketApi {

private OSS ossClient;

public AliOssBucketApi(OSS ossClient) {
this.ossClient = ossClient;
}

private static final Logger log = LoggerFactory.getLogger(AliOssBucketApi.class);
@Autowired
private AliOssClientSupport aliOssClientSupport;

/**
* 创建对象存储空间
Expand Down Expand Up @@ -53,10 +54,7 @@ public void createBucket(String bucketName, String access, String type) {
createBucketRequest.setStorageClass(StorageClass.parse(type));

// 创建存储空间。
ossClient.createBucket(createBucketRequest);

// 关闭OSSClient。
ossClient.shutdown();
aliOssClientSupport.getInstanceClient().createBucket(createBucketRequest);
}

/**
Expand All @@ -79,11 +77,11 @@ public List<Bucket> listBuckets(String prefix, Integer maxKeys, String marker) {
if (StringUtils.isNotEmpty(marker)) {
listBucketsRequest.setMarker(marker);
}
BucketList bucketList = ossClient.listBuckets(listBucketsRequest);
BucketList bucketList = aliOssClientSupport.getInstanceClient().listBuckets(listBucketsRequest);
List<Bucket> buckets = bucketList.getBucketList();

// 关闭OSSClient
ossClient.shutdown();
// 关闭aliOssClientSupport.getInstanceClient()
aliOssClientSupport.getInstanceClient().shutdown();
return buckets;
}

Expand All @@ -96,11 +94,10 @@ public List<Bucket> listBuckets(String prefix, Integer maxKeys, String marker) {
public boolean isBucket(String bucketName) {
Assert.notNull(bucketName, "存储空间名称不能为空");

boolean exists = aliOssClientSupport.getInstanceClient().doesBucketExist(bucketName);

boolean exists = ossClient.doesBucketExist(bucketName);

// 关闭OSSClient。
ossClient.shutdown();
// 关闭aliOssClientSupport.getInstanceClient()。
aliOssClientSupport.getInstanceClient().shutdown();
return exists;
}

Expand All @@ -113,10 +110,10 @@ public boolean isBucket(String bucketName) {
public String getBucketRegion(String bucketName) {
Assert.notNull(bucketName, "存储空间名称不能为空");

String location = ossClient.getBucketLocation(bucketName);
String location = aliOssClientSupport.getInstanceClient().getBucketLocation(bucketName);

// 关闭OSSClient
ossClient.shutdown();
// 关闭aliOssClientSupport.getInstanceClient()
aliOssClientSupport.getInstanceClient().shutdown();
return location;
}

Expand All @@ -130,7 +127,7 @@ public BucketInfo getBucketInfo(String bucketName) {
Assert.notNull(bucketName, "存储空间名称不能为空");

// 存储空间的信息包括地域(Region或Location)、创建日期(CreationDate)、拥有者(Owner)、权限(Grants)等。
BucketInfo info = ossClient.getBucketInfo(bucketName);
BucketInfo info = aliOssClientSupport.getInstanceClient().getBucketInfo(bucketName);
// 获取地域。
String location = info.getBucket().getLocation();
// 获取创建日期。
Expand All @@ -140,8 +137,8 @@ public BucketInfo getBucketInfo(String bucketName) {
// 获取容灾类型。
DataRedundancyType dataRedundancyType = info.getDataRedundancyType();

// 关闭OSSClient
ossClient.shutdown();
// 关闭aliOssClientSupport.getInstanceClient()
aliOssClientSupport.getInstanceClient().shutdown();
return info;
}

Expand All @@ -158,10 +155,10 @@ public void setBucketAccess(String bucketName, String access) {
Assert.notNull(access, "权限名称不能为空");

// 设置存储空间的访问权限为私有。
ossClient.setBucketAcl(bucketName, CannedAccessControlList.parse(access));
aliOssClientSupport.getInstanceClient().setBucketAcl(bucketName, CannedAccessControlList.parse(access));

// 关闭OSSClient
ossClient.shutdown();
// 关闭aliOssClientSupport.getInstanceClient()
aliOssClientSupport.getInstanceClient().shutdown();
}

/**
Expand All @@ -174,10 +171,10 @@ public String getBucketAccess(String bucketName) {
Assert.notNull(bucketName, "存储空间名称不能为空");

// 获取存储空间的访问权限。
AccessControlList acl = ossClient.getBucketAcl(bucketName);
AccessControlList acl = aliOssClientSupport.getInstanceClient().getBucketAcl(bucketName);

// 关闭OSSClient
ossClient.shutdown();
// 关闭aliOssClientSupport.getInstanceClient()
aliOssClientSupport.getInstanceClient().shutdown();
return acl.toString();
}

Expand All @@ -190,10 +187,10 @@ public void deleteBucket(String bucketName) {
Assert.notNull(bucketName, "存储空间名称不能为空");

// 删除存储空间。
ossClient.deleteBucket(bucketName);
aliOssClientSupport.getInstanceClient().deleteBucket(bucketName);

// 关闭OSSClient
ossClient.shutdown();
// 关闭aliOssClientSupport.getInstanceClient()
aliOssClientSupport.getInstanceClient().shutdown();
}

/**
Expand All @@ -213,10 +210,10 @@ public void setBucketTag(Map<String, String> tags, String bucketName) {
Map.Entry<String, String> entry = entries.next();
request.setTag(entry.getKey(), entry.getValue());
}
ossClient.setBucketTagging(request);
aliOssClientSupport.getInstanceClient().setBucketTagging(request);

// 关闭OSSClient
ossClient.shutdown();
// 关闭aliOssClientSupport.getInstanceClient()
aliOssClientSupport.getInstanceClient().shutdown();
}

/**
Expand All @@ -229,11 +226,11 @@ public Map<String, String> getBucketTags(String bucketName) {
Assert.notNull(bucketName, "存储空间名称不能为空");

// 获取Bucket标签信息。
TagSet tagSet = ossClient.getBucketTagging(new GenericRequest(bucketName));
TagSet tagSet = aliOssClientSupport.getInstanceClient().getBucketTagging(new GenericRequest(bucketName));
Map<String, String> tags = tagSet.getAllTags();

// 关闭OSSClient
ossClient.shutdown();
// 关闭aliOssClientSupport.getInstanceClient()
aliOssClientSupport.getInstanceClient().shutdown();
return tags;
}
}

0 comments on commit 09fef27

Please sign in to comment.