You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "Xuanwo (via GitHub)" <gi...@apache.org> on 2023/07/02 16:13:16 UTC

[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2588: feat(service): Support stat for Dropbox

Xuanwo commented on code in PR #2588:
URL: https://github.com/apache/incubator-opendal/pull/2588#discussion_r1249601531


##########
core/src/services/dropbox/backend.rs:
##########
@@ -90,4 +91,38 @@ impl Accessor for DropboxBackend {
             _ => Err(parse_error(resp).await?),
         }
     }
+
+    async fn stat(&self, path: &str, _: OpStat) -> Result<RpStat> {
+        if path == "/" {
+            return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
+        }
+        let resp = self.core.dropbox_get_stat(path).await?;
+        let status = resp.status();
+        if status.is_success() {
+            let bytes = resp.into_body().bytes().await?;
+            let decoded_response = serde_json::from_slice::<DropboxMetadataResponse>(&bytes)
+                .map_err(new_json_deserialize_error)?;
+            let entry_mode: EntryMode = match decoded_response.tag.as_str() {
+                "file" => EntryMode::FILE,
+                "folder" => EntryMode::DIR,
+                _ => EntryMode::Unknown,
+            };
+            let mut metadata = Metadata::new(entry_mode);
+            let last_modified = decoded_response.client_modified;
+            let date_utc_last_modified = parse_datetime_from_rfc3339(&last_modified)?;
+            metadata.set_last_modified(date_utc_last_modified);
+            if decoded_response.size.is_some() {
+                let size = decoded_response.size.unwrap();
+                metadata.set_content_length(size);
+            }
+            Ok(RpStat::new(metadata))
+        } else {
+            match status {

Review Comment:
   I don't like code like `if status { xxx } else { match status { yyy } }`. How about writing them in flat way?



##########
core/src/services/dropbox/core.rs:
##########
@@ -111,6 +111,23 @@ impl DropboxCore {
         self.client.send(request).await
     }
 
+    pub async fn dropbox_get_stat(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
+        let url = "https://api.dropboxapi.com/2/files/get_metadata".to_string();
+        let args = DropboxMetadataArgs {
+            path: build_rooted_abs_path(&self.root, path),
+            ..Default::default()
+        };
+
+        let bs = Bytes::from(serde_json::to_string(&args).map_err(new_json_serialize_error)?);

Review Comment:
   How about using `serde_json::to_vec` directly?



##########
core/src/services/dropbox/core.rs:
##########
@@ -111,6 +111,23 @@ impl DropboxCore {
         self.client.send(request).await
     }
 
+    pub async fn dropbox_get_stat(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
+        let url = "https://api.dropboxapi.com/2/files/get_metadata".to_string();
+        let args = DropboxMetadataArgs {
+            path: build_rooted_abs_path(&self.root, path),
+            ..Default::default()
+        };
+
+        let bs = Bytes::from(serde_json::to_string(&args).map_err(new_json_serialize_error)?);
+
+        let request = self
+            .build_auth_header(Request::post(&url))

Review Comment:
   Please build request first and calling `self.core.sign()` instead.



##########
core/src/services/dropbox/core.rs:
##########
@@ -111,6 +111,23 @@ impl DropboxCore {
         self.client.send(request).await
     }
 
+    pub async fn dropbox_get_stat(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {

Review Comment:
   Please naming the function in the same way as it's API, like: `dropbox_get_metadata` 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org