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

@@ -8,10 +8,10 @@ from typing import Any, Dict, List, Optional, Tuple
from SYS.logger import debug, log
from SYS.utils_constant import mime_maps
from Store._base import StoreBackend
from Store._base import Store
class HydrusNetwork(StoreBackend):
class HydrusNetwork(Store):
"""File storage backend for Hydrus client.
Each instance represents a specific Hydrus client connection.
@@ -26,7 +26,7 @@ class HydrusNetwork(StoreBackend):
api_key: Hydrus Client API access key
url: Hydrus client URL (e.g., 'http://192.168.1.230:45869')
"""
from API.HydrusNetwork import HydrusClient
from API.HydrusNetwork import HydrusNetwork as HydrusClient
self._instance_name = instance_name
self._api_key = api_key
@@ -45,7 +45,7 @@ class HydrusNetwork(StoreBackend):
Args:
file_path: Path to the file to upload
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)
@@ -57,15 +57,15 @@ class HydrusNetwork(StoreBackend):
"""
from SYS.utils import sha256_file
tags = kwargs.get("tags", [])
tag_list = kwargs.get("tag", [])
url = kwargs.get("url", [])
title = kwargs.get("title")
# Add title to tags if provided and not already present
if title:
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:
# Compute file hash
@@ -113,7 +113,7 @@ class HydrusNetwork(StoreBackend):
log(f"Hydrus: {file_hash}", file=sys.stderr)
# Add tags if provided (both for new and existing files)
if tags:
if tag_list:
try:
# Use default tag service
service_name = "my tags"
@@ -121,8 +121,8 @@ class HydrusNetwork(StoreBackend):
service_name = "my tags"
try:
debug(f"Adding {len(tags)} tag(s) to Hydrus: {tags}")
client.add_tags(file_hash, tags, service_name)
debug(f"Adding {len(tag_list)} tag(s) to Hydrus: {tag_list}")
client.add_tag(file_hash, tag_list, service_name)
log(f"Tags added via '{service_name}'", file=sys.stderr)
except Exception as exc:
log(f"⚠️ Failed to add tags: {exc}", file=sys.stderr)
@@ -144,7 +144,7 @@ class HydrusNetwork(StoreBackend):
log(f"❌ Hydrus upload 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 Hydrus database for files matching query.
Args:
@@ -290,7 +290,7 @@ class HydrusNetwork(StoreBackend):
"size": size,
"size_bytes": size,
"store": self._instance_name,
"tags": all_tags,
"tag": all_tags,
"file_id": file_id,
"mime": mime_type,
"ext": ext,
@@ -323,7 +323,7 @@ class HydrusNetwork(StoreBackend):
"size": size,
"size_bytes": size,
"store": self._instance_name,
"tags": all_tags,
"tag": all_tags,
"file_id": file_id,
"mime": mime_type,
"ext": ext,
@@ -488,7 +488,7 @@ class HydrusNetwork(StoreBackend):
tag_list = list(tags) if isinstance(tags, (list, tuple)) else [str(tags)]
if not tag_list:
return False
client.add_tags(file_identifier, tag_list, service_name)
client.add_tag(file_identifier, tag_list, service_name)
return True
except Exception as exc:
debug(f"Hydrus add_tag failed: {exc}")
@@ -506,7 +506,7 @@ class HydrusNetwork(StoreBackend):
tag_list = list(tags) if isinstance(tags, (list, tuple)) else [str(tags)]
if not tag_list:
return False
client.delete_tags(file_identifier, tag_list, service_name)
client.delete_tag(file_identifier, tag_list, service_name)
return True
except Exception as exc:
debug(f"Hydrus delete_tag failed: {exc}")