Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo committed Jan 10, 2024
1 parent c321521 commit fee030f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 63 deletions.
20 changes: 10 additions & 10 deletions core/src/services/cos/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl CosCore {
&self,
path: &str,
upload_id: &str,
parts: Vec<CompleteMultipartRequestPart>,
parts: Vec<CompleteMultipartUploadRequestPart>,
) -> Result<Response<IncomingAsyncBody>> {
let p = build_abs_path(&self.root, path);

Expand All @@ -393,7 +393,7 @@ impl CosCore {

let req = Request::post(&url);

let content = quick_xml::se::to_string(&CompleteMultipartRequest { part: parts })
let content = quick_xml::se::to_string(&CompleteMultipartUploadRequest { part: parts })
.map_err(new_xml_deserialize_error)?;
// Make sure content length has been set to avoid post with chunked encoding.
let req = req.header(CONTENT_LENGTH, content.len());
Expand Down Expand Up @@ -432,23 +432,23 @@ impl CosCore {
}
}

/// Result of CreateMultipart
/// Result of CreateMultipartUpload
#[derive(Default, Debug, Deserialize)]
#[serde(default, rename_all = "PascalCase")]
pub struct InitiateMultipartResult {
pub struct InitiateMultipartUploadResult {
pub upload_id: String,
}

/// Request of CompleteMultipartRequest
/// Request of CompleteMultipartUploadRequest
#[derive(Default, Debug, Serialize)]
#[serde(default, rename = "CompleteMultipart", rename_all = "PascalCase")]
pub struct CompleteMultipartRequest {
pub part: Vec<CompleteMultipartRequestPart>,
#[serde(default, rename = "CompleteMultipartUpload", rename_all = "PascalCase")]
pub struct CompleteMultipartUploadRequest {
pub part: Vec<CompleteMultipartUploadRequestPart>,
}

#[derive(Clone, Default, Debug, Serialize)]
#[serde(default, rename_all = "PascalCase")]
pub struct CompleteMultipartRequestPart {
pub struct CompleteMultipartUploadRequestPart {
#[serde(rename = "PartNumber")]
pub part_number: usize,
/// # TODO
Expand All @@ -461,7 +461,7 @@ pub struct CompleteMultipartRequestPart {
/// ```ignore
/// #[derive(Default, Debug, Serialize)]
/// #[serde(default, rename_all = "PascalCase")]
/// struct CompleteMultipartRequestPart {
/// struct CompleteMultipartUploadRequestPart {
/// #[serde(rename = "PartNumber")]
/// part_number: usize,
/// #[serde(rename = "ETag", serialize_with = "partial_escape")]
Expand Down
20 changes: 10 additions & 10 deletions core/src/services/obs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl ObsCore {
&self,
path: &str,
upload_id: &str,
parts: Vec<CompleteMultipartRequestPart>,
parts: Vec<CompleteMultipartUploadRequestPart>,
) -> Result<Response<IncomingAsyncBody>> {
let p = build_abs_path(&self.root, path);
let url = format!(
Expand All @@ -385,7 +385,7 @@ impl ObsCore {

let req = Request::post(&url);

let content = quick_xml::se::to_string(&CompleteMultipartRequest {
let content = quick_xml::se::to_string(&CompleteMultipartUploadRequest {
part: parts.to_vec(),
})
.map_err(new_xml_deserialize_error)?;
Expand Down Expand Up @@ -426,23 +426,23 @@ impl ObsCore {
}
}

/// Result of CreateMultipart
/// Result of CreateMultipartUpload
#[derive(Default, Debug, Deserialize)]
#[serde(default, rename_all = "PascalCase")]
pub struct InitiateMultipartResult {
pub struct InitiateMultipartUploadResult {
pub upload_id: String,
}

/// Request of CompleteMultipartRequest
/// Request of CompleteMultipartUploadRequest
#[derive(Default, Debug, Serialize)]
#[serde(default, rename = "CompleteMultipart", rename_all = "PascalCase")]
pub struct CompleteMultipartRequest {
pub part: Vec<CompleteMultipartRequestPart>,
#[serde(default, rename = "CompleteMultipartUpload", rename_all = "PascalCase")]
pub struct CompleteMultipartUploadRequest {
pub part: Vec<CompleteMultipartUploadRequestPart>,
}

#[derive(Clone, Default, Debug, Serialize)]
#[serde(default, rename_all = "PascalCase")]
pub struct CompleteMultipartRequestPart {
pub struct CompleteMultipartUploadRequestPart {
#[serde(rename = "PartNumber")]
pub part_number: usize,
///
Expand All @@ -455,7 +455,7 @@ pub struct CompleteMultipartRequestPart {
/// ```ignore
/// #[derive(Default, Debug, Serialize)]
/// #[serde(default, rename_all = "PascalCase")]
/// struct CompleteMultipartRequestPart {
/// struct CompleteMultipartUploadRequestPart {
/// #[serde(rename = "PartNumber")]
/// part_number: usize,
/// #[serde(rename = "ETag", serialize_with = "partial_escape")]
Expand Down
45 changes: 23 additions & 22 deletions core/src/services/oss/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl OssCore {

/// Set sse headers
/// # Note
/// According to the OSS documentation, only PutObject, CopyObject, and InitiateMultipart may require to be set.
/// According to the OSS documentation, only PutObject, CopyObject, and InitiateMultipartUpload may require to be set.
pub fn insert_sse_headers(&self, mut req: http::request::Builder) -> http::request::Builder {
if let Some(v) = &self.server_side_encryption {
let mut v = v.clone();
Expand Down Expand Up @@ -564,7 +564,7 @@ impl OssCore {
path: &str,
upload_id: &str,
is_presign: bool,
parts: Vec<MultipartPart>,
parts: Vec<MultipartUploadPart>,
) -> Result<Response<IncomingAsyncBody>> {
let p = build_abs_path(&self.root, path);
let endpoint = self.get_endpoint(is_presign);
Expand All @@ -577,7 +577,7 @@ impl OssCore {

let req = Request::post(&url);

let content = quick_xml::se::to_string(&CompleteMultipartRequest {
let content = quick_xml::se::to_string(&CompleteMultipartUploadRequest {
part: parts.to_vec(),
})
.map_err(new_xml_deserialize_error)?;
Expand All @@ -595,7 +595,7 @@ impl OssCore {
}

/// Abort an on-going multipart upload.
/// reference docs https://www.alibabacloud.com/help/zh/oss/developer-reference/abortMultipart
/// reference docs https://www.alibabacloud.com/help/zh/oss/developer-reference/abortmultipartupload
pub async fn oss_abort_multipart_upload(
&self,
path: &str,
Expand Down Expand Up @@ -654,7 +654,7 @@ pub struct DeleteObjectsResultError {

#[derive(Default, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct InitiateMultipartResult {
pub struct InitiateMultipartUploadResult {
#[cfg(test)]
pub bucket: String,
#[cfg(test)]
Expand All @@ -664,22 +664,22 @@ pub struct InitiateMultipartResult {

#[derive(Clone, Default, Debug, Serialize)]
#[serde(default, rename_all = "PascalCase")]
pub struct MultipartPart {
pub struct MultipartUploadPart {
#[serde(rename = "PartNumber")]
pub part_number: usize,
#[serde(rename = "ETag")]
pub etag: String,
}

#[derive(Default, Debug, Serialize)]
#[serde(default, rename = "CompleteMultipart", rename_all = "PascalCase")]
pub struct CompleteMultipartRequest {
pub part: Vec<MultipartPart>,
#[serde(default, rename = "CompleteMultipartUpload", rename_all = "PascalCase")]
pub struct CompleteMultipartUploadRequest {
pub part: Vec<MultipartUploadPart>,
}

#[derive(Default, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct CompleteMultipartResult {
pub struct CompleteMultipartUploadResult {
pub location: String,
pub bucket: String,
pub key: String,
Expand Down Expand Up @@ -792,13 +792,13 @@ mod tests {
fn test_deserialize_initiate_multipart_upload_response() {
let bs = Bytes::from(
r#"<?xml version="1.0" encoding="UTF-8"?>
<InitiateMultipartResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
<InitiateMultipartUploadResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
<Bucket>oss-example</Bucket>
<Key>multipart.data</Key>
<UploadId>0004B9894A22E5B1888A1E29F823****</UploadId>
</InitiateMultipartResult>"#,
</InitiateMultipartUploadResult>"#,
);
let out: InitiateMultipartResult =
let out: InitiateMultipartUploadResult =
quick_xml::de::from_reader(bs.reader()).expect("must success");

assert_eq!("0004B9894A22E5B1888A1E29F823****", out.upload_id);
Expand All @@ -808,17 +808,17 @@ mod tests {

#[test]
fn test_serialize_complete_multipart_upload_request() {
let req = CompleteMultipartRequest {
let req = CompleteMultipartUploadRequest {
part: vec![
MultipartPart {
MultipartUploadPart {
part_number: 1,
etag: "\"3349DC700140D7F86A0784842780****\"".to_string(),
},
MultipartPart {
MultipartUploadPart {
part_number: 5,
etag: "\"8EFDA8BE206636A695359836FE0A****\"".to_string(),
},
MultipartPart {
MultipartUploadPart {
part_number: 8,
etag: "\"8C315065167132444177411FDA14****\"".to_string(),
},
Expand All @@ -832,7 +832,7 @@ mod tests {
req.serialize(serializer).unwrap();
pretty_assertions::assert_eq!(
serialized,
r#"<CompleteMultipart>
r#"<CompleteMultipartUpload>
<Part>
<PartNumber>1</PartNumber>
<ETag>"3349DC700140D7F86A0784842780****"</ETag>
Expand All @@ -845,7 +845,7 @@ mod tests {
<PartNumber>8</PartNumber>
<ETag>"8C315065167132444177411FDA14****"</ETag>
</Part>
</CompleteMultipart>"#
</CompleteMultipartUpload>"#
.replace('"', "&quot;") /* Escape `"` by hand to address <https://github.com/tafia/quick-xml/issues/362> */
)
}
Expand All @@ -854,16 +854,17 @@ mod tests {
fn test_deserialize_complete_oss_multipart_result() {
let bytes = Bytes::from(
r#"<?xml version="1.0" encoding="UTF-8"?>
<CompleteMultipartResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
<CompleteMultipartUploadResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
<EncodingType>url</EncodingType>
<Location>http://oss-example.oss-cn-hangzhou.aliyuncs.com /multipart.data</Location>
<Bucket>oss-example</Bucket>
<Key>multipart.data</Key>
<ETag>"B864DB6A936D376F9F8D3ED3BBE540****"</ETag>
</CompleteMultipartResult>"#,
</CompleteMultipartUploadResult>"#,
);

let result: CompleteMultipartResult = quick_xml::de::from_reader(bytes.reader()).unwrap();
let result: CompleteMultipartUploadResult =
quick_xml::de::from_reader(bytes.reader()).unwrap();
assert_eq!("\"B864DB6A936D376F9F8D3ED3BBE540****\"", result.etag);
assert_eq!(
"http://oss-example.oss-cn-hangzhou.aliyuncs.com /multipart.data",
Expand Down
42 changes: 21 additions & 21 deletions core/src/services/s3/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ impl S3Core {
&self,
path: &str,
upload_id: &str,
parts: Vec<CompleteMultipartRequestPart>,
parts: Vec<CompleteMultipartUploadRequestPart>,
) -> Result<Response<IncomingAsyncBody>> {
let p = build_abs_path(&self.root, path);

Expand All @@ -624,7 +624,7 @@ impl S3Core {
// Set SSE headers.
let req = self.insert_sse_headers(req, true);

let content = quick_xml::se::to_string(&CompleteMultipartRequest { part: parts })
let content = quick_xml::se::to_string(&CompleteMultipartUploadRequest { part: parts })
.map_err(new_xml_deserialize_error)?;
// Make sure content length has been set to avoid post with chunked encoding.
let req = req.header(CONTENT_LENGTH, content.len());
Expand Down Expand Up @@ -697,23 +697,23 @@ impl S3Core {
}
}

/// Result of CreateMultipart
/// Result of CreateMultipartUpload
#[derive(Default, Debug, Deserialize)]
#[serde(default, rename_all = "PascalCase")]
pub struct InitiateMultipartResult {
pub struct InitiateMultipartUploadResult {
pub upload_id: String,
}

/// Request of CompleteMultipartRequest
/// Request of CompleteMultipartUploadRequest
#[derive(Default, Debug, Serialize)]
#[serde(default, rename = "CompleteMultipart", rename_all = "PascalCase")]
pub struct CompleteMultipartRequest {
pub part: Vec<CompleteMultipartRequestPart>,
#[serde(default, rename = "CompleteMultipartUpload", rename_all = "PascalCase")]
pub struct CompleteMultipartUploadRequest {
pub part: Vec<CompleteMultipartUploadRequestPart>,
}

#[derive(Clone, Default, Debug, Serialize)]
#[serde(default, rename_all = "PascalCase")]
pub struct CompleteMultipartRequestPart {
pub struct CompleteMultipartUploadRequestPart {
#[serde(rename = "PartNumber")]
pub part_number: usize,
/// # TODO
Expand All @@ -726,7 +726,7 @@ pub struct CompleteMultipartRequestPart {
/// ```ignore
/// #[derive(Default, Debug, Serialize)]
/// #[serde(default, rename_all = "PascalCase")]
/// struct CompleteMultipartRequestPart {
/// struct CompleteMultipartUploadRequestPart {
/// #[serde(rename = "PartNumber")]
/// part_number: usize,
/// #[serde(rename = "ETag", serialize_with = "partial_escape")]
Expand Down Expand Up @@ -824,19 +824,19 @@ mod tests {

use super::*;

/// This example is from https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipart.html#API_CreateMultipart_Examples
/// This example is from https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html#API_CreateMultipartUpload_Examples
#[test]
fn test_deserialize_initiate_multipart_upload_result() {
let bs = Bytes::from(
r#"<?xml version="1.0" encoding="UTF-8"?>
<InitiateMultipartResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<InitiateMultipartUploadResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Bucket>example-bucket</Bucket>
<Key>example-object</Key>
<UploadId>VXBsb2FkIElEIGZvciA2aWWpbmcncyBteS1tb3ZpZS5tMnRzIHVwbG9hZA</UploadId>
</InitiateMultipartResult>"#,
</InitiateMultipartUploadResult>"#,
);

let out: InitiateMultipartResult =
let out: InitiateMultipartUploadResult =
quick_xml::de::from_reader(bs.reader()).expect("must success");

assert_eq!(
Expand All @@ -845,20 +845,20 @@ mod tests {
)
}

/// This example is from https://docs.aws.amazon.com/AmazonS3/latest/API/API_CompleteMultipart.html#API_CompleteMultipart_Examples
/// This example is from https://docs.aws.amazon.com/AmazonS3/latest/API/API_CompleteMultipartUpload.html#API_CompleteMultipartUpload_Examples
#[test]
fn test_serialize_complete_multipart_upload_request() {
let req = CompleteMultipartRequest {
let req = CompleteMultipartUploadRequest {
part: vec![
CompleteMultipartRequestPart {
CompleteMultipartUploadRequestPart {
part_number: 1,
etag: "\"a54357aff0632cce46d942af68356b38\"".to_string(),
},
CompleteMultipartRequestPart {
CompleteMultipartUploadRequestPart {
part_number: 2,
etag: "\"0c78aef83f66abc1fa1e8477f296d394\"".to_string(),
},
CompleteMultipartRequestPart {
CompleteMultipartUploadRequestPart {
part_number: 3,
etag: "\"acbd18db4cc2f85cedef654fccc4a4d8\"".to_string(),
},
Expand All @@ -869,7 +869,7 @@ mod tests {

pretty_assertions::assert_eq!(
actual,
r#"<CompleteMultipart>
r#"<CompleteMultipartUpload>
<Part>
<PartNumber>1</PartNumber>
<ETag>"a54357aff0632cce46d942af68356b38"</ETag>
Expand All @@ -882,7 +882,7 @@ mod tests {
<PartNumber>3</PartNumber>
<ETag>"acbd18db4cc2f85cedef654fccc4a4d8"</ETag>
</Part>
</CompleteMultipart>"#
</CompleteMultipartUpload>"#
// Cleanup space and new line
.replace([' ', '\n'], "")
// Escape `"` by hand to address <https://github.com/tafia/quick-xml/issues/362>
Expand Down

0 comments on commit fee030f

Please sign in to comment.