Add IPFS dry-run adapter support

This commit is contained in:
jwinterm
2026-07-05 21:05:46 -04:00
parent a8cb056225
commit 3a51468d29
24 changed files with 169 additions and 33 deletions
+20 -1
View File
@@ -14,6 +14,10 @@ class Route:
def route_url(raw_url: str) -> Route:
path_route = _route_path_address(raw_url)
if path_route:
return path_route
normalized = _normalize_url(raw_url)
parsed = urlparse(normalized)
scheme = parsed.scheme.lower()
@@ -21,6 +25,8 @@ def route_url(raw_url: str) -> Route:
if scheme == "gemini":
return Route(raw_url, normalized, "gemini", "gemini", "gemini scheme")
if scheme in {"ipfs", "ipns"}:
return Route(raw_url, normalized, "ipfs", "ipfs", f"{scheme} scheme")
if scheme in {"rns", "lxmf", "nomad"}:
return Route(raw_url, normalized, "reticulum", "reticulum", f"{scheme} scheme")
if host.endswith(".onion"):
@@ -34,6 +40,19 @@ def route_url(raw_url: str) -> Route:
def _normalize_url(raw_url: str) -> str:
value = raw_url.strip()
if "://" not in value and not value.startswith(("rns:", "lxmf:")):
if "://" not in value and not value.startswith(("rns:", "lxmf:", "ipfs:", "ipns:")):
value = "https://" + value
return value
def _route_path_address(raw_url: str) -> Route | None:
value = raw_url.strip()
if value.startswith("/ipfs/"):
cid = value.removeprefix("/ipfs/").strip("/")
normalized = f"ipfs://{cid}" if cid else "ipfs://"
return Route(raw_url, normalized, "ipfs", "ipfs", "/ipfs path")
if value.startswith("/ipns/"):
name = value.removeprefix("/ipns/").strip("/")
normalized = f"ipns://{name}" if name else "ipns://"
return Route(raw_url, normalized, "ipfs", "ipfs", "/ipns path")
return None