mirror of
https://github.com/Such-Software/adaptive-multi-protocol-browser.git
synced 2026-10-19 15:28:33 +02:00
Add IPFS dry-run adapter support
This commit is contained in:
+20
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user