This commit is contained in:
2026-01-14 15:03:08 -08:00
parent 25c940351a
commit 0f726b11dc
2 changed files with 26 additions and 8 deletions

View File

@@ -242,11 +242,18 @@ class ZeroTier(Store):
# CLI prefers 'path' and 'size_bytes' # CLI prefers 'path' and 'size_bytes'
if "file_path" in f and "path" not in f: if "file_path" in f and "path" not in f:
f["path"] = f["file_path"] f["path"] = f["file_path"]
if "title" not in f:
# Try to extract title from tags
tags = f.get("tag") or []
title_tag = next((t for t in tags if str(t).lower().startswith("title:")), None)
if title_tag and ":" in title_tag:
f["title"] = title_tag.split(":", 1)[1].strip()
elif "title" not in f:
try: try:
f["title"] = Path(f["file_path"]).stem f["title"] = Path(f["file_path"]).stem
except Exception: except Exception:
f["title"] = f["file_path"] f["title"] = f["file_path"]
if "size" in f and "size_bytes" not in f: if "size" in f and "size_bytes" not in f:
f["size_bytes"] = f["size"] f["size_bytes"] = f["size"]
return files return files
@@ -364,6 +371,11 @@ class ZeroTier(Store):
res = self._request_remote("GET", f"/files/{file_hash}") res = self._request_remote("GET", f"/files/{file_hash}")
if isinstance(res, dict): if isinstance(res, dict):
# Extract title from tags for the details panel/metadata view
tags = res.get("tag") or []
title_tag = next((t for t in tags if str(t).lower().startswith("title:")), None)
if title_tag and ":" in title_tag:
res["title"] = title_tag.split(":", 1)[1].strip()
return res return res
return None return None

View File

@@ -233,7 +233,7 @@ def create_app():
@require_storage() @require_storage()
def search_files(): def search_files():
"""Search for files by name or tag.""" """Search for files by name or tag."""
from API.folder import LocalLibrarySearchOptimizer from API.folder import LocalLibrarySearchOptimizer, API_folder_store
query = request.args.get("q", "") query = request.args.get("q", "")
limit = request.args.get("limit", 100, type=int) limit = request.args.get("limit", 100, type=int)
@@ -242,20 +242,26 @@ def create_app():
db_query = query if query and query != "*" else "" db_query = query if query and query != "*" else ""
try: try:
with LocalLibrarySearchOptimizer(STORAGE_PATH) as db: with LocalLibrarySearchOptimizer(STORAGE_PATH) as search_db:
results = db.search_by_name(db_query, limit) results = search_db.search_by_name(db_query, limit)
tag_results = db.search_by_tag(db_query, limit) tag_results = search_db.search_by_tag(db_query, limit)
all_results = { all_results_dict = {
r["hash"]: r r["hash"]: r
for r in (results + tag_results) for r in (results + tag_results)
} }
# Fetch tags for each result to support title extraction on client
with API_folder_store(STORAGE_PATH) as db:
for res in all_results_dict.values():
if res.get("file_path"):
res["tag"] = db.get_tags(Path(res["file_path"]))
return ( return (
jsonify( jsonify(
{ {
"query": query, "query": query,
"count": len(all_results), "count": len(all_results_dict),
"files": list(all_results.values()), "files": list(all_results_dict.values()),
} }
), ),
200, 200,