update and cleanup repo
This commit is contained in:
+35
-42
@@ -58,8 +58,30 @@ def _extract_set_value_arg(args: Sequence[str]) -> Optional[str]:
|
||||
return extract_arg_value(args, flags={"-set-value"})
|
||||
|
||||
|
||||
def _get_matrix_config_block(config: Dict[str, Any]) -> Dict[str, Any]:
|
||||
if not isinstance(config, dict):
|
||||
return {}
|
||||
plugins = config.get("plugin")
|
||||
if not isinstance(plugins, dict):
|
||||
return {}
|
||||
matrix_cfg = plugins.get("matrix")
|
||||
return matrix_cfg if isinstance(matrix_cfg, dict) else {}
|
||||
|
||||
|
||||
def _ensure_matrix_config_block(config: Dict[str, Any]) -> Dict[str, Any]:
|
||||
plugins = config.setdefault("plugin", {})
|
||||
if not isinstance(plugins, dict):
|
||||
plugins = {}
|
||||
config["plugin"] = plugins
|
||||
matrix_cfg = plugins.setdefault("matrix", {})
|
||||
if not isinstance(matrix_cfg, dict):
|
||||
matrix_cfg = {}
|
||||
plugins["matrix"] = matrix_cfg
|
||||
return matrix_cfg
|
||||
|
||||
|
||||
def _update_matrix_config(config: Dict[str, Any], key: str, value: Any) -> bool:
|
||||
"""Update the Matrix provider block in the shared config.
|
||||
"""Update the Matrix plugin block in the shared config.
|
||||
|
||||
This method writes to the unified config store so changes persist between
|
||||
sessions.
|
||||
@@ -71,29 +93,13 @@ def _update_matrix_config(config: Dict[str, Any], key: str, value: Any) -> bool:
|
||||
value_str = str(value)
|
||||
|
||||
current_cfg = load_config() or {}
|
||||
providers = current_cfg.setdefault("provider", {})
|
||||
if not isinstance(providers, dict):
|
||||
providers = {}
|
||||
current_cfg["provider"] = providers
|
||||
|
||||
matrix_cfg = providers.setdefault("matrix", {})
|
||||
if not isinstance(matrix_cfg, dict):
|
||||
matrix_cfg = {}
|
||||
providers["matrix"] = matrix_cfg
|
||||
|
||||
matrix_cfg = _ensure_matrix_config_block(current_cfg)
|
||||
matrix_cfg[key] = value_str
|
||||
|
||||
save_config(current_cfg)
|
||||
|
||||
# Keep the supplied config dict in sync for the running CLI
|
||||
target_providers = config.setdefault("provider", {})
|
||||
if not isinstance(target_providers, dict):
|
||||
target_providers = {}
|
||||
config["provider"] = target_providers
|
||||
target_matrix = target_providers.setdefault("matrix", {})
|
||||
if not isinstance(target_matrix, dict):
|
||||
target_matrix = {}
|
||||
target_providers["matrix"] = target_matrix
|
||||
target_matrix = _ensure_matrix_config_block(config)
|
||||
target_matrix[key] = value_str
|
||||
return True
|
||||
except Exception as exc:
|
||||
@@ -103,13 +109,8 @@ def _update_matrix_config(config: Dict[str, Any], key: str, value: Any) -> bool:
|
||||
|
||||
def _parse_config_room_filter_ids(config: Dict[str, Any]) -> List[str]:
|
||||
try:
|
||||
if not isinstance(config, dict):
|
||||
return []
|
||||
providers = config.get("provider")
|
||||
if not isinstance(providers, dict):
|
||||
return []
|
||||
matrix_conf = providers.get("matrix")
|
||||
if not isinstance(matrix_conf, dict):
|
||||
matrix_conf = _get_matrix_config_block(config)
|
||||
if not matrix_conf:
|
||||
return []
|
||||
raw = None
|
||||
# Support a few common spellings; `room` is the documented key.
|
||||
@@ -138,16 +139,11 @@ def _parse_config_room_filter_ids(config: Dict[str, Any]) -> List[str]:
|
||||
def _get_matrix_size_limit_bytes(config: Dict[str, Any]) -> Optional[int]:
|
||||
"""Return max allowed per-file size in bytes for Matrix uploads.
|
||||
|
||||
Config: [provider=Matrix] size_limit=50 # MB
|
||||
Config: [plugin=matrix] size_limit=50 # MB
|
||||
"""
|
||||
try:
|
||||
if not isinstance(config, dict):
|
||||
return None
|
||||
providers = config.get("provider")
|
||||
if not isinstance(providers, dict):
|
||||
return None
|
||||
matrix_conf = providers.get("matrix")
|
||||
if not isinstance(matrix_conf, dict):
|
||||
matrix_conf = _get_matrix_config_block(config)
|
||||
if not matrix_conf:
|
||||
return None
|
||||
|
||||
raw = None
|
||||
@@ -236,7 +232,7 @@ def _resolve_room_identifier(value: str, config: Dict[str, Any]) -> Optional[str
|
||||
conf_ids = _parse_config_room_filter_ids(config)
|
||||
if conf_ids:
|
||||
# Attempt to fetch names for the configured IDs
|
||||
block = config.get("provider", {}).get("matrix", {})
|
||||
block = _get_matrix_config_block(config)
|
||||
if block and block.get("homeserver") and block.get("access_token"):
|
||||
try:
|
||||
m = _get_matrix_provider(config)
|
||||
@@ -252,7 +248,7 @@ def _resolve_room_identifier(value: str, config: Dict[str, Any]) -> Optional[str
|
||||
pass
|
||||
|
||||
# Last resort: attempt to ask the server for matching rooms (if possible)
|
||||
block = config.get("provider", {}).get("matrix", {})
|
||||
block = _get_matrix_config_block(config)
|
||||
if block and block.get("homeserver") and block.get("access_token"):
|
||||
try:
|
||||
m = _get_matrix_provider(config)
|
||||
@@ -631,7 +627,7 @@ def _resolve_upload_path(item: Any, config: Dict[str, Any]) -> Optional[str]:
|
||||
url = _resolve_plugin_url(url, config)
|
||||
|
||||
try:
|
||||
from API.HTTP import _download_direct_file
|
||||
from API.HTTP import download_direct_file
|
||||
|
||||
base_tmp = None
|
||||
if isinstance(config, dict):
|
||||
@@ -642,7 +638,7 @@ def _resolve_upload_path(item: Any, config: Dict[str, Any]) -> Optional[str]:
|
||||
)
|
||||
output_dir = output_dir / "matrix"
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
result = _download_direct_file(url, output_dir, quiet=True)
|
||||
result = download_direct_file(url, output_dir, quiet=True)
|
||||
if (result and hasattr(result,
|
||||
"path") and isinstance(result.path,
|
||||
Path) and result.path.exists()):
|
||||
@@ -691,10 +687,7 @@ def _show_settings_table(config: Dict[str, Any]) -> int:
|
||||
|
||||
matrix_conf = {}
|
||||
try:
|
||||
if isinstance(config, dict):
|
||||
providers = config.get("provider")
|
||||
if isinstance(providers, dict):
|
||||
matrix_conf = providers.get("matrix") or {}
|
||||
matrix_conf = _get_matrix_config_block(config)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user