feat: rename is_image to has_thumbnail in VfsEntry and update related logic

This commit is contained in:
ShiYu
2025-10-18 16:12:55 +08:00
parent c14224827d
commit 11799cd97c
6 changed files with 14 additions and 11 deletions

View File

@@ -8,7 +8,7 @@ class VfsEntry(BaseModel):
size: int
mtime: int
type: Optional[str] = None
is_image: Optional[bool] = None
has_thumbnail: Optional[bool] = None
class DirListing(BaseModel):

View File

@@ -171,9 +171,9 @@ async def list_virtual_dir(path: str, page_num: int = 1, page_size: int = 50, so
def annotate_entry(entry: Dict) -> None:
if not entry.get("is_dir"):
entry["is_image"] = is_image_filename(entry.get("name", ""))
entry["has_thumbnail"] = is_image_filename(entry.get("name", ""))
else:
entry["is_image"] = False
entry["has_thumbnail"] = False
try:
adapter_model, rel = await resolve_adapter_by_path(norm)
@@ -225,13 +225,13 @@ async def list_virtual_dir(path: str, page_num: int = 1, page_size: int = 50, so
for name in child_mount_entries:
if name not in covered:
mount_entries.append({"name": name, "is_dir": True,
"size": 0, "mtime": 0, "type": "mount", "is_image": False})
"size": 0, "mtime": 0, "type": "mount", "has_thumbnail": False})
if mount_entries:
for ent in adapter_entries_for_merge:
annotate_entry(ent)
combined_entries = adapter_entries_for_merge + [
{**ent, "is_image": False} for ent in mount_entries
{**ent, "has_thumbnail": False} for ent in mount_entries
]
combined_entries.sort(key=build_sort_key, reverse=reverse)
@@ -596,6 +596,9 @@ async def stat_file(path: str):
is_dir = bool(info.get("is_dir"))
except Exception:
is_dir = False
rel_name = rel.rstrip('/').split('/')[-1] if rel else path.rstrip('/').split('/')[-1]
name_hint = info.get("name") or rel_name
info["has_thumbnail"] = bool(not is_dir and is_image_filename(str(name_hint or "")))
if not is_dir:
vector_index = await _gather_vector_index(path)
if vector_index is not None:

View File

@@ -6,7 +6,7 @@ export interface VfsEntry {
size: number;
mtime: number;
type?: string;
is_image?: boolean;
has_thumbnail?: boolean;
}
export interface DirListing {

View File

@@ -54,8 +54,8 @@ const DEFAULT_TONE: RgbColor = { r: 28, g: 32, b: 46 };
const isImageEntry = (ent: VfsEntry) => {
if (ent.is_dir) return false;
const maybe = ent as VfsEntry & { is_image?: boolean };
if (typeof maybe.is_image === 'boolean' && maybe.is_image) return true;
const maybe = ent as VfsEntry & { has_thumbnail?: boolean };
if (typeof maybe.has_thumbnail === 'boolean' && maybe.has_thumbnail) return true;
const ext = ent.name.split('.').pop()?.toLowerCase();
if (!ext) return false;
return ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'avif', 'ico', 'tif', 'tiff', 'svg', 'heic', 'heif', 'arw', 'cr2', 'cr3', 'nef', 'rw2', 'orf', 'pef', 'dng'].includes(ext);

View File

@@ -221,7 +221,7 @@ const SearchDialog: React.FC<SearchDialogProps> = ({ open, onClose }) => {
size: Number((stat as any)?.size ?? 0),
mtime: Number((stat as any)?.mtime ?? (stat as any)?.mtime_ms ?? 0),
type: (stat as any)?.type,
is_image: Boolean((stat as any)?.is_image),
has_thumbnail: Boolean((stat as any)?.has_thumbnail),
};
statCacheRef.current.set(fullPath, entry);
return entry;

View File

@@ -13,7 +13,7 @@ export function useThumbnails(entries: VfsEntry[], path: string) {
useEffect(() => {
const newThumbs: Record<string, string> = {};
const targets = entries.filter(e => !e.is_dir && (e as any).is_image && !thumbs[e.name]);
const targets = entries.filter(e => !e.is_dir && (e as any).has_thumbnail && !thumbs[e.name]);
if (targets.length > 0) {
targets.forEach(ent => {
@@ -37,4 +37,4 @@ export function useThumbnails(entries: VfsEntry[], path: string) {
}, [entries, path, thumbs]);
return { thumbs };
}
}