df
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
This commit is contained in:
@@ -169,6 +169,7 @@ def _extract_file_path(item: Any) -> Optional[str]:
|
||||
|
||||
Returns a filesystem path string only if it exists.
|
||||
"""
|
||||
|
||||
def _maybe_local_path(value: Any) -> Optional[str]:
|
||||
if value is None:
|
||||
return None
|
||||
@@ -225,7 +226,11 @@ def _extract_url(item: Any) -> Optional[str]:
|
||||
if isinstance(item, dict):
|
||||
for key in ("url", "source_url", "path", "target"):
|
||||
raw = item.get(key)
|
||||
if isinstance(raw, str) and raw.strip() and raw.strip().startswith(("http://", "https://")):
|
||||
if (
|
||||
isinstance(raw, str)
|
||||
and raw.strip()
|
||||
and raw.strip().startswith(("http://", "https://"))
|
||||
):
|
||||
return raw.strip()
|
||||
except Exception:
|
||||
pass
|
||||
@@ -264,7 +269,9 @@ def _extract_hash_from_hydrus_file_url(url: str) -> Optional[str]:
|
||||
return None
|
||||
|
||||
|
||||
def _maybe_download_hydrus_file(item: Any, config: Dict[str, Any], output_dir: Path) -> Optional[str]:
|
||||
def _maybe_download_hydrus_file(
|
||||
item: Any, config: Dict[str, Any], output_dir: Path
|
||||
) -> Optional[str]:
|
||||
"""If the item looks like a Hydrus file (hash + Hydrus URL), download it using Hydrus access key headers.
|
||||
|
||||
This avoids 401 from Hydrus when the URL is /get_files/file?hash=... without headers.
|
||||
@@ -307,18 +314,24 @@ def _maybe_download_hydrus_file(item: Any, config: Dict[str, Any], output_dir: P
|
||||
is_hydrus_url = False
|
||||
if url:
|
||||
parsed = urlparse(url)
|
||||
is_hydrus_url = (parsed.path or "").endswith("/get_files/file") and _extract_hash_from_hydrus_file_url(url) == file_hash
|
||||
is_hydrus_url = (parsed.path or "").endswith(
|
||||
"/get_files/file"
|
||||
) and _extract_hash_from_hydrus_file_url(url) == file_hash
|
||||
hydrus_instances: set[str] = set()
|
||||
try:
|
||||
store_cfg = (config or {}).get("store") if isinstance(config, dict) else None
|
||||
if isinstance(store_cfg, dict):
|
||||
hydrus_cfg = store_cfg.get("hydrusnetwork")
|
||||
if isinstance(hydrus_cfg, dict):
|
||||
hydrus_instances = {str(k).strip().lower() for k in hydrus_cfg.keys() if str(k).strip()}
|
||||
hydrus_instances = {
|
||||
str(k).strip().lower() for k in hydrus_cfg.keys() if str(k).strip()
|
||||
}
|
||||
except Exception:
|
||||
hydrus_instances = set()
|
||||
|
||||
store_hint = store_name.lower() in {"hydrus", "hydrusnetwork"} or (store_name.lower() in hydrus_instances)
|
||||
store_hint = store_name.lower() in {"hydrus", "hydrusnetwork"} or (
|
||||
store_name.lower() in hydrus_instances
|
||||
)
|
||||
if not (is_hydrus_url or store_hint):
|
||||
return None
|
||||
|
||||
@@ -402,7 +415,11 @@ def _resolve_upload_path(item: Any, config: Dict[str, Any]) -> Optional[str]:
|
||||
base_tmp = None
|
||||
if isinstance(config, dict):
|
||||
base_tmp = config.get("temp")
|
||||
output_dir = Path(str(base_tmp)).expanduser() if base_tmp else (Path(tempfile.gettempdir()) / "Medios-Macina")
|
||||
output_dir = (
|
||||
Path(str(base_tmp)).expanduser()
|
||||
if base_tmp
|
||||
else (Path(tempfile.gettempdir()) / "Medios-Macina")
|
||||
)
|
||||
output_dir = output_dir / "matrix" / "hydrus"
|
||||
hydrus_path = _maybe_download_hydrus_file(item, config, output_dir)
|
||||
if hydrus_path:
|
||||
@@ -423,11 +440,20 @@ def _resolve_upload_path(item: Any, config: Dict[str, Any]) -> Optional[str]:
|
||||
base_tmp = None
|
||||
if isinstance(config, dict):
|
||||
base_tmp = config.get("temp")
|
||||
output_dir = Path(str(base_tmp)).expanduser() if base_tmp else (Path(tempfile.gettempdir()) / "Medios-Macina")
|
||||
output_dir = (
|
||||
Path(str(base_tmp)).expanduser()
|
||||
if base_tmp
|
||||
else (Path(tempfile.gettempdir()) / "Medios-Macina")
|
||||
)
|
||||
output_dir = output_dir / "matrix"
|
||||
output_dir.mkdir(parents=True, exist_ok=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():
|
||||
if (
|
||||
result
|
||||
and hasattr(result, "path")
|
||||
and isinstance(result.path, Path)
|
||||
and result.path.exists()
|
||||
):
|
||||
return str(result.path)
|
||||
except Exception as exc:
|
||||
debug(f"[matrix] Failed to download URL for upload: {exc}")
|
||||
@@ -467,6 +493,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
return 1
|
||||
|
||||
from Provider.matrix import Matrix
|
||||
|
||||
try:
|
||||
provider = Matrix(config)
|
||||
except Exception as exc:
|
||||
@@ -490,7 +517,10 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
file_path = _resolve_upload_path(item, config)
|
||||
if not file_path:
|
||||
any_failed = True
|
||||
log("Matrix upload requires a local file (path) or a direct URL on the selected item", file=sys.stderr)
|
||||
log(
|
||||
"Matrix upload requires a local file (path) or a direct URL on the selected item",
|
||||
file=sys.stderr,
|
||||
)
|
||||
continue
|
||||
|
||||
media_path = Path(file_path)
|
||||
@@ -561,6 +591,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
pass
|
||||
|
||||
from Provider.matrix import Matrix
|
||||
|
||||
try:
|
||||
provider = Matrix(config)
|
||||
except Exception as exc:
|
||||
@@ -581,7 +612,9 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
|
||||
# Diagnostics if a configured filter yields no rows (provider filtered before name lookups for speed).
|
||||
if not rooms and not _has_flag(args, "-all"):
|
||||
configured_ids_dbg = [str(v).strip() for v in _parse_config_room_filter_ids(config) if str(v).strip()]
|
||||
configured_ids_dbg = [
|
||||
str(v).strip() for v in _parse_config_room_filter_ids(config) if str(v).strip()
|
||||
]
|
||||
if configured_ids_dbg:
|
||||
try:
|
||||
joined_ids = provider.list_joined_room_ids()
|
||||
@@ -592,7 +625,10 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
|
||||
if not rooms:
|
||||
if _parse_config_room_filter_ids(config) and not _has_flag(args, "-all"):
|
||||
log("No joined rooms matched the configured Matrix room filter (use: .matrix -all)", file=sys.stderr)
|
||||
log(
|
||||
"No joined rooms matched the configured Matrix room filter (use: .matrix -all)",
|
||||
file=sys.stderr,
|
||||
)
|
||||
else:
|
||||
log("No joined rooms found.", file=sys.stderr)
|
||||
return 0
|
||||
@@ -630,15 +666,31 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
ctx.set_pending_pipeline_tail([[".matrix", "-send"]], ".matrix")
|
||||
return 0
|
||||
|
||||
|
||||
CMDLET = Cmdlet(
|
||||
name=".matrix",
|
||||
alias=["matrix", "rooms"],
|
||||
summary="Send selected items to a Matrix room",
|
||||
usage="@N | .matrix",
|
||||
arg=[
|
||||
CmdletArg(name="send", type="bool", description="(internal) Send to selected room(s)", required=False),
|
||||
CmdletArg(name="all", type="bool", description="Ignore config room filter and show all joined rooms", required=False),
|
||||
CmdletArg(name="text", type="string", description="Send a follow-up text message after each upload (caption-like)", required=False),
|
||||
CmdletArg(
|
||||
name="send",
|
||||
type="bool",
|
||||
description="(internal) Send to selected room(s)",
|
||||
required=False,
|
||||
),
|
||||
CmdletArg(
|
||||
name="all",
|
||||
type="bool",
|
||||
description="Ignore config room filter and show all joined rooms",
|
||||
required=False,
|
||||
),
|
||||
CmdletArg(
|
||||
name="text",
|
||||
type="string",
|
||||
description="Send a follow-up text message after each upload (caption-like)",
|
||||
required=False,
|
||||
),
|
||||
],
|
||||
exec=_run
|
||||
exec=_run,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user