k
This commit is contained in:
@@ -233,7 +233,23 @@ class ZeroTier(Store):
|
||||
params = {"q": query, "limit": int(kwargs.get("limit", 100))}
|
||||
res = self._request_remote("GET", "/files/search", params=params)
|
||||
if isinstance(res, dict):
|
||||
return list(res.get("files") or [])
|
||||
files = list(res.get("files") or [])
|
||||
# Inject store name and normalize keys for the CLI
|
||||
for f in files:
|
||||
if isinstance(f, dict):
|
||||
f["store"] = self._name
|
||||
# remote_storage_server returns 'file_path' and 'size'
|
||||
# CLI prefers 'path' and 'size_bytes'
|
||||
if "file_path" in f and "path" not in f:
|
||||
f["path"] = f["file_path"]
|
||||
if "title" not in f:
|
||||
try:
|
||||
f["title"] = Path(f["file_path"]).stem
|
||||
except Exception:
|
||||
f["title"] = f["file_path"]
|
||||
if "size" in f and "size_bytes" not in f:
|
||||
f["size_bytes"] = f["size"]
|
||||
return files
|
||||
return []
|
||||
|
||||
def get_file(self, file_hash: str, **kwargs: Any) -> Optional[Path | str]:
|
||||
|
||||
@@ -44,7 +44,8 @@ from SYS import pipeline as ctx
|
||||
|
||||
STORAGE_ORIGINS = {"local",
|
||||
"hydrus",
|
||||
"folder"}
|
||||
"folder",
|
||||
"zerotier"}
|
||||
|
||||
|
||||
class search_file(Cmdlet):
|
||||
@@ -887,11 +888,24 @@ class search_file(Cmdlet):
|
||||
store_val = str(item_dict.get("store") or "").lower()
|
||||
if store_filter != store_val:
|
||||
continue
|
||||
|
||||
# Normalize storage results (ensure title, ext, etc.)
|
||||
normalized = self._ensure_storage_columns(item_dict)
|
||||
|
||||
# If normalize skipped it due to STORAGE_ORIGINS, do it manually
|
||||
if "title" not in normalized:
|
||||
normalized["title"] = (
|
||||
item_dict.get("title") or item_dict.get("name") or
|
||||
item_dict.get("path") or item_dict.get("target") or "Result"
|
||||
)
|
||||
if "ext" not in normalized:
|
||||
t = str(normalized.get("title", ""))
|
||||
if "." in t:
|
||||
normalized["ext"] = t.split(".")[-1].lower()[:5]
|
||||
|
||||
# Make hash/store available for downstream cmdlet without rerunning search
|
||||
hash_val = normalized.get("hash")
|
||||
store_val = normalized.get("store") or item_dict.get("store")
|
||||
store_val = normalized.get("store") or item_dict.get("store") or backend_to_search
|
||||
if hash_val and not normalized.get("hash"):
|
||||
normalized["hash"] = hash_val
|
||||
if store_val and not normalized.get("store"):
|
||||
|
||||
@@ -204,6 +204,8 @@ def create_app():
|
||||
"""Check server health and storage availability."""
|
||||
status = {
|
||||
"status": "ok",
|
||||
"service": "remote_storage",
|
||||
"name": os.environ.get("MM_SERVER_NAME", "Remote Storage"),
|
||||
"storage_configured": STORAGE_PATH is not None,
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
}
|
||||
@@ -236,13 +238,13 @@ def create_app():
|
||||
query = request.args.get("q", "")
|
||||
limit = request.args.get("limit", 100, type=int)
|
||||
|
||||
if not query:
|
||||
return jsonify({"error": "Search query required"}), 400
|
||||
# Allow empty query or '*' for "list everything"
|
||||
db_query = query if query and query != "*" else ""
|
||||
|
||||
try:
|
||||
with LocalLibrarySearchOptimizer(STORAGE_PATH) as db:
|
||||
results = db.search_by_name(query, limit)
|
||||
tag_results = db.search_by_tag(query, limit)
|
||||
results = db.search_by_name(db_query, limit)
|
||||
tag_results = db.search_by_tag(db_query, limit)
|
||||
all_results = {
|
||||
r["hash"]: r
|
||||
for r in (results + tag_results)
|
||||
|
||||
Reference in New Issue
Block a user