Skip to content

Commit

Permalink
Don't use download url from list file API if file category is image
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed May 6, 2022
1 parent a40ecaf commit 05c230f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/drive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl AliyunDrive {
let mut marker = None;
loop {
let res = self.list(parent_file_id, marker.as_deref()).await?;
files.extend(res.items.into_iter());
files.extend(res.items.into_iter().map(|f| f.into()));
if res.next_marker.is_empty() {
break;
}
Expand Down
35 changes: 34 additions & 1 deletion src/drive/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,24 @@ pub struct ListFileRequest<'a> {

#[derive(Debug, Clone, Deserialize)]
pub struct ListFileResponse {
pub items: Vec<AliyunFile>,
pub items: Vec<ListFileItem>,
pub next_marker: String,
}

#[derive(Debug, Clone, Deserialize)]
pub struct ListFileItem {
pub name: String,
pub category: Option<String>,
#[serde(rename = "file_id")]
pub id: String,
pub r#type: FileType,
pub created_at: DateTime,
pub updated_at: DateTime,
#[serde(default)]
pub size: u64,
pub url: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
pub struct GetFileByPathRequest<'a> {
pub drive_id: &'a str,
Expand Down Expand Up @@ -274,3 +288,22 @@ impl AliyunFile {
}
}
}

impl From<ListFileItem> for AliyunFile {
fn from(f: ListFileItem) -> Self {
Self {
name: f.name,
id: f.id,
r#type: f.r#type,
created_at: f.created_at,
updated_at: f.updated_at,
size: f.size,
// 文件列表接口返回的图片下载地址经常是有问题的, 不使用它
url: if matches!(f.category.as_deref(), Some("image")) {
None
} else {
f.url
},
}
}
}

0 comments on commit 05c230f

Please sign in to comment.