kk
This commit is contained in:
@@ -42,10 +42,22 @@ class Folder(Store):
|
||||
Dict[str,
|
||||
int]]] = {}
|
||||
|
||||
def __new__(cls, *args: Any, **kwargs: Any) -> "Folder":
|
||||
return super().__new__(cls)
|
||||
|
||||
setattr(__new__, "keys", ("NAME", "PATH"))
|
||||
@classmethod
|
||||
def config(cls) -> List[Dict[str, Any]]:
|
||||
return [
|
||||
{
|
||||
"key": "NAME",
|
||||
"label": "Store Name",
|
||||
"default": "",
|
||||
"required": True
|
||||
},
|
||||
{
|
||||
"key": "PATH",
|
||||
"label": "Folder Path",
|
||||
"default": "",
|
||||
"required": True
|
||||
}
|
||||
]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -29,6 +29,32 @@ class HydrusNetwork(Store):
|
||||
Maintains its own HydrusClient.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def config(cls) -> List[Dict[str, Any]]:
|
||||
return [
|
||||
{
|
||||
"key": "NAME",
|
||||
"label": "Store Name",
|
||||
"default": "",
|
||||
"placeholder": "e.g. home_hydrus",
|
||||
"required": True
|
||||
},
|
||||
{
|
||||
"key": "URL",
|
||||
"label": "Hydrus URL",
|
||||
"default": "http://127.0.0.1:45869",
|
||||
"placeholder": "http://127.0.0.1:45869",
|
||||
"required": True
|
||||
},
|
||||
{
|
||||
"key": "API",
|
||||
"label": "API Key",
|
||||
"default": "",
|
||||
"required": True,
|
||||
"secret": True
|
||||
}
|
||||
]
|
||||
|
||||
def _log_prefix(self) -> str:
|
||||
store_name = getattr(self, "NAME", None) or "unknown"
|
||||
return f"[hydrusnetwork:{store_name}]"
|
||||
@@ -46,8 +72,6 @@ class HydrusNetwork(Store):
|
||||
setattr(instance, "URL", str(url))
|
||||
return instance
|
||||
|
||||
setattr(__new__, "keys", ("NAME", "API", "URL"))
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
instance_name: Optional[str] = None,
|
||||
|
||||
@@ -12,6 +12,20 @@ from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
class Store(ABC):
|
||||
|
||||
@classmethod
|
||||
def config(cls) -> List[Dict[str, Any]]:
|
||||
"""Return configuration schema for this store.
|
||||
|
||||
Returns a list of dicts:
|
||||
{
|
||||
"key": "PATH",
|
||||
"label": "Store Location",
|
||||
"default": "",
|
||||
"required": True
|
||||
}
|
||||
"""
|
||||
return []
|
||||
|
||||
@abstractmethod
|
||||
def add_file(self, file_path: Path, **kwargs: Any) -> str:
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -80,6 +80,23 @@ def _discover_store_classes() -> Dict[str, Type[BaseStore]]:
|
||||
|
||||
|
||||
def _required_keys_for(store_cls: Type[BaseStore]) -> list[str]:
|
||||
# Support new config() schema
|
||||
if hasattr(store_cls, "config") and callable(store_cls.config):
|
||||
try:
|
||||
schema = store_cls.config()
|
||||
keys = []
|
||||
if isinstance(schema, list):
|
||||
for field in schema:
|
||||
if isinstance(field, dict) and field.get("required"):
|
||||
k = field.get("key")
|
||||
if k:
|
||||
keys.append(str(k))
|
||||
if keys:
|
||||
return keys
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Legacy __new__.keys support
|
||||
keys = getattr(store_cls.__new__, "keys", None)
|
||||
if keys is None:
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user