mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-09-05 23:57:19 +08:00
feat: rename is_image to has_thumbnail in VfsEntry and update related logic
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ class VfsEntry(BaseModel):
|
|||||||
size: int
|
size: int
|
||||||
mtime: int
|
mtime: int
|
||||||
type: Optional[str] = None
|
type: Optional[str] = None
|
||||||
is_image: Optional[bool] = None
|
has_thumbnail: Optional[bool] = None
|
||||||
|
|
||||||
|
|
||||||
class DirListing(BaseModel):
|
class DirListing(BaseModel):
|
||||||
|
|||||||
@@ -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:
|
def annotate_entry(entry: Dict) -> None:
|
||||||
if not entry.get("is_dir"):
|
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:
|
else:
|
||||||
entry["is_image"] = False
|
entry["has_thumbnail"] = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
adapter_model, rel = await resolve_adapter_by_path(norm)
|
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:
|
for name in child_mount_entries:
|
||||||
if name not in covered:
|
if name not in covered:
|
||||||
mount_entries.append({"name": name, "is_dir": True,
|
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:
|
if mount_entries:
|
||||||
for ent in adapter_entries_for_merge:
|
for ent in adapter_entries_for_merge:
|
||||||
annotate_entry(ent)
|
annotate_entry(ent)
|
||||||
combined_entries = adapter_entries_for_merge + [
|
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)
|
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"))
|
is_dir = bool(info.get("is_dir"))
|
||||||
except Exception:
|
except Exception:
|
||||||
is_dir = False
|
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:
|
if not is_dir:
|
||||||
vector_index = await _gather_vector_index(path)
|
vector_index = await _gather_vector_index(path)
|
||||||
if vector_index is not None:
|
if vector_index is not None:
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ export interface VfsEntry {
|
|||||||
size: number;
|
size: number;
|
||||||
mtime: number;
|
mtime: number;
|
||||||
type?: string;
|
type?: string;
|
||||||
is_image?: boolean;
|
has_thumbnail?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DirListing {
|
export interface DirListing {
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ const DEFAULT_TONE: RgbColor = { r: 28, g: 32, b: 46 };
|
|||||||
|
|
||||||
const isImageEntry = (ent: VfsEntry) => {
|
const isImageEntry = (ent: VfsEntry) => {
|
||||||
if (ent.is_dir) return false;
|
if (ent.is_dir) return false;
|
||||||
const maybe = ent as VfsEntry & { is_image?: boolean };
|
const maybe = ent as VfsEntry & { has_thumbnail?: boolean };
|
||||||
if (typeof maybe.is_image === 'boolean' && maybe.is_image) return true;
|
if (typeof maybe.has_thumbnail === 'boolean' && maybe.has_thumbnail) return true;
|
||||||
const ext = ent.name.split('.').pop()?.toLowerCase();
|
const ext = ent.name.split('.').pop()?.toLowerCase();
|
||||||
if (!ext) return false;
|
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);
|
return ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'avif', 'ico', 'tif', 'tiff', 'svg', 'heic', 'heif', 'arw', 'cr2', 'cr3', 'nef', 'rw2', 'orf', 'pef', 'dng'].includes(ext);
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ const SearchDialog: React.FC<SearchDialogProps> = ({ open, onClose }) => {
|
|||||||
size: Number((stat as any)?.size ?? 0),
|
size: Number((stat as any)?.size ?? 0),
|
||||||
mtime: Number((stat as any)?.mtime ?? (stat as any)?.mtime_ms ?? 0),
|
mtime: Number((stat as any)?.mtime ?? (stat as any)?.mtime_ms ?? 0),
|
||||||
type: (stat as any)?.type,
|
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);
|
statCacheRef.current.set(fullPath, entry);
|
||||||
return entry;
|
return entry;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export function useThumbnails(entries: VfsEntry[], path: string) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const newThumbs: Record<string, string> = {};
|
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) {
|
if (targets.length > 0) {
|
||||||
targets.forEach(ent => {
|
targets.forEach(ent => {
|
||||||
@@ -37,4 +37,4 @@ export function useThumbnails(entries: VfsEntry[], path: string) {
|
|||||||
}, [entries, path, thumbs]);
|
}, [entries, path, thumbs]);
|
||||||
|
|
||||||
return { thumbs };
|
return { thumbs };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user