j
This commit is contained in:
@@ -3569,7 +3569,7 @@ class LocalLibrarySearchOptimizer:
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to update search result for {file_path}: {e}")
|
||||
|
||||
def search_by_tag(self, tag: str, limit: int = 100) -> List[Path]:
|
||||
def search_by_tag(self, tag: str, limit: int = 100) -> List[Dict[str, Any]]:
|
||||
"""Fast tag-based search using database."""
|
||||
if not self.db:
|
||||
return []
|
||||
@@ -3578,9 +3578,10 @@ class LocalLibrarySearchOptimizer:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT f.file_path
|
||||
SELECT f.hash, f.file_path, m.duration, m.size, m.type as media_kind, m.url
|
||||
FROM file f
|
||||
JOIN tag t ON f.hash = t.hash
|
||||
LEFT JOIN metadata m ON f.hash = m.hash
|
||||
WHERE t.tag LIKE ?
|
||||
LIMIT ?
|
||||
""",
|
||||
@@ -3588,11 +3589,47 @@ class LocalLibrarySearchOptimizer:
|
||||
limit),
|
||||
)
|
||||
|
||||
return [self.db._from_db_file_path(row[0]) for row in cursor.fetchall()]
|
||||
results = []
|
||||
for row in cursor.fetchall():
|
||||
res = dict(row)
|
||||
# Resolve path to absolute string for remote consumption
|
||||
res["file_path"] = str(self.db._from_db_file_path(res["file_path"]))
|
||||
results.append(res)
|
||||
return results
|
||||
except Exception as e:
|
||||
logger.error(f"Tag search failed: {e}")
|
||||
return []
|
||||
|
||||
def search_by_name(self, query: str, limit: int = 100) -> List[Dict[str, Any]]:
|
||||
"""Fast name-based search using database."""
|
||||
if not self.db:
|
||||
return []
|
||||
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT f.hash, f.file_path, m.duration, m.size, m.type as media_kind, m.url
|
||||
FROM file f
|
||||
LEFT JOIN metadata m ON f.hash = m.hash
|
||||
WHERE f.file_path LIKE ?
|
||||
LIMIT ?
|
||||
""",
|
||||
(f"%{query}%",
|
||||
limit),
|
||||
)
|
||||
|
||||
results = []
|
||||
for row in cursor.fetchall():
|
||||
res = dict(row)
|
||||
# Resolve path to absolute string for remote consumption
|
||||
res["file_path"] = str(self.db._from_db_file_path(res["file_path"]))
|
||||
results.append(res)
|
||||
return results
|
||||
except Exception as e:
|
||||
logger.error(f"Name search failed: {e}")
|
||||
return []
|
||||
|
||||
def save_playlist(self, name: str, items: List[Dict[str, Any]]) -> bool:
|
||||
"""Save a playlist to the database."""
|
||||
if not self.db:
|
||||
@@ -3705,9 +3742,6 @@ class LocalLibrarySearchOptimizer:
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to delete playlist ID {playlist_id}: {e}")
|
||||
return False
|
||||
if not self.db:
|
||||
return []
|
||||
return self.db.search_by_tag(tag, limit)
|
||||
|
||||
def search_by_hash(self, file_hash: str) -> Optional[Path]:
|
||||
"""Fast hash-based search using database."""
|
||||
|
||||
@@ -536,14 +536,16 @@ def discover_services_on_network(
|
||||
path = paths[0]
|
||||
url = f"{scheme}://{host}:{port}{path}"
|
||||
ok, code, payload = _probe_url(url, timeout=timeout, accept_json=accept_json)
|
||||
if ok:
|
||||
if ok or code == 401:
|
||||
hint = None
|
||||
try:
|
||||
# remote_storage_server returns {"status": "ok", ...}
|
||||
if isinstance(payload, dict) and payload.get("status"):
|
||||
if code == 401:
|
||||
hint = "remote_storage" # Most likely
|
||||
elif isinstance(payload, dict) and payload.get("status"):
|
||||
hint = "remote_storage"
|
||||
# hydrus returns {"api_version": ...}
|
||||
if isinstance(payload, dict) and payload.get("api_version"):
|
||||
elif isinstance(payload, dict) and payload.get("api_version"):
|
||||
hint = "hydrus"
|
||||
except Exception:
|
||||
pass
|
||||
@@ -553,7 +555,7 @@ def discover_services_on_network(
|
||||
port=int(port),
|
||||
path=path,
|
||||
url=url,
|
||||
ok=True,
|
||||
ok=(code == 200),
|
||||
status_code=code,
|
||||
payload=payload,
|
||||
service_hint=hint,
|
||||
|
||||
Reference in New Issue
Block a user