This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 4ebb69b5d feat(services/cos): Rewrite the method signatures using 
OpWrite (#3070)
4ebb69b5d is described below

commit 4ebb69b5d39f6812c3a69382ae9bc2c809145513
Author: Au <[email protected]>
AuthorDate: Thu Sep 14 23:16:45 2023 +0800

    feat(services/cos): Rewrite the method signatures using OpWrite (#3070)
    
    * feat(services/cos)!: Rewrite the method signatures using OpWrite
    
    * chore(services/cos): change Default::default to OpWrite::default
---
 core/src/services/cos/backend.rs | 21 ++++++++++-----------
 core/src/services/cos/core.rs    | 20 ++++++++------------
 core/src/services/cos/writer.rs  | 18 ++++--------------
 3 files changed, 22 insertions(+), 37 deletions(-)

diff --git a/core/src/services/cos/backend.rs b/core/src/services/cos/backend.rs
index d4428ad69..b41f12b5e 100644
--- a/core/src/services/cos/backend.rs
+++ b/core/src/services/cos/backend.rs
@@ -299,9 +299,12 @@ impl Accessor for CosBackend {
     }
 
     async fn create_dir(&self, path: &str, _: OpCreateDir) -> 
Result<RpCreateDir> {
-        let mut req =
-            self.core
-                .cos_put_object_request(path, Some(0), None, None, None, 
AsyncBody::Empty)?;
+        let mut req = self.core.cos_put_object_request(
+            path,
+            Some(0),
+            &OpWrite::default(),
+            AsyncBody::Empty,
+        )?;
 
         self.core.sign(&mut req).await?;
 
@@ -409,14 +412,10 @@ impl Accessor for CosBackend {
                 v.if_match(),
                 v.if_none_match(),
             )?,
-            PresignOperation::Write(v) => self.core.cos_put_object_request(
-                path,
-                None,
-                v.content_type(),
-                v.content_disposition(),
-                v.cache_control(),
-                AsyncBody::Empty,
-            )?,
+            PresignOperation::Write(v) => {
+                self.core
+                    .cos_put_object_request(path, None, v, AsyncBody::Empty)?
+            }
         };
         self.core.sign_query(&mut req, args.expire()).await?;
 
diff --git a/core/src/services/cos/core.rs b/core/src/services/cos/core.rs
index fa6bfe99e..27e428b23 100644
--- a/core/src/services/cos/core.rs
+++ b/core/src/services/cos/core.rs
@@ -151,9 +151,7 @@ impl CosCore {
         &self,
         path: &str,
         size: Option<u64>,
-        content_type: Option<&str>,
-        content_disposition: Option<&str>,
-        cache_control: Option<&str>,
+        args: &OpWrite,
         body: AsyncBody,
     ) -> Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
@@ -165,13 +163,13 @@ impl CosCore {
         if let Some(size) = size {
             req = req.header(CONTENT_LENGTH, size)
         }
-        if let Some(cache_control) = cache_control {
+        if let Some(cache_control) = args.cache_control() {
             req = req.header(CACHE_CONTROL, cache_control)
         }
-        if let Some(pos) = content_disposition {
+        if let Some(pos) = args.content_disposition() {
             req = req.header(CONTENT_DISPOSITION, pos)
         }
-        if let Some(mime) = content_type {
+        if let Some(mime) = args.content_type() {
             req = req.header(CONTENT_TYPE, mime)
         }
 
@@ -334,9 +332,7 @@ impl CosCore {
     pub async fn cos_initiate_multipart_upload(
         &self,
         path: &str,
-        content_type: Option<&str>,
-        content_disposition: Option<&str>,
-        cache_control: Option<&str>,
+        args: &OpWrite,
     ) -> Result<Response<IncomingAsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
@@ -344,15 +340,15 @@ impl CosCore {
 
         let mut req = Request::post(&url);
 
-        if let Some(mime) = content_type {
+        if let Some(mime) = args.content_type() {
             req = req.header(CONTENT_TYPE, mime)
         }
 
-        if let Some(content_disposition) = content_disposition {
+        if let Some(content_disposition) = args.content_disposition() {
             req = req.header(CONTENT_DISPOSITION, content_disposition)
         }
 
-        if let Some(cache_control) = cache_control {
+        if let Some(cache_control) = args.cache_control() {
             req = req.header(CACHE_CONTROL, cache_control)
         }
 
diff --git a/core/src/services/cos/writer.rs b/core/src/services/cos/writer.rs
index 11681b99a..26c833de6 100644
--- a/core/src/services/cos/writer.rs
+++ b/core/src/services/cos/writer.rs
@@ -48,14 +48,9 @@ impl CosWriter {
 #[async_trait]
 impl oio::MultipartUploadWrite for CosWriter {
     async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()> {
-        let mut req = self.core.cos_put_object_request(
-            &self.path,
-            Some(size),
-            self.op.content_type(),
-            self.op.content_disposition(),
-            self.op.cache_control(),
-            body,
-        )?;
+        let mut req = self
+            .core
+            .cos_put_object_request(&self.path, Some(size), &self.op, body)?;
 
         self.core.sign(&mut req).await?;
 
@@ -75,12 +70,7 @@ impl oio::MultipartUploadWrite for CosWriter {
     async fn initiate_part(&self) -> Result<String> {
         let resp = self
             .core
-            .cos_initiate_multipart_upload(
-                &self.path,
-                self.op.content_type(),
-                self.op.content_disposition(),
-                self.op.cache_control(),
-            )
+            .cos_initiate_multipart_upload(&self.path, &self.op)
             .await?;
 
         let status = resp.status();

Reply via email to