enhance(fs):优化文件夹扫描。
This commit is contained in:
		| @@ -48,8 +48,12 @@ pub async fn scan_directory(target: String) -> Result<Vec<FileItem>, String> { | |||||||
|         if !entry.path().is_file() { |         if !entry.path().is_file() { | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|         let (width, height) = image::image_dimensions(entry.path()) |         let image_detect_result = image::image_dimensions(entry.path()); | ||||||
|             .map_err(|_e| format!("读取图片文件 {} 元信息失败。", entry.path().display()))?; |         if image_detect_result.is_err() { | ||||||
|  |             println!("读取图片文件 {} 元信息失败。", entry.path().display()); | ||||||
|  |             continue; | ||||||
|  |         } | ||||||
|  |         let (width, height) = image_detect_result.unwrap(); | ||||||
|         let file_hash_id = entry |         let file_hash_id = entry | ||||||
|             .path() |             .path() | ||||||
|             .to_str() |             .to_str() | ||||||
| @@ -60,20 +64,27 @@ pub async fn scan_directory(target: String) -> Result<Vec<FileItem>, String> { | |||||||
|         let filename = entry |         let filename = entry | ||||||
|             .path() |             .path() | ||||||
|             .file_name() |             .file_name() | ||||||
|             .ok_or(String::from("不能获取到文件名。"))? |             .ok_or(String::from("不能获取到文件名。")) | ||||||
|             .to_owned() |             .map(ToOwned::to_owned) | ||||||
|             .into_string() |             .map(|s| s.into_string().unwrap()); | ||||||
|             .unwrap(); |         if filename.is_err() { | ||||||
|  |             println!("不能获取到文件 {} 文件名。", entry.path().display()); | ||||||
|  |             continue; | ||||||
|  |         } | ||||||
|         let path = entry |         let path = entry | ||||||
|             .path() |             .path() | ||||||
|             .clone() |             .clone() | ||||||
|             .to_str() |             .to_str() | ||||||
|             .ok_or(String::from("不能获取到文件路径。"))? |             .ok_or(String::from("不能获取到文件路径。")) | ||||||
|             .to_string(); |             .map(ToString::to_string); | ||||||
|  |         if path.is_err() { | ||||||
|  |             println!("不能获取到文件 {} 路径。", entry.path().display()); | ||||||
|  |             continue; | ||||||
|  |         } | ||||||
|         file_items.push(FileItem { |         file_items.push(FileItem { | ||||||
|             id: file_hash_id, |             id: file_hash_id, | ||||||
|             filename, |             filename: filename.unwrap(), | ||||||
|             path, |             path: path.unwrap(), | ||||||
|             height, |             height, | ||||||
|             width, |             width, | ||||||
|         }); |         }); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user