Skip to content

Commit

Permalink
fix(services/aliyun-drive): unable to list /
Browse files Browse the repository at this point in the history
Signed-off-by: Hanchin Hsieh <[email protected]>
  • Loading branch information
yuchanns committed Jun 18, 2024
1 parent dbb9b9f commit 694e09f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions core/src/services/aliyun_drive/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,29 @@ impl AliyunDriveCore {
Ok((token, drive_id.clone()))
}

pub async fn get_by_path(&self, path: &str) -> Result<Buffer> {
let file_path = build_rooted_abs_path(&self.root, path);
pub fn build_path(&self, path: &str, rooted: bool) -> String {
let file_path = if rooted {
build_rooted_abs_path(&self.root, path)
} else {
build_abs_path(&self.root, path)
};
let file_path = file_path.strip_suffix('/').unwrap_or(&file_path);
if file_path.is_empty() {
return "/".to_string();
}
file_path.to_string()
}

pub async fn get_by_path(&self, path: &str) -> Result<Buffer> {
let file_path = self.build_path(path, true);
let req = Request::post(format!(
"{}/adrive/v1.0/openFile/get_by_path",
self.endpoint
));
let (token, drive_id) = self.get_token_and_drive().await?;
let body = serde_json::to_vec(&GetByPathRequest {
drive_id: &drive_id,
file_path,
file_path: &file_path,
})
.map_err(new_json_serialize_error)?;
let req = req
Expand All @@ -190,7 +202,7 @@ impl AliyunDriveCore {
}

pub async fn ensure_dir_exists(&self, path: &str) -> Result<String> {
let file_path = build_abs_path(&self.root, path.strip_suffix('/').unwrap_or(path));
let file_path = self.build_path(path, false);
if file_path == "/" {
return Ok("root".to_string());
}
Expand Down

0 comments on commit 694e09f

Please sign in to comment.