Skip to content

Commit

Permalink
change path add segment
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn committed May 29, 2024
1 parent a838948 commit c087705
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 55 deletions.
13 changes: 11 additions & 2 deletions src/main/java/com/qiniu/storage/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
}


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
2 changes: 1 addition & 1 deletion src/main/java/com/qiniu/storage/DownloadUrl.java
Original file line number Diff line number Diff line change
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

0 comments on commit c087705

Please sign in to comment.