Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(services/aliyun-drive): unable to list / #4754

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading