From ddb92a8a33a0c6c444b5323421bca056a5d0258b Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Wed, 15 May 2024 15:57:39 +0800 Subject: [PATCH 01/10] fix: download key has prefix / --- src/main/java/com/qiniu/storage/Api.java | 5 +---- src/main/java/com/qiniu/storage/ApiUploadV1MakeFile.java | 4 ++-- src/test/java/test/com/qiniu/storage/DownloadUrlTest.java | 3 +++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/qiniu/storage/Api.java b/src/main/java/com/qiniu/storage/Api.java index b43efaf6..ccf3e054 100644 --- a/src/main/java/com/qiniu/storage/Api.java +++ b/src/main/java/com/qiniu/storage/Api.java @@ -506,10 +506,7 @@ public String getPath() throws QiniuException { * @throws QiniuException 组装 query 时的异常,一般为缺失必要参数的异常 */ protected void buildPath() throws QiniuException { - path = StringUtils.join(pathSegments, "/"); - if (!path.startsWith("/")) { - path = "/" + path; - } + path = "/" + StringUtils.join(pathSegments, "/"); } diff --git a/src/main/java/com/qiniu/storage/ApiUploadV1MakeFile.java b/src/main/java/com/qiniu/storage/ApiUploadV1MakeFile.java index 5f152590..6e04cc56 100644 --- a/src/main/java/com/qiniu/storage/ApiUploadV1MakeFile.java +++ b/src/main/java/com/qiniu/storage/ApiUploadV1MakeFile.java @@ -189,14 +189,14 @@ protected void buildPath() throws QiniuException { addPathSegment(UrlSafeBase64.encodeToString(key)); } - if (params != null && params.size() > 0) { + if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { addPathSegment(key); addPathSegment(UrlSafeBase64.encodeToString("" + params.get(key))); } } - if (metaDataParam != null && metaDataParam.size() > 0) { + if (metaDataParam != null && !metaDataParam.isEmpty()) { for (String key : metaDataParam.keySet()) { addPathSegment(key); addPathSegment(UrlSafeBase64.encodeToString("" + metaDataParam.get(key))); diff --git a/src/test/java/test/com/qiniu/storage/DownloadUrlTest.java b/src/test/java/test/com/qiniu/storage/DownloadUrlTest.java index 5afac57e..d5ae64fa 100644 --- a/src/test/java/test/com/qiniu/storage/DownloadUrlTest.java +++ b/src/test/java/test/com/qiniu/storage/DownloadUrlTest.java @@ -16,6 +16,8 @@ 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; @@ -59,6 +61,7 @@ public void testSpecialKey() { { put("", ""); put("abc_def.mp4", "abc_def.mp4"); + put("/ab/cd", "/ab/cd"); put("ab/cd", "ab/cd"); put("ab/中文/de", "ab/%E4%B8%AD%E6%96%87/de"); put("ab+-*de f", "ab%2B-%2Ade%20f"); From a838948b85674f07232a3be82fc64e7adc610a40 Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Mon, 27 May 2024 15:16:28 +0800 Subject: [PATCH 02/10] version to 7.15.1 --- CHANGELOG.md | 3 +++ src/main/java/com/qiniu/common/Constants.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70086595..1398314a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## 7.15.1(2024-05-29) +* 处理在构造 Download URL 时 Key 前缀为 / 的情况 + ## 7.15.0(2023-12-25) * 区域缓存支持磁盘缓存 * 提供快速生成公有云的区域实例的方法 diff --git a/src/main/java/com/qiniu/common/Constants.java b/src/main/java/com/qiniu/common/Constants.java index 3441e977..260c9a02 100644 --- a/src/main/java/com/qiniu/common/Constants.java +++ b/src/main/java/com/qiniu/common/Constants.java @@ -10,7 +10,7 @@ public final class Constants { /** * 版本号 */ - public static final String VERSION = "7.15.0"; + public static final String VERSION = "7.15.1"; /** * 块大小,不能改变 */ From c087705311eeeee88ea0cab53dddcb167a017e56 Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Wed, 29 May 2024 12:12:28 +0800 Subject: [PATCH 03/10] change path add segment --- src/main/java/com/qiniu/storage/Api.java | 13 ++++++++-- .../com/qiniu/storage/ApiQueryRegion.java | 4 ++-- .../qiniu/storage/ApiUploadV1MakeBlock.java | 4 ++-- .../qiniu/storage/ApiUploadV1MakeFile.java | 24 +++++++++---------- .../qiniu/storage/ApiUploadV1PutChunk.java | 6 ++--- .../qiniu/storage/ApiUploadV2AbortUpload.java | 12 +++++----- .../storage/ApiUploadV2CompleteUpload.java | 12 +++++----- .../qiniu/storage/ApiUploadV2InitUpload.java | 10 ++++---- .../qiniu/storage/ApiUploadV2ListParts.java | 12 +++++----- .../qiniu/storage/ApiUploadV2UploadPart.java | 14 +++++------ .../storage/DownloadPrivateCloudUrl.java | 6 ++--- .../java/com/qiniu/storage/DownloadUrl.java | 2 +- 12 files changed, 64 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/qiniu/storage/Api.java b/src/main/java/com/qiniu/storage/Api.java index 3405978c..35280fda 100644 --- a/src/main/java/com/qiniu/storage/Api.java +++ b/src/main/java/com/qiniu/storage/Api.java @@ -403,7 +403,13 @@ protected Request(String urlPrefix) { this.scheme = url.getProtocol(); this.host = url.getHost(); this.port = url.getPort(); - this.addPathSegment(url.getPath()); + + // segment 不包含左边的 /, 截掉左边第一个 / + String segment = url.getPath(); + if (segment != null && segment.startsWith("/")) { + segment = segment.substring(1); + } + this.addPathSegment(segment); String query = url.getQuery(); if (StringUtils.isNullOrEmpty(query)) { @@ -506,7 +512,10 @@ public String getPath() throws QiniuException { * @throws QiniuException 组装 query 时的异常,一般为缺失必要参数的异常 */ protected void buildPath() throws QiniuException { - path = StringUtils.join(pathSegments, ""); + path = StringUtils.join(pathSegments, "/"); + if (!path.isEmpty()) { + path = "/" + path; + } } diff --git a/src/main/java/com/qiniu/storage/ApiQueryRegion.java b/src/main/java/com/qiniu/storage/ApiQueryRegion.java index 80ce55ee..c0d52826 100644 --- a/src/main/java/com/qiniu/storage/ApiQueryRegion.java +++ b/src/main/java/com/qiniu/storage/ApiQueryRegion.java @@ -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(); } } diff --git a/src/main/java/com/qiniu/storage/ApiUploadV1MakeBlock.java b/src/main/java/com/qiniu/storage/ApiUploadV1MakeBlock.java index 9de2df6d..ec80dbc0 100644 --- a/src/main/java/com/qiniu/storage/ApiUploadV1MakeBlock.java +++ b/src/main/java/com/qiniu/storage/ApiUploadV1MakeBlock.java @@ -135,8 +135,8 @@ protected void buildPath() throws QiniuException { ApiUtils.throwInvalidRequestParamException("block size"); } - addPathSegment("/mkblk"); - addPathSegment("/" + blockSize); + addPathSegment("mkblk"); + addPathSegment("" + blockSize); super.buildPath(); } diff --git a/src/main/java/com/qiniu/storage/ApiUploadV1MakeFile.java b/src/main/java/com/qiniu/storage/ApiUploadV1MakeFile.java index 212ac751..8f4650e1 100644 --- a/src/main/java/com/qiniu/storage/ApiUploadV1MakeFile.java +++ b/src/main/java/com/qiniu/storage/ApiUploadV1MakeFile.java @@ -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))); } } diff --git a/src/main/java/com/qiniu/storage/ApiUploadV1PutChunk.java b/src/main/java/com/qiniu/storage/ApiUploadV1PutChunk.java index 386cd2ce..699c8b60 100644 --- a/src/main/java/com/qiniu/storage/ApiUploadV1PutChunk.java +++ b/src/main/java/com/qiniu/storage/ApiUploadV1PutChunk.java @@ -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(); } diff --git a/src/main/java/com/qiniu/storage/ApiUploadV2AbortUpload.java b/src/main/java/com/qiniu/storage/ApiUploadV2AbortUpload.java index acbf40bc..845def72 100644 --- a/src/main/java/com/qiniu/storage/ApiUploadV2AbortUpload.java +++ b/src/main/java/com/qiniu/storage/ApiUploadV2AbortUpload.java @@ -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(); } } diff --git a/src/main/java/com/qiniu/storage/ApiUploadV2CompleteUpload.java b/src/main/java/com/qiniu/storage/ApiUploadV2CompleteUpload.java index f451ed73..9cfde854 100644 --- a/src/main/java/com/qiniu/storage/ApiUploadV2CompleteUpload.java +++ b/src/main/java/com/qiniu/storage/ApiUploadV2CompleteUpload.java @@ -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(); } diff --git a/src/main/java/com/qiniu/storage/ApiUploadV2InitUpload.java b/src/main/java/com/qiniu/storage/ApiUploadV2InitUpload.java index 3df2d638..07cd7a74 100644 --- a/src/main/java/com/qiniu/storage/ApiUploadV2InitUpload.java +++ b/src/main/java/com/qiniu/storage/ApiUploadV2InitUpload.java @@ -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(); } } diff --git a/src/main/java/com/qiniu/storage/ApiUploadV2ListParts.java b/src/main/java/com/qiniu/storage/ApiUploadV2ListParts.java index 2687c6c1..2c376b62 100644 --- a/src/main/java/com/qiniu/storage/ApiUploadV2ListParts.java +++ b/src/main/java/com/qiniu/storage/ApiUploadV2ListParts.java @@ -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(); } } diff --git a/src/main/java/com/qiniu/storage/ApiUploadV2UploadPart.java b/src/main/java/com/qiniu/storage/ApiUploadV2UploadPart.java index fd5cdbf3..1fcbf5ee 100644 --- a/src/main/java/com/qiniu/storage/ApiUploadV2UploadPart.java +++ b/src/main/java/com/qiniu/storage/ApiUploadV2UploadPart.java @@ -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(); } diff --git a/src/main/java/com/qiniu/storage/DownloadPrivateCloudUrl.java b/src/main/java/com/qiniu/storage/DownloadPrivateCloudUrl.java index f6592686..080f80ce 100644 --- a/src/main/java/com/qiniu/storage/DownloadPrivateCloudUrl.java +++ b/src/main/java/com/qiniu/storage/DownloadPrivateCloudUrl.java @@ -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); } diff --git a/src/main/java/com/qiniu/storage/DownloadUrl.java b/src/main/java/com/qiniu/storage/DownloadUrl.java index 43dd9824..00d7ec50 100644 --- a/src/main/java/com/qiniu/storage/DownloadUrl.java +++ b/src/main/java/com/qiniu/storage/DownloadUrl.java @@ -159,7 +159,7 @@ public String buildURL() throws QiniuException { } } if (!StringUtils.isNullOrEmpty(keyAndStyle)) { - request.addPathSegment("/" + keyAndStyle); + request.addPathSegment(keyAndStyle); } didSetKeyForUrl(request); From 10778d444553ed5af7cfbe84e19b364466e6d81a Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Fri, 19 Jul 2024 17:17:08 +0800 Subject: [PATCH 04/10] api request parse host --- src/main/java/com/qiniu/storage/Api.java | 16 +++++++++++----- src/main/java/com/qiniu/util/UrlUtils.java | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/qiniu/storage/Api.java b/src/main/java/com/qiniu/storage/Api.java index 35280fda..763b9c14 100644 --- a/src/main/java/com/qiniu/storage/Api.java +++ b/src/main/java/com/qiniu/storage/Api.java @@ -4,10 +4,7 @@ import com.qiniu.http.Client; import com.qiniu.http.MethodType; import com.qiniu.http.RequestStreamBody; -import com.qiniu.util.Auth; -import com.qiniu.util.Json; -import com.qiniu.util.StringMap; -import com.qiniu.util.StringUtils; +import com.qiniu.util.*; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.RequestBody; @@ -461,7 +458,16 @@ public String getHost() throws QiniuException { } void setHost(String host) { - this.host = host; + URL tmpUrl = UrlUtils.parseHost(host); + if (tmpUrl == null) { + this.host = null; + return; + } + + this.host = tmpUrl.getHost(); + if (tmpUrl.getPort() >= 0) { + this.port = tmpUrl.getPort(); + } } /** diff --git a/src/main/java/com/qiniu/util/UrlUtils.java b/src/main/java/com/qiniu/util/UrlUtils.java index f5b8e83e..f39ac88f 100644 --- a/src/main/java/com/qiniu/util/UrlUtils.java +++ b/src/main/java/com/qiniu/util/UrlUtils.java @@ -1,6 +1,8 @@ package com.qiniu.util; import java.io.CharArrayWriter; +import java.net.MalformedURLException; +import java.net.URL; import java.nio.charset.Charset; import java.util.BitSet; @@ -191,6 +193,19 @@ public static String removeHostScheme(String host) { return host; } + public static URL parseHost(String host) { + if (StringUtils.isNullOrEmpty(host)) { + return null; + } + + String tmpHost = setHostScheme(host, true); + try { + return new URL(tmpHost); + } catch (MalformedURLException e) { + return null; + } + } + /** * 如果 host 包含 scheme 则优先使用 host 中包含的 scheme From ffd888f0433fda3b82aed7d8fdcd2b921f3517ea Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Fri, 26 Jul 2024 10:22:35 +0800 Subject: [PATCH 05/10] delete fog-cn-east --- examples/upload_v1_api.java | 1 - examples/upload_v2_api.java | 1 - .../java/com/qiniu/storage/UpHostHelper.java | 1 - src/test/java/test/com/qiniu/TestConfig.java | 4 --- .../test/com/qiniu/processing/PfopTest.java | 8 ++--- .../test/com/qiniu/storage/BucketTest.java | 15 -------- .../com/qiniu/storage/RecordUploadTest.java | 4 --- .../com/qiniu/storage/ResumeUploadTest.java | 36 ++++++++----------- .../com/qiniu/storage/StreamUploadTest.java | 6 ++-- .../com/qiniu/storage/SwitchRegionTest.java | 32 ++++++++--------- 10 files changed, 35 insertions(+), 73 deletions(-) diff --git a/examples/upload_v1_api.java b/examples/upload_v1_api.java index 360edf73..853b8754 100644 --- a/examples/upload_v1_api.java +++ b/examples/upload_v1_api.java @@ -28,7 +28,6 @@ public class UploadDemo { * 华南机房(region2): up-z2.qiniup.com 或 upload-z2.qiniup.com * 北美机房(regionNa0): up-na0.qiniup.com 或 upload-na0.qiniup.com * 新加坡机房(regionAs0): up-as0.qiniup.com 或 upload-as0.qiniup.com - * 雾存储华东一区(regionFogCnEast1): up-fog-cn-east-1.qiniup.com 或 upload-fog-cn-east-1.qiniup.com */ String urlPrefix = "urlPrefix"; // http://up.qiniup.com //要上传的空间 diff --git a/examples/upload_v2_api.java b/examples/upload_v2_api.java index 648a76b3..749a3e9b 100644 --- a/examples/upload_v2_api.java +++ b/examples/upload_v2_api.java @@ -24,7 +24,6 @@ public class UploadDemo { * 华南机房(region2): up-z2.qiniup.com 或 upload-z2.qiniup.com * 北美机房(regionNa0): up-na0.qiniup.com 或 upload-na0.qiniup.com * 新加坡机房(regionAs0): up-as0.qiniup.com 或 upload-as0.qiniup.com - * 雾存储华东一区(regionFogCnEast1): up-fog-cn-east-1.qiniup.com 或 upload-fog-cn-east-1.qiniup.com */ String urlPrefix = "urlPrefix" // http://up.qiniup.com"; // 要上传的空间 diff --git a/src/main/java/com/qiniu/storage/UpHostHelper.java b/src/main/java/com/qiniu/storage/UpHostHelper.java index 70f3185e..5725b6e6 100644 --- a/src/main/java/com/qiniu/storage/UpHostHelper.java +++ b/src/main/java/com/qiniu/storage/UpHostHelper.java @@ -67,7 +67,6 @@ private String failedUpHost(String regionKey) { this.add("upload-z2.qiniup.com"); this.add("upload-na0.qiniup.com"); this.add("upload-as0.qiniup.com"); - this.add("upload-fog-cn-east-1.qiniup.com"); } }; Collections.shuffle(accHosts); // ? diff --git a/src/test/java/test/com/qiniu/TestConfig.java b/src/test/java/test/com/qiniu/TestConfig.java index 26aaf593..64c5f3bd 100644 --- a/src/test/java/test/com/qiniu/TestConfig.java +++ b/src/test/java/test/com/qiniu/TestConfig.java @@ -346,10 +346,6 @@ public String getRegionId() { public Region getRegion() { return region; } - - public boolean isFog() { - return regionId.equals("fog-cn-east-1"); - } } } diff --git a/src/test/java/test/com/qiniu/processing/PfopTest.java b/src/test/java/test/com/qiniu/processing/PfopTest.java index b1e5a74f..ec6aaf01 100644 --- a/src/test/java/test/com/qiniu/processing/PfopTest.java +++ b/src/test/java/test/com/qiniu/processing/PfopTest.java @@ -13,7 +13,9 @@ import org.junit.jupiter.api.Test; import test.com.qiniu.ResCode; import test.com.qiniu.TestConfig; + import java.util.*; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -31,9 +33,7 @@ public void testPfop() throws QiniuException { Map bucketKeyMap = new HashMap(); TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile testFile : files) { - if (!testFile.isFog()) { - bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion()); - } + bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion()); } List ids = new ArrayList<>(); @@ -55,7 +55,7 @@ public void testPfop() throws QiniuException { String fopMp4 = String.format("avthumb/mp4/vcodec/libx264/s/320x240|saveas/%s", UrlSafeBase64.encodeToString(mp4SaveEntry)); - String fops = StringUtils.join(new String[] { fopM3u8, fopMp4 }, ";"); + String fops = StringUtils.join(new String[]{fopM3u8, fopMp4}, ";"); System.out.println(fops); try { diff --git a/src/test/java/test/com/qiniu/storage/BucketTest.java b/src/test/java/test/com/qiniu/storage/BucketTest.java index 01ac6115..540c3181 100644 --- a/src/test/java/test/com/qiniu/storage/BucketTest.java +++ b/src/test/java/test/com/qiniu/storage/BucketTest.java @@ -509,11 +509,6 @@ public void testFetch() throws Exception { testFileWithHandler(new TestFileHandler() { @Override public void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws IOException { - // 雾存储不支持 fetch - if (file.isFog()) { - return; - } - try { String resUrl = "http://devtools.qiniu.com/qiniu.png"; String resKey = "qiniu.png"; @@ -972,11 +967,6 @@ public void testPutBucketAccessStyleMode() throws Exception { testFileWithHandler(new TestFileHandler() { @Override public void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws IOException { - // 雾存储没有域名 - if (file.isFog()) { - return; - } - String bucket = file.getBucketName(); String url = file.getTestUrl(); System.out.println(bucket + " -- " + url); @@ -1590,11 +1580,6 @@ public void testChangeFileType() throws Exception { testFileWithHandler(new TestFileHandler() { @Override public void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws IOException { - // 雾存储不支持 changeType - if (file.isFog()) { - return; - } - String bucket = file.getBucketName(); String key = file.getKey(); String keyToChangeType = "keyToChangeType" + Math.random(); diff --git a/src/test/java/test/com/qiniu/storage/RecordUploadTest.java b/src/test/java/test/com/qiniu/storage/RecordUploadTest.java index 0cd9314e..a38942b6 100644 --- a/src/test/java/test/com/qiniu/storage/RecordUploadTest.java +++ b/src/test/java/test/com/qiniu/storage/RecordUploadTest.java @@ -52,10 +52,6 @@ private void template(final int size, boolean isResumeV2, boolean isConcurrent) TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile file : files) { - // 雾存储不支持 v1 - if (file.isFog() && !isResumeV2) { - continue; - } String bucket = file.getBucketName(); final Region region = file.getRegion(); diff --git a/src/test/java/test/com/qiniu/storage/ResumeUploadTest.java b/src/test/java/test/com/qiniu/storage/ResumeUploadTest.java index e545607f..505539d1 100644 --- a/src/test/java/test/com/qiniu/storage/ResumeUploadTest.java +++ b/src/test/java/test/com/qiniu/storage/ResumeUploadTest.java @@ -14,10 +14,12 @@ import org.junit.jupiter.api.Test; import test.com.qiniu.TempFile; import test.com.qiniu.TestConfig; + import static org.junit.jupiter.api.Assertions.assertEquals; 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.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -33,12 +35,12 @@ public class ResumeUploadTest { private static boolean[][] testConfigList = { // isHttps, isResumeV2, isStream, isConcurrent - { false, true, false, false }, { false, false, false, true }, { false, false, true, false }, - { false, false, true, true }, { false, true, false, false }, { false, true, false, true }, - { false, true, true, false }, { false, true, true, true }, { true, false, false, false }, - { true, false, false, true }, { true, false, true, false }, { true, false, true, true }, - { true, true, false, false }, { true, true, false, true }, { true, true, true, false }, - { true, true, true, true } }; + {false, true, false, false}, {false, false, false, true}, {false, false, true, false}, + {false, false, true, true}, {false, true, false, false}, {false, true, false, true}, + {false, true, true, false}, {false, true, true, true}, {true, false, false, false}, + {true, false, false, true}, {true, false, true, false}, {true, false, true, true}, + {true, true, false, false}, {true, true, false, true}, {true, true, true, false}, + {true, true, true, true}}; /** * 检测自定义变量foo是否生效 @@ -51,10 +53,6 @@ public void testXVar() throws IOException { TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile file : files) { - // 雾存储不支持 v1 - if (file.isFog()) { - continue; - } String bucket = file.getBucketName(); Region region = file.getRegion(); final String expectKey = "世/界"; @@ -99,10 +97,6 @@ private void template(int size, boolean isHttps, boolean isResumeV2, boolean isS throws IOException { TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile file : files) { - // 雾存储不支持 v1 - if (file.isFog() && !isResumeV2) { - continue; - } String bucket = file.getBucketName(); Region region = file.getRegion(); Configuration config = new Configuration(region); @@ -169,14 +163,12 @@ private void template(int size, boolean isHttps, boolean isResumeV2, boolean isS checkMd5 = true; } if (checkMd5) { - if (!file.isFog()) { - String md5 = Md5.md5(f); - String serverMd5 = getFileMD5(file.getTestDomain(), expectKey); - System.out.println(" md5:" + md5); - System.out.println("serverMd5:" + serverMd5); - assertNotNull(serverMd5); - assertEquals(md5, serverMd5); - } + String md5 = Md5.md5(f); + String serverMd5 = getFileMD5(file.getTestDomain(), expectKey); + System.out.println(" md5:" + md5); + System.out.println("serverMd5:" + serverMd5); + assertNotNull(serverMd5); + assertEquals(md5, serverMd5); } else { final String etag = Etag.file(f); System.out.println(" etag:" + etag); diff --git a/src/test/java/test/com/qiniu/storage/StreamUploadTest.java b/src/test/java/test/com/qiniu/storage/StreamUploadTest.java index 3fb42cb0..b72b55d6 100644 --- a/src/test/java/test/com/qiniu/storage/StreamUploadTest.java +++ b/src/test/java/test/com/qiniu/storage/StreamUploadTest.java @@ -14,8 +14,10 @@ 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.fail; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -73,9 +75,7 @@ private void template(int size, boolean https) throws IOException { Map bucketKeyMap = new HashMap(); TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile testFile : files) { - if (!testFile.isFog()) { - bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion()); - } + bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion()); } for (Map.Entry entry : bucketKeyMap.entrySet()) { diff --git a/src/test/java/test/com/qiniu/storage/SwitchRegionTest.java b/src/test/java/test/com/qiniu/storage/SwitchRegionTest.java index 0c42271b..1231c55a 100644 --- a/src/test/java/test/com/qiniu/storage/SwitchRegionTest.java +++ b/src/test/java/test/com/qiniu/storage/SwitchRegionTest.java @@ -15,10 +15,12 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.assertEquals; 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.io.File; import java.io.IOException; import java.net.URLEncoder; @@ -36,13 +38,13 @@ public class SwitchRegionTest { private static final int serialType = 1; private static final int concurrentType = 2; - private static int[][] testConfigList = { { httpType, -1, formType }, { httpType, resumableV1Type, serialType }, - { httpType, resumableV1Type, concurrentType }, { httpType, resumableV2Type, serialType }, - { httpType, resumableV2Type, concurrentType }, + private static int[][] testConfigList = {{httpType, -1, formType}, {httpType, resumableV1Type, serialType}, + {httpType, resumableV1Type, concurrentType}, {httpType, resumableV2Type, serialType}, + {httpType, resumableV2Type, concurrentType}, - { httpsType, -1, formType }, { httpsType, resumableV1Type, serialType }, - { httpsType, resumableV1Type, concurrentType }, { httpsType, resumableV2Type, serialType }, - { httpsType, resumableV2Type, concurrentType }, }; + {httpsType, -1, formType}, {httpsType, resumableV1Type, serialType}, + {httpsType, resumableV1Type, concurrentType}, {httpsType, resumableV2Type, serialType}, + {httpsType, resumableV2Type, concurrentType}}; /** * 分片上传 检测key、hash、fszie、fname是否符合预期 @@ -59,10 +61,6 @@ private void template(int size, int httpType, int uploadType, int uploadStyle) t TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile file : files) { - // 雾存储不支持 v1 - if (file.isFog() && uploadType == resumableV1Type) { - continue; - } String bucket = file.getBucketName(); Region mockRegion = new Region.Builder().region("custom").srcUpHost("mock.src.host.com") @@ -139,14 +137,12 @@ private void template(int size, int httpType, int uploadType, int uploadStyle) t checkMd5 = true; } if (checkMd5) { - if (!file.isFog()) { - String md5 = Md5.md5(f); - String serverMd5 = getFileMD5(file.getTestDomain(), expectKey); - System.out.println(" md5:" + md5); - System.out.println("serverMd5:" + serverMd5); - assertNotNull(serverMd5); - assertEquals(md5, serverMd5); - } + String md5 = Md5.md5(f); + String serverMd5 = getFileMD5(file.getTestDomain(), expectKey); + System.out.println(" md5:" + md5); + System.out.println("serverMd5:" + serverMd5); + assertNotNull(serverMd5); + assertEquals(md5, serverMd5); } else { final String etag = Etag.file(f); System.out.println(" etag:" + etag); From e0169cab86e3d27547fcc95cff4b20945117d18c Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Mon, 9 Sep 2024 10:29:40 +0800 Subject: [PATCH 06/10] pfop --- .../qiniu/processing/OperationManager.java | 33 ++++++++++++++++-- .../com/qiniu/processing/OperationStatus.java | 19 +++++++++++ src/main/java/com/qiniu/storage/Api.java | 34 ++++++++++++++----- .../storage/ApiInterceptorRetryHosts.java | 11 ++++-- src/main/java/com/qiniu/util/Auth.java | 1 + .../test/com/qiniu/processing/PfopTest.java | 31 +++++++++++++++++ 6 files changed, 115 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/qiniu/processing/OperationManager.java b/src/main/java/com/qiniu/processing/OperationManager.java index 9c60b634..8e7c5503 100644 --- a/src/main/java/com/qiniu/processing/OperationManager.java +++ b/src/main/java/com/qiniu/processing/OperationManager.java @@ -80,7 +80,7 @@ public String pfop(String bucket, String key, String fops) throws QiniuException * @param bucket 空间名 * @param key 文件名 * @param fops fops指令,如果有多个指令,需要使用分号(;)进行拼接,例如 avthumb/mp4/xxx|saveas/xxx;vframe/jpg/xxx|saveas/xxx - * @param params notifyURL、force、pipeline 等参数 + * @param params notifyURL、force、pipeline、type等参数 * @return persistentId 请求返回的任务ID,可以根据该ID查询任务状态 * @throws QiniuException 触发失败异常,包含错误响应等信息 * 相关链接 @@ -154,8 +154,35 @@ public String pfop(String bucket, String key, String fops, String pipeline, bool */ public String pfop(String bucket, String key, String fops, String pipeline, String notifyURL, boolean force) throws QiniuException { - StringMap params = new StringMap().putNotEmpty("pipeline", pipeline). - putNotEmpty("notifyURL", notifyURL).putWhen("force", 1, force); + StringMap params = new StringMap() + .putNotEmpty("type", "1") + .putNotEmpty("pipeline", pipeline) + .putNotEmpty("notifyURL", notifyURL) + .putWhen("force", 1, force); + return pfop(bucket, key, fops, params); + } + + /** + * 发送请求对空间中的文件进行持久化处理 + * + * @param bucket 空间名 + * @param key 文件名 + * @param fops fop指令 + * @param pipeline 持久化数据处理队列名称 + * @param notifyURL 处理结果通知地址,任务完成后自动以POST方式将处理结果提交到指定的地址 + * @param type 任务类型,0:非闲时任务,1:闲时任务 + * @param force 用于对同一个指令进行强制处理时指定,一般用于覆盖空间已有文件或者重试失败的指令 + * @return persistentId 请求返回的任务ID,可以根据该ID查询任务状态 + * @throws QiniuException 触发失败异常,包含错误响应等信息 + * 相关链接 + */ + public String pfop(String bucket, String key, String fops, String pipeline, String notifyURL, String type, boolean force) + throws QiniuException { + StringMap params = new StringMap() + .putNotEmpty("type", type) + .putNotEmpty("pipeline", pipeline) + .putNotEmpty("notifyURL", notifyURL) + .putWhen("force", 1, force); return pfop(bucket, key, fops, params); } diff --git a/src/main/java/com/qiniu/processing/OperationStatus.java b/src/main/java/com/qiniu/processing/OperationStatus.java index 5fa9db27..4b1d582e 100644 --- a/src/main/java/com/qiniu/processing/OperationStatus.java +++ b/src/main/java/com/qiniu/processing/OperationStatus.java @@ -9,30 +9,49 @@ public class OperationStatus { * 持久化处理的进程ID,即 persistentId */ public String id; + /** * 状态码 0 成功,1 等待处理,2 正在处理,3 处理失败,4 通知提交失败 */ public int code; + /** * 与状态码相对应的详细描述 */ public String desc; + /** * 处理源文件的文件名 */ public String inputKey; + /** * 处理源文件所在的空间名 */ public String inputBucket; + /** * 云处理操作的处理队列 */ public String pipeline; + /** * 云处理请求的请求id,主要用于七牛技术人员的问题排查 */ public String reqid; + + /** + * 是否是闲时任务 + * 0:非闲时任务 + * 1:显示任务 + */ + public String type; + + /** + * 任务创建时间 + */ + public String creationDate; + /** * 云处理操作列表,包含每个云处理操作的状态信息 */ diff --git a/src/main/java/com/qiniu/storage/Api.java b/src/main/java/com/qiniu/storage/Api.java index 763b9c14..ed3f402d 100644 --- a/src/main/java/com/qiniu/storage/Api.java +++ b/src/main/java/com/qiniu/storage/Api.java @@ -395,6 +395,10 @@ public static class Request implements Cloneable { * @param urlPrefix 请求的 urlPrefix, scheme + host */ protected Request(String urlPrefix) { + if (StringUtils.isNullOrEmpty(urlPrefix)) { + return; + } + try { URL url = new URL(urlPrefix); this.scheme = url.getProtocol(); @@ -634,6 +638,15 @@ public StringMap getHeader() throws QiniuException { return header; } + /** + * 构造 header 信息,如果需要设置请求体,子类需要重写 + * + * @throws QiniuException 组装 header 时的异常,一般为缺失必要参数的异常 + */ + protected void buildHeader() throws QiniuException { + + } + /** * 获取 URL * @@ -804,6 +817,7 @@ boolean canRetry() { protected void prepareToRequest() throws QiniuException { buildPath(); buildQuery(); + buildHeader(); buildBodyInfo(); } @@ -1052,14 +1066,18 @@ protected RequestBody get() { } final MultipartBody.Builder b = new MultipartBody.Builder(); - b.addFormDataPart(name, fileName, body); - - fields.forEach(new StringMap.Consumer() { - @Override - public void accept(String key, Object value) { - b.addFormDataPart(key, value.toString()); - } - }); + if (StringUtils.isNullOrEmpty(name)) { + b.addFormDataPart(name, fileName, body); + } + + if (fields != null) { + fields.forEach(new StringMap.Consumer() { + @Override + public void accept(String key, Object value) { + b.addFormDataPart(key, value.toString()); + } + }); + } b.setType(MediaType.parse("multipart/form-data")); diff --git a/src/main/java/com/qiniu/storage/ApiInterceptorRetryHosts.java b/src/main/java/com/qiniu/storage/ApiInterceptorRetryHosts.java index 343ac2b5..54bd8c3f 100644 --- a/src/main/java/com/qiniu/storage/ApiInterceptorRetryHosts.java +++ b/src/main/java/com/qiniu/storage/ApiInterceptorRetryHosts.java @@ -37,9 +37,14 @@ Api.Response intercept(Api.Request request, Api.Handler handler) throws QiniuExc } String reqHost = request.getHost(); - String firstHost = hostProvider.provider(); - if (!hostProvider.isHostValid(reqHost) && !StringUtils.isNullOrEmpty(firstHost)) { - request.setHost(firstHost); + if (!hostProvider.isHostValid(reqHost)) { + // 支持不配置默认的 host,未配置则从 provider 中获取 + String firstHost = hostProvider.provider(); + if (!StringUtils.isNullOrEmpty(firstHost)) { + request.setHost(firstHost); + } else { + throw QiniuException.unrecoverable("no host provide"); + } } if (retryMax == 0) { diff --git a/src/main/java/com/qiniu/util/Auth.java b/src/main/java/com/qiniu/util/Auth.java index 4ec8c38e..a7aca466 100755 --- a/src/main/java/com/qiniu/util/Auth.java +++ b/src/main/java/com/qiniu/util/Auth.java @@ -48,6 +48,7 @@ public final class Auth { "fsizeMin", "trafficLimit", + "persistentType", "persistentOps", "persistentNotifyUrl", "persistentPipeline", diff --git a/src/test/java/test/com/qiniu/processing/PfopTest.java b/src/test/java/test/com/qiniu/processing/PfopTest.java index ec6aaf01..2a234d67 100644 --- a/src/test/java/test/com/qiniu/processing/PfopTest.java +++ b/src/test/java/test/com/qiniu/processing/PfopTest.java @@ -7,6 +7,8 @@ import com.qiniu.processing.OperationStatus; import com.qiniu.storage.Configuration; import com.qiniu.storage.Region; +import com.qiniu.util.Auth; +import com.qiniu.util.StringMap; import com.qiniu.util.StringUtils; import com.qiniu.util.UrlSafeBase64; import org.junit.jupiter.api.Tag; @@ -138,4 +140,33 @@ private void testPfopIsSuccess(String jobid) { assertEquals(0, status.code); } + @Test + @Tag("IntegrationTest") + public void testPfopA() { + try { + Auth auth = TestConfig.testAuth; + Map bucketKeyMap = new HashMap(); + TestConfig.TestFile[] files = TestConfig.getTestFileArray(); + for (TestConfig.TestFile testFile : files) { + bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion()); + } + for (Map.Entry entry : bucketKeyMap.entrySet()) { + String bucket = entry.getKey(); + Region region = entry.getValue(); + + Configuration cfg = new Configuration(region); + OperationManager operationManager = new OperationManager(auth, cfg); + String jobID = operationManager.pfop(bucket, TestConfig.testMp4FileKey, "avinfo", "", "", "1", true); + + OperationStatus status = operationManager.prefop(bucket, jobID); + assertNotNull(status, "1. prefop type error"); + assertTrue(status.code == 0 || status.code == 1 || status.code == 3, "2. prefop type error"); + assertEquals("1", status.type, "3. prefop type error"); + } + + } catch (QiniuException ex) { + ex.printStackTrace(); + assertTrue(ResCode.find(ex.code(), ResCode.getPossibleResCode(612))); + } + } } From 01edc797eff7be7716b0ab51cd28dab8cd97c070 Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Mon, 9 Sep 2024 10:39:39 +0800 Subject: [PATCH 07/10] pfop --- src/main/java/com/qiniu/processing/OperationManager.java | 5 ++--- src/main/java/com/qiniu/processing/OperationStatus.java | 2 +- src/main/java/com/qiniu/storage/Api.java | 2 +- src/test/java/test/com/qiniu/processing/PfopTest.java | 8 ++++---- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/qiniu/processing/OperationManager.java b/src/main/java/com/qiniu/processing/OperationManager.java index 8e7c5503..ab231cac 100644 --- a/src/main/java/com/qiniu/processing/OperationManager.java +++ b/src/main/java/com/qiniu/processing/OperationManager.java @@ -155,7 +155,6 @@ public String pfop(String bucket, String key, String fops, String pipeline, bool public String pfop(String bucket, String key, String fops, String pipeline, String notifyURL, boolean force) throws QiniuException { StringMap params = new StringMap() - .putNotEmpty("type", "1") .putNotEmpty("pipeline", pipeline) .putNotEmpty("notifyURL", notifyURL) .putWhen("force", 1, force); @@ -176,10 +175,10 @@ public String pfop(String bucket, String key, String fops, String pipeline, Stri * @throws QiniuException 触发失败异常,包含错误响应等信息 * 相关链接 */ - public String pfop(String bucket, String key, String fops, String pipeline, String notifyURL, String type, boolean force) + public String pfop(String bucket, String key, String fops, String pipeline, String notifyURL, Integer type, boolean force) throws QiniuException { StringMap params = new StringMap() - .putNotEmpty("type", type) + .putNotNull("type", type) .putNotEmpty("pipeline", pipeline) .putNotEmpty("notifyURL", notifyURL) .putWhen("force", 1, force); diff --git a/src/main/java/com/qiniu/processing/OperationStatus.java b/src/main/java/com/qiniu/processing/OperationStatus.java index 4b1d582e..8053c205 100644 --- a/src/main/java/com/qiniu/processing/OperationStatus.java +++ b/src/main/java/com/qiniu/processing/OperationStatus.java @@ -45,7 +45,7 @@ public class OperationStatus { * 0:非闲时任务 * 1:显示任务 */ - public String type; + public Integer type; /** * 任务创建时间 diff --git a/src/main/java/com/qiniu/storage/Api.java b/src/main/java/com/qiniu/storage/Api.java index ed3f402d..dd4fe762 100644 --- a/src/main/java/com/qiniu/storage/Api.java +++ b/src/main/java/com/qiniu/storage/Api.java @@ -1066,7 +1066,7 @@ protected RequestBody get() { } final MultipartBody.Builder b = new MultipartBody.Builder(); - if (StringUtils.isNullOrEmpty(name)) { + if (!StringUtils.isNullOrEmpty(name)) { b.addFormDataPart(name, fileName, body); } diff --git a/src/test/java/test/com/qiniu/processing/PfopTest.java b/src/test/java/test/com/qiniu/processing/PfopTest.java index 2a234d67..bf75df02 100644 --- a/src/test/java/test/com/qiniu/processing/PfopTest.java +++ b/src/test/java/test/com/qiniu/processing/PfopTest.java @@ -8,7 +8,6 @@ import com.qiniu.storage.Configuration; import com.qiniu.storage.Region; import com.qiniu.util.Auth; -import com.qiniu.util.StringMap; import com.qiniu.util.StringUtils; import com.qiniu.util.UrlSafeBase64; import org.junit.jupiter.api.Tag; @@ -142,7 +141,7 @@ private void testPfopIsSuccess(String jobid) { @Test @Tag("IntegrationTest") - public void testPfopA() { + void testPfopWithType() { try { Auth auth = TestConfig.testAuth; Map bucketKeyMap = new HashMap(); @@ -156,12 +155,13 @@ public void testPfopA() { Configuration cfg = new Configuration(region); OperationManager operationManager = new OperationManager(auth, cfg); - String jobID = operationManager.pfop(bucket, TestConfig.testMp4FileKey, "avinfo", "", "", "1", true); + String jobID = operationManager.pfop(bucket, TestConfig.testMp4FileKey, "avinfo", "", "", 1, true); OperationStatus status = operationManager.prefop(bucket, jobID); assertNotNull(status, "1. prefop type error"); + assertNotNull(status.creationDate, "1. prefop type error"); assertTrue(status.code == 0 || status.code == 1 || status.code == 3, "2. prefop type error"); - assertEquals("1", status.type, "3. prefop type error"); + assertEquals(1, (int) status.type, "3. prefop type error"); } } catch (QiniuException ex) { From a2f07d02078091e5646ef66f99cef6cccf368371 Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Wed, 11 Sep 2024 17:40:58 +0800 Subject: [PATCH 08/10] upload: add fop test case --- .../com/qiniu/storage/FormUploadTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/test/java/test/com/qiniu/storage/FormUploadTest.java b/src/test/java/test/com/qiniu/storage/FormUploadTest.java index 62b14f31..86074ab2 100644 --- a/src/test/java/test/com/qiniu/storage/FormUploadTest.java +++ b/src/test/java/test/com/qiniu/storage/FormUploadTest.java @@ -2,6 +2,8 @@ import com.qiniu.common.QiniuException; import com.qiniu.http.Response; +import com.qiniu.processing.OperationManager; +import com.qiniu.processing.OperationStatus; import com.qiniu.storage.Configuration; import com.qiniu.storage.UpCompletionHandler; import com.qiniu.storage.UploadManager; @@ -27,6 +29,56 @@ public class FormUploadTest { UploadManager uploadManager = new UploadManager(new Configuration()); + @Test + @Tag("IntegrationTest") + void testUploadWithFop() { + TestConfig.TestFile file = TestConfig.getTestFileArray()[0]; + final String expectKey = "test-fop"; + final String bucket = file.getBucketName(); + + String persistentOpfs = String.format("%s:vframe_test_target.jpg", bucket); + StringMap policy = new StringMap(); + policy.put("persistentOps", persistentOpfs); + policy.put("persistentType", 1); + + Configuration config = new Configuration(); + config.useHttpsDomains = true; + + Response r = null; + try { + String token = TestConfig.testAuth.uploadToken(bucket, expectKey, 3600, policy); + UploadManager uploadManager = new UploadManager(config); + StringMap params = new StringMap().put("x:foo", "foo_val"); + r = uploadManager.put("hello".getBytes(), expectKey, token, params, null, false); + } catch (QiniuException e) { + fail(e.toString()); + } + assertEquals(200, r.statusCode); + + StringMap map = null; + try { + map = r.jsonToMap(); + } catch (QiniuException e) { + fail(e.toString()); + } + + assertNotNull(map, "1. testUploadWithFop error"); + + String persistentId = (String) map.get("persistentId"); + assertNotNull(persistentId, "2. testUploadWithFop error"); + + try { + OperationManager operationManager = new OperationManager(TestConfig.testAuth, config); + OperationStatus status = operationManager.prefop(bucket, persistentId); + assertNotNull(status, "3. prefop type error"); + assertNotNull(status.creationDate, "4. prefop type error"); + assertTrue(status.code == 0 || status.code == 1 || status.code == 3, "5. prefop type error"); + assertEquals(1, (int) status.type, "6. prefop type error"); + } catch (QiniuException e) { + fail(e.toString()); + } + } + /** * hello上传测试 */ From cb3be0f30e172ed091f1545313907eca0be147b6 Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Thu, 12 Sep 2024 16:05:46 +0800 Subject: [PATCH 09/10] change: pfop type doc --- src/main/java/com/qiniu/processing/OperationStatus.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/qiniu/processing/OperationStatus.java b/src/main/java/com/qiniu/processing/OperationStatus.java index 8053c205..64bf80ab 100644 --- a/src/main/java/com/qiniu/processing/OperationStatus.java +++ b/src/main/java/com/qiniu/processing/OperationStatus.java @@ -42,8 +42,8 @@ public class OperationStatus { /** * 是否是闲时任务 - * 0:非闲时任务 - * 1:显示任务 + * null 或 0:非闲时任务 + * 1:闲时任务 */ public Integer type; From 1ddc3c433fa7c333b4596e4900a0047c9a2eacda Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Thu, 12 Sep 2024 16:13:13 +0800 Subject: [PATCH 10/10] version to v7.16.0 --- CHANGELOG.md | 4 ++++ README.md | 4 ++-- src/main/java/com/qiniu/common/Constants.java | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1398314a..df020d2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## 7.16.0(2024-09-12) +* 支持闲时任务 +* 移除已下线区域相关域名 + ## 7.15.1(2024-05-29) * 处理在构造 Download URL 时 Key 前缀为 / 的情况 diff --git a/README.md b/README.md index fa22979b..ef768fbd 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,12 @@ com.qiniu qiniu-java-sdk - [7.15.0, 7.15.99] + [7.16.0, 7.16.99] ``` 或者 Gradle: ```groovy -implementation 'com.qiniu:qiniu-java-sdk:7.15.+' +implementation 'com.qiniu:qiniu-java-sdk:7.16.+' ``` ## 运行环境 diff --git a/src/main/java/com/qiniu/common/Constants.java b/src/main/java/com/qiniu/common/Constants.java index 260c9a02..e0e05c64 100644 --- a/src/main/java/com/qiniu/common/Constants.java +++ b/src/main/java/com/qiniu/common/Constants.java @@ -10,7 +10,7 @@ public final class Constants { /** * 版本号 */ - public static final String VERSION = "7.15.1"; + public static final String VERSION = "7.16.0"; /** * 块大小,不能改变 */