Skip to content

Commit

Permalink
refactor(aliyun-drive): lister without get file detail
Browse files Browse the repository at this point in the history
co-authored-by: yuchanns <me@yuchanns.xyz>
Signed-off-by: suyanhanx <suyanhanx@gmail.com>
  • Loading branch information
suyanhanx and yuchanns committed Jun 17, 2024
1 parent 514e9ca commit 72fe48e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
16 changes: 13 additions & 3 deletions bin/oay/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions core/src/services/aliyun_drive/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use chrono::Utc;

use self::oio::Entry;
use super::core::AliyunDriveCore;
use super::core::AliyunDriveFile;
use super::core::AliyunDriveFileList;
use crate::raw::*;
use crate::EntryMode;
Expand Down Expand Up @@ -93,20 +92,16 @@ impl oio::PageList for AliyunDriveLister {
let n = result.items.len();

for item in result.items {
let res = self.core.get(&item.file_id).await?;
let file: AliyunDriveFile =
serde_json::from_reader(res.reader()).map_err(new_json_serialize_error)?;

let path = if parent.parent_path.starts_with('/') {
build_abs_path(&parent.parent_path, &file.name)
build_abs_path(&parent.parent_path, &item.name)
} else {
build_abs_path(&format!("/{}", &parent.parent_path), &file.name)
build_abs_path(&format!("/{}", &parent.parent_path), &item.name)
};

let (path, md) = if file.path_type == "folder" {
let (path, md) = if item.path_type == "folder" {
let path = format!("{}/", path);
let meta = Metadata::new(EntryMode::DIR).with_last_modified(
file.updated_at
item.updated_at
.parse::<chrono::DateTime<Utc>>()
.map_err(|e| {
Error::new(ErrorKind::Unexpected, "parse last modified time")
Expand All @@ -116,17 +111,17 @@ impl oio::PageList for AliyunDriveLister {
(path, meta)
} else {
let mut meta = Metadata::new(EntryMode::FILE).with_last_modified(
file.updated_at
item.updated_at
.parse::<chrono::DateTime<Utc>>()
.map_err(|e| {
Error::new(ErrorKind::Unexpected, "parse last modified time")
.set_source(e)
})?,
);
if let Some(v) = file.size {
if let Some(v) = item.size {
meta = meta.with_content_length(v);
}
if let Some(v) = file.content_type {
if let Some(v) = item.content_type {
meta = meta.with_content_type(v);
}
(path, meta)
Expand Down

0 comments on commit 72fe48e

Please sign in to comment.