Skip to content

Commit

Permalink
Merge branch 'master' of YangSen-qn:qiniu/java-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn committed May 15, 2024
2 parents ddb92a8 + 8d3cc04 commit 1d09325
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 63 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/version-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Java SDK Version Check
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
jobs:
linux:
name: Version Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV
- name: Check
run: |
set -e
grep -qF "## ${RELEASE_VERSION}" CHANGELOG.md
grep -qF "public static final String VERSION = \"${RELEASE_VERSION}\";" src/main/java/com/qiniu/common/Constants.java
2 changes: 1 addition & 1 deletion src/main/java/com/qiniu/storage/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public String getPath() throws QiniuException {
* @throws QiniuException 组装 query 时的异常,一般为缺失必要参数的异常
*/
protected void buildPath() throws QiniuException {
path = "/" + StringUtils.join(pathSegments, "/");
path = StringUtils.join(pathSegments, "");
}


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/qiniu/storage/ApiQueryRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ protected void buildQuery() throws QiniuException {

@Override
protected void buildPath() throws QiniuException {
addPathSegment("v4");
addPathSegment("query");
addPathSegment("/v4");
addPathSegment("/query");
super.buildPath();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/qiniu/storage/ApiUploadV1MakeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ protected void buildPath() throws QiniuException {
ApiUtils.throwInvalidRequestParamException("block size");
}

addPathSegment("mkblk");
addPathSegment(blockSize + "");
addPathSegment("/mkblk");
addPathSegment("/" + blockSize);
super.buildPath();
}

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/qiniu/storage/ApiUploadV1MakeFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,35 +171,35 @@ protected void buildPath() throws QiniuException {
ApiUtils.throwInvalidRequestParamException("file size");
}

addPathSegment("mkfile");
addPathSegment(fileSize + "");
addPathSegment("/mkfile");
addPathSegment("/" + fileSize);

if (!StringUtils.isNullOrEmpty(fileMimeType)) {
addPathSegment("mimeType");
addPathSegment(UrlSafeBase64.encodeToString(fileMimeType));
addPathSegment("/mimeType");
addPathSegment("/" + UrlSafeBase64.encodeToString(fileMimeType));
}

if (!StringUtils.isNullOrEmpty(fileName)) {
addPathSegment("fname");
addPathSegment(UrlSafeBase64.encodeToString(fileName));
addPathSegment("/fname");
addPathSegment("/" + UrlSafeBase64.encodeToString(fileName));
}

if (key != null) {
addPathSegment("key");
addPathSegment(UrlSafeBase64.encodeToString(key));
addPathSegment("/key");
addPathSegment("/" + UrlSafeBase64.encodeToString(key));
}

if (params != null && !params.isEmpty()) {
for (String key : params.keySet()) {
addPathSegment(key);
addPathSegment(UrlSafeBase64.encodeToString("" + params.get(key)));
addPathSegment("/" + key);
addPathSegment("/" + UrlSafeBase64.encodeToString("" + params.get(key)));
}
}

if (metaDataParam != null && !metaDataParam.isEmpty()) {
for (String key : metaDataParam.keySet()) {
addPathSegment(key);
addPathSegment(UrlSafeBase64.encodeToString("" + metaDataParam.get(key)));
addPathSegment("/" + key);
addPathSegment("/" + UrlSafeBase64.encodeToString("" + metaDataParam.get(key)));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/qiniu/storage/ApiUploadV1PutChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ protected void buildPath() throws QiniuException {
ApiUtils.throwInvalidRequestParamException("block last context");
}

addPathSegment("bput");
addPathSegment(blockLastContext);
addPathSegment(chunkOffset + "");
addPathSegment("/bput");
addPathSegment("/" + blockLastContext);
addPathSegment("/" + chunkOffset);
super.buildPath();
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/qiniu/storage/ApiUploadV2AbortUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ protected void buildPath() throws QiniuException {
}

String bucket = token.getBucket();
addPathSegment("buckets");
addPathSegment(bucket);
addPathSegment("objects");
addPathSegment(ApiUtils.resumeV2EncodeKey(key));
addPathSegment("uploads");
addPathSegment(uploadId);
addPathSegment("/buckets");
addPathSegment("/" + bucket);
addPathSegment("/objects");
addPathSegment("/" + ApiUtils.resumeV2EncodeKey(key));
addPathSegment("/uploads");
addPathSegment("/" + uploadId);
super.buildPath();
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/qiniu/storage/ApiUploadV2CompleteUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ protected void buildPath() throws QiniuException {
}

String bucket = token.getBucket();
addPathSegment("buckets");
addPathSegment(bucket);
addPathSegment("objects");
addPathSegment(ApiUtils.resumeV2EncodeKey(key));
addPathSegment("uploads");
addPathSegment(uploadId);
addPathSegment("/buckets");
addPathSegment("/" + bucket);
addPathSegment("/objects");
addPathSegment("/" + ApiUtils.resumeV2EncodeKey(key));
addPathSegment("/uploads");
addPathSegment("/" + uploadId);
super.buildPath();
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/qiniu/storage/ApiUploadV2InitUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ protected void buildPath() throws QiniuException {
}

String bucket = getUploadToken().getBucket();
addPathSegment("buckets");
addPathSegment(bucket);
addPathSegment("objects");
addPathSegment(ApiUtils.resumeV2EncodeKey(key));
addPathSegment("uploads");
addPathSegment("/buckets");
addPathSegment("/" + bucket);
addPathSegment("/objects");
addPathSegment("/" + ApiUtils.resumeV2EncodeKey(key));
addPathSegment("/uploads");
super.buildPath();
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/qiniu/storage/ApiUploadV2ListParts.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ protected void buildPath() throws QiniuException {
}

String bucket = token.getBucket();
addPathSegment("buckets");
addPathSegment(bucket);
addPathSegment("objects");
addPathSegment(ApiUtils.resumeV2EncodeKey(key));
addPathSegment("uploads");
addPathSegment(uploadId);
addPathSegment("/buckets");
addPathSegment("/" + bucket);
addPathSegment("/objects");
addPathSegment("/" + ApiUtils.resumeV2EncodeKey(key));
addPathSegment("/uploads");
addPathSegment("/" + uploadId);
super.buildPath();
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/qiniu/storage/ApiUploadV2UploadPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ protected void buildPath() throws QiniuException {
}

String bucket = getUploadToken().getBucket();
addPathSegment("buckets");
addPathSegment(bucket);
addPathSegment("objects");
addPathSegment(ApiUtils.resumeV2EncodeKey(key));
addPathSegment("uploads");
addPathSegment(uploadId);
addPathSegment(partNumber + "");
addPathSegment("/buckets");
addPathSegment("/" + bucket);
addPathSegment("/objects");
addPathSegment("/" + ApiUtils.resumeV2EncodeKey(key));
addPathSegment("/uploads");
addPathSegment("/" + uploadId);
addPathSegment("/" + partNumber);
super.buildPath();
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/qiniu/storage/DownloadPrivateCloudUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ protected void willBuildUrl() throws QiniuException {

@Override
protected void willSetKeyForUrl(Api.Request request) throws QiniuException {
request.addPathSegment("getfile");
request.addPathSegment(accessKey);
request.addPathSegment(bucketName);
request.addPathSegment("/getfile");
request.addPathSegment("/" + accessKey);
request.addPathSegment("/" + bucketName);
super.willSetKeyForUrl(request);
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/qiniu/storage/DownloadUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public DownloadUrl setFop(String fop) {
* 配置 style【可选】
* 如果觉得 fop 这样的形式够冗长,还可以为这些串行的 fop 集合定义一个友好别名。如此一来,就可以用友好URL风格进行访问,这个别名就是 style 。
* eg:
* 对 userBucket 的 fop(imageView2/2/w/320/h/480) 使用 style 的方式, 分隔符为 "-"
* 使用 qrsctl 命令定义 style: (qrsctl separator [bucket] [styleSeparator])
* qrsctl separator userBucket -
* 定义数据处理的别名为 aliasName: (qrsctl style [bucket] [aliasName] [fop])
* qrsctl style userBucket iphone imageView2/2/w/320/h/480
* 对 userBucket 的 fop(imageView2/2/w/320/h/480) 使用 style 的方式, 分隔符为 "-"
* 使用 qrsctl 命令定义 style: (qrsctl separator [bucket] [styleSeparator])
* qrsctl separator userBucket -
* 定义数据处理的别名为 aliasName: (qrsctl style [bucket] [aliasName] [fop])
* qrsctl style userBucket iphone imageView2/2/w/320/h/480
* <p>
* <a href="https://developer.qiniu.com/dora/6217/directions-for-use-pfop"> 相关链接 </a>
*
Expand Down Expand Up @@ -159,7 +159,7 @@ public String buildURL() throws QiniuException {
}
}
if (!StringUtils.isNullOrEmpty(keyAndStyle)) {
request.addPathSegment(keyAndStyle);
request.addPathSegment("/" + keyAndStyle);
}
didSetKeyForUrl(request);

Expand Down
11 changes: 7 additions & 4 deletions src/test/java/test/com/qiniu/storage/DownloadUrlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import test.com.qiniu.TestConfig;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -80,8 +80,11 @@ public void testSpecialKey() {
String encodeKey = keys.get(key);
try {
String url = new DownloadUrl(domain, false, key).buildURL();
String exceptUrl = "http://" + domain + "/" + encodeKey;
assertEquals(exceptUrl, url, "url:" + url + " exceptUrl:" + exceptUrl);
String exceptUrl = "http://" + domain;
if (!key.isEmpty()) {
exceptUrl += "/" + encodeKey;
}
assertEquals(exceptUrl, url, "key:" + key);
} catch (QiniuException e) {
fail(e.error());
}
Expand Down

0 comments on commit 1d09325

Please sign in to comment.