Compare commits

...

2 Commits

Author SHA1 Message Date
徐涛
c63da5222e enhance(fs):优化文件夹扫描。 2023-03-22 09:25:21 +08:00
徐涛
32e797f35d enhance(debug):去掉一些不再使用的调试语句。 2023-03-22 08:40:30 +08:00
2 changed files with 22 additions and 13 deletions

View File

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

View File

@ -4,7 +4,7 @@ import { ActionIcon, Box, Flex, Stack, Text, Tooltip } from '@mantine/core';
import { notifications } from '@mantine/notifications';
import { IconEye, IconSquareMinus, IconSquarePlus } from '@tabler/icons-react';
import { invoke } from '@tauri-apps/api';
import { equals, isEmpty, isNil, length, map, not } from 'ramda';
import { equals, isEmpty, isNil, map, not } from 'ramda';
import { FC, PropsWithChildren, useCallback, useContext, useState } from 'react';
import { useMeasure, useMount } from 'react-use';
import { EventBusContext } from '../EventBus';
@ -69,7 +69,6 @@ const Branch: FC<PropsWithChildren<{ current: DirItem; expanded: boolean }>> = (
try {
selectDir(current.id);
const files = await invoke('scan_directory', { target: current.path });
console.log('[debug]获取到文件个数:', length(files));
storeFiles(files);
ebus.emit('reset_views');
} catch (e) {
@ -122,7 +121,6 @@ export const DirTree: FC = () => {
const [viewRef, { width }] = useMeasure();
const handleFocusAction = useCallback(() => {
console.log('[debug]focus action: ', focused, selected);
if (isNil(focused) && not(isNil(selected))) {
focus(selected);
} else {