This commit is contained in:
nose
2025-12-11 23:21:45 -08:00
parent 16d8a763cd
commit e2ffcab030
44 changed files with 3558 additions and 1793 deletions

View File

@@ -11,7 +11,7 @@ from typing import Any, Dict, List, Optional, Tuple
from SYS.logger import debug, log
from SYS.utils import sha256_file
from Store._base import StoreBackend
from Store._base import Store
def _normalize_hash(value: Any) -> Optional[str]:
@@ -30,7 +30,7 @@ def _resolve_file_hash(db_hash: Optional[str], file_path: Path) -> Optional[str]
return _normalize_hash(file_path.stem)
class Folder(StoreBackend):
class Folder(Store):
""""""
# Track which locations have already been migrated to avoid repeated migrations
_migrated_locations = set()
@@ -243,7 +243,7 @@ class Folder(StoreBackend):
Args:
file_path: Path to the file to add
move: If True, move file instead of copy (default: False)
tags: Optional list of tags to add
tag: Optional list of tag values to add
url: Optional list of url to associate with the file
title: Optional title (will be added as 'title:value' tag)
@@ -251,15 +251,15 @@ class Folder(StoreBackend):
File hash (SHA256 hex string) as identifier
"""
move_file = bool(kwargs.get("move"))
tags = kwargs.get("tags", [])
tag_list = kwargs.get("tag", [])
url = kwargs.get("url", [])
title = kwargs.get("title")
# Extract title from tags if not explicitly provided
if not title:
for tag in tags:
if isinstance(tag, str) and tag.lower().startswith("title:"):
title = tag.split(":", 1)[1].strip()
for candidate in tag_list:
if isinstance(candidate, str) and candidate.lower().startswith("title:"):
title = candidate.split(":", 1)[1].strip()
break
# Fallback to filename if no title
@@ -268,8 +268,8 @@ class Folder(StoreBackend):
# Ensure title is in tags
title_tag = f"title:{title}"
if not any(str(tag).lower().startswith("title:") for tag in tags):
tags = [title_tag] + list(tags)
if not any(str(candidate).lower().startswith("title:") for candidate in tag_list):
tag_list = [title_tag] + list(tag_list)
try:
file_hash = sha256_file(file_path)
@@ -290,8 +290,8 @@ class Folder(StoreBackend):
file=sys.stderr,
)
# Still add tags and url if provided
if tags:
self.add_tag(file_hash, tags)
if tag_list:
self.add_tag(file_hash, tag_list)
if url:
self.add_url(file_hash, url)
return file_hash
@@ -316,8 +316,8 @@ class Folder(StoreBackend):
})
# Add tags if provided
if tags:
self.add_tag(file_hash, tags)
if tag_list:
self.add_tag(file_hash, tag_list)
# Add url if provided
if url:
@@ -330,7 +330,7 @@ class Folder(StoreBackend):
log(f"❌ Local storage failed: {exc}", file=sys.stderr)
raise
def search_store(self, query: str, **kwargs: Any) -> list[Dict[str, Any]]:
def search(self, query: str, **kwargs: Any) -> list[Dict[str, Any]]:
"""Search local database for files by title tag or filename."""
from fnmatch import fnmatch
from API.folder import DatabaseAPI
@@ -685,9 +685,6 @@ class Folder(StoreBackend):
log(f"❌ Local search failed: {exc}", file=sys.stderr)
raise
def search(self, query: str, **kwargs: Any) -> list[Dict[str, Any]]:
"""Alias for search_file to match the interface expected by FileStorage."""
return self.search_store(query, **kwargs)
def _resolve_library_root(self, file_path: Path, config: Dict[str, Any]) -> Optional[Path]:
"""Return the library root containing medios-macina.db.