Skip to content

Commit

Permalink
Merge pull request #37 from JoshuaYin/master
Browse files Browse the repository at this point in the history
2.4.2
  • Loading branch information
joshua.yin authored Mar 20, 2020
2 parents fadd08a + e9a5239 commit fd3421c
Show file tree
Hide file tree
Showing 42 changed files with 270 additions and 197 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<dependency>
<groupId>cn.ucloud.ufile</groupId>
<artifactId>ufile-client-java</artifactId>
<version>2.4.1</version>
<version>2.4.2</version>
</dependency>
```

Expand All @@ -36,7 +36,7 @@
/*
* your other dependencies
*/
implementation 'cn.ucloud.ufile:ufile-client-java:2.4.1'
implementation 'cn.ucloud.ufile:ufile-client-java:2.4.2'
}
```

Expand Down
2 changes: 1 addition & 1 deletion ufile-sample-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dependency>
<groupId>cn.ucloud.ufile</groupId>
<artifactId>ufile-client-java</artifactId>
<version>2.4.1</version>
<version>2.4.2</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cn.ucloud.ufile.UfileClient;
import cn.ucloud.ufile.auth.*;
import cn.ucloud.ufile.http.HttpClient;
import cn.ucloud.ufile.http.interceptor.LogInterceptor;
import cn.ucloud.ufile.util.JLog;

import java.util.concurrent.Executors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import cn.ucloud.ufile.api.object.policy.PutPolicyForCallback;
import cn.ucloud.ufile.bean.MultiUploadResponse;
import cn.ucloud.ufile.bean.base.BaseObjectResponseBean;
import cn.ucloud.ufile.bean.base.BaseResponseBean;
import cn.ucloud.ufile.exception.UfileClientException;
import cn.ucloud.ufile.exception.UfileServerException;
import cn.ucloud.ufile.http.OnProgressListener;
Expand Down
2 changes: 1 addition & 1 deletion ufile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>cn.ucloud.ufile</groupId>
<artifactId>ufile</artifactId>
<packaging>pom</packaging>
<version>2.4.1</version>
<version>2.4.2</version>

<modules>
<module>ufile-core</module>
Expand Down
Binary file modified ufile/ufile-client-java/apidocs.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions ufile/ufile-client-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<parent>
<artifactId>ufile</artifactId>
<groupId>cn.ucloud.ufile</groupId>
<version>2.4.1</version>
<version>2.4.2</version>
</parent>

<artifactId>ufile-client-java</artifactId>
<version>2.4.1</version>
<version>2.4.2</version>

<dependencies>
<dependency>
Expand All @@ -26,7 +26,7 @@
<dependency>
<groupId>cn.ucloud.ufile</groupId>
<artifactId>ufile-core</artifactId>
<version>2.4.1</version>
<version>2.4.2</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ public synchronized static BucketApiBuilder bucket(BucketAuthorizer authorizer)
* @return Object相关API构造器 {@link ObjectApiBuilder}
*/
public synchronized static ObjectApiBuilder object(ObjectAuthorizer authorizer, ObjectConfig config) {
return new ObjectApiBuilder(createClient(), authorizer, config.host());
return new ObjectApiBuilder(createClient(), authorizer, config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public class AppendObjectApi extends UfileObjectApi<AppendObjectResultBean> {
/**
* 构造方法
*
* @param authorizer Object授权器
* @param host API域名
* @param httpClient Http客户端
* @param authorizer Object授权器
* @param objectConfig ObjectConfig {@link ObjectConfig}
* @param httpClient Http客户端
*/
protected AppendObjectApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
super(authorizer, host, httpClient);
protected AppendObjectApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
super(authorizer, objectConfig, httpClient);
progressConfig = ProgressConfig.callbackDefault();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public class CopyObjectApi extends UfileObjectApi<CopyObjectResultBean> {
/**
* 构造方法
*
* @param authorizer Object授权器
* @param host API域名
* @param httpClient Http客户端
* @param authorizer Object授权器
* @param objectConfig ObjectConfig {@link ObjectConfig}
* @param httpClient Http客户端
*/
protected CopyObjectApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
super(authorizer, host, httpClient);
protected CopyObjectApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
super(authorizer, objectConfig, httpClient);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public class DeleteObjectApi extends UfileObjectApi<BaseObjectResponseBean> {
/**
* 构造方法
*
* @param authorizer Object授权器
* @param host API域名
* @param httpClient Http客户端
* @param authorizer Object授权器
* @param objectConfig ObjectConfig {@link ObjectConfig}
* @param httpClient Http客户端
*/
protected DeleteObjectApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
super(authorizer, host, httpClient);
protected DeleteObjectApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
super(authorizer, objectConfig, httpClient);
RESP_CODE_SUCCESS = 204;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ public class DownloadFileApi extends UfileObjectApi<DownloadFileBean> {
/**
* 构造方法
*
* @param authorizer Object授权器
* @param host API域名
* @param httpClient Http客户端
* @param authorizer Object授权器
* @param objectConfig ObjectConfig {@link ObjectConfig}
* @param httpClient Http客户端
*/
protected DownloadFileApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
super(authorizer, host, httpClient);
protected DownloadFileApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
super(authorizer, objectConfig, httpClient);
RESP_CODE_SUCCESS = 206;
progressConfig = ProgressConfig.callbackDefault();
}
Expand Down Expand Up @@ -256,7 +256,7 @@ protected void prepareData() throws UfileClientException {
rangeEnd = profile.getContentLength() - 1;
totalSize = rangeEnd - rangeStart + 1;

host = new GenerateObjectPrivateUrlApi(authorizer, host, profile.getKeyName(), profile.getBucket(), expiresDuration)
host = new GenerateObjectPrivateUrlApi(authorizer, objectConfig, profile.getKeyName(), profile.getBucket(), expiresDuration)
.withAuthOptionalData(authOptionalData)
.createUrl();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public class GenerateObjectPrivateUrlApi {
private ObjectAuthorizer authorizer;
private String host;
private ObjectConfig objectConfig;

/**
* Required
Expand Down Expand Up @@ -57,21 +57,23 @@ public class GenerateObjectPrivateUrlApi {
* 构造方法
*
* @param authorizer Object授权器
* @param host API域名
* @param objectConfig ObjectConfig {@link ObjectConfig}
* @param keyName 对象名称
* @param bucketName bucket名称
* @param expiresDuration 私有下载路径的有效时间,即:生成的下载URL会在 创建时刻的时间戳 + expiresDuration毫秒 后的时刻过期
*/
protected GenerateObjectPrivateUrlApi(ObjectAuthorizer authorizer, String host, String keyName, String bucketName, int expiresDuration) {
protected GenerateObjectPrivateUrlApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig,
String keyName, String bucketName, int expiresDuration) {
this.authorizer = authorizer;
this.host = host;
this.objectConfig = objectConfig;
this.keyName = keyName;
this.bucketName = bucketName;
this.expiresDuration = expiresDuration;
}

/**
* 使用Content-Disposition: attachment,并配置attachment的文件名
*
* @param attachmentFileName Content-Disposition: attachment的文件名
* @return
*/
Expand All @@ -82,6 +84,7 @@ public GenerateObjectPrivateUrlApi withAttachment(String attachmentFileName) {

/**
* 使用Content-Disposition: attachment,并且文件名默认为keyName
*
* @return
*/
public GenerateObjectPrivateUrlApi withAttachment() {
Expand Down Expand Up @@ -169,18 +172,23 @@ public void run() {
}

private String generateFinalHost(String bucketName, String keyName) throws UfileClientException {
if (host == null || host.length() == 0)
return host;
if (objectConfig == null)
return null;

if (host.startsWith("http"))
return String.format("%s/%s", host, keyName);
if (objectConfig.isCustomDomain())
return String.format("%s/%s", objectConfig.getCustomHost(), keyName);

try {
bucketName = URLEncoder.encode(bucketName, "UTF-8").replace("+", "%20");
String region = URLEncoder.encode(objectConfig.getRegion(), "UTF-8")
.replace("+", "%20");
String proxySuffix = URLEncoder.encode(objectConfig.getProxySuffix(), "UTF-8")
.replace("+", "%20");
keyName = URLEncoder.encode(keyName, "UTF-8").replace("+", "%20");
return String.format("http://%s.%s/%s", bucketName, host, keyName);
return new StringBuilder(objectConfig.getProtocol().getValue())
.append(String.format("%s.%s.%s/%s", bucketName, region, proxySuffix, keyName)).toString();
} catch (UnsupportedEncodingException e) {
throw new UfileClientException("Occur error during URLEncode bucketName and keyName");
throw new UfileClientException("Occur error during URLEncode bucketName and keyName", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @date: 2018/11/16 12:00
*/
public class GenerateObjectPublicUrlApi {
private String host;
private ObjectConfig objectConfig;
/**
* Required
* 云端对象名称
Expand All @@ -37,18 +37,19 @@ public class GenerateObjectPublicUrlApi {
/**
* 构造方法
*
* @param host API域名
* @param keyName 对象名称
* @param bucketName bucket名称
* @param objectConfig ObjectConfig {@link ObjectConfig}
* @param keyName 对象名称
* @param bucketName bucket名称
*/
protected GenerateObjectPublicUrlApi(String host, String keyName, String bucketName) {
this.host = host;
protected GenerateObjectPublicUrlApi(ObjectConfig objectConfig, String keyName, String bucketName) {
this.objectConfig = objectConfig;
this.keyName = keyName;
this.bucketName = bucketName;
}

/**
* 使用Content-Disposition: attachment,并配置attachment的文件名
*
* @param attachmentFileName Content-Disposition: attachment的文件名
* @return
*/
Expand All @@ -59,6 +60,7 @@ public GenerateObjectPublicUrlApi withAttachment(String attachmentFileName) {

/**
* 使用Content-Disposition: attachment,并且文件名默认为keyName
*
* @return
*/
public GenerateObjectPublicUrlApi withAttachment() {
Expand Down Expand Up @@ -90,18 +92,23 @@ public String createUrl() throws UfileClientException {
}

private String generateFinalHost(String bucketName, String keyName) throws UfileClientException {
if (host == null || host.length() == 0)
return host;
if (objectConfig == null)
return null;

if (host.startsWith("http"))
return String.format("%s/%s", host, keyName);
if (objectConfig.isCustomDomain())
return String.format("%s/%s", objectConfig.getCustomHost(), keyName);

try {
bucketName = URLEncoder.encode(bucketName, "UTF-8").replace("+","%20");
keyName = URLEncoder.encode(keyName, "UTF-8").replace("+","%20");
return String.format("http://%s.%s/%s", bucketName, host, keyName);
bucketName = URLEncoder.encode(bucketName, "UTF-8").replace("+", "%20");
String region = URLEncoder.encode(objectConfig.getRegion(), "UTF-8")
.replace("+", "%20");
String proxySuffix = URLEncoder.encode(objectConfig.getProxySuffix(), "UTF-8")
.replace("+", "%20");
keyName = URLEncoder.encode(keyName, "UTF-8").replace("+", "%20");
return new StringBuilder(objectConfig.getProtocol().getValue())
.append(String.format("%s.%s.%s/%s", bucketName, region, proxySuffix, keyName)).toString();
} catch (UnsupportedEncodingException e) {
throw new UfileClientException("Occur error during URLEncode bucketName and keyName");
throw new UfileClientException("Occur error during URLEncode bucketName and keyName", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ public class GetFileApi extends UfileObjectApi<DownloadFileBean> {
/**
* 构造方法
*
* @param authorizer Object授权器
* @param host API域名
* @param httpClient Http客户端
* @param authorizer Object授权器
* @param objectConfig ObjectConfig {@link ObjectConfig}
* @param httpClient Http客户端
*/
protected GetFileApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
super(authorizer, host, httpClient);
protected GetFileApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
super(authorizer, objectConfig, httpClient);
RESP_CODE_SUCCESS = 206;
host = objectConfig.getCustomHost();
progressConfig = ProgressConfig.callbackDefault();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ public class GetStreamApi extends UfileObjectApi<DownloadStreamBean> {
/**
* 构造方法
*
* @param authorizer Object授权器
* @param host API域名
* @param httpClient Http客户端
* @param authorizer Object授权器
* @param objectConfig ObjectConfig {@link ObjectConfig}
* @param httpClient Http客户端
*/
protected GetStreamApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
super(authorizer, host, httpClient);
protected GetStreamApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
super(authorizer, objectConfig, httpClient);
RESP_CODE_SUCCESS = 206;
host = objectConfig.getCustomHost();
progressConfig = ProgressConfig.callbackDefault();
}

Expand Down
Loading

0 comments on commit fd3421c

Please sign in to comment.