feat: nomad

This commit is contained in:
2026-04-06 20:16:37 +02:00
parent 6e8a4af40d
commit d7e9788f99
5 changed files with 58 additions and 74 deletions

View File

@@ -181,16 +181,17 @@ def start_browser() -> None:
# Config helpers
# ---------------------------------------------------------------------------
def _rns_config_path() -> Path:
"""Return the path to the RNS config file."""
configdir = os.environ.get("RNS_CONFIG_DIR", str(Path.home() / ".reticulum"))
return Path(configdir) / "config"
_CONFIG_PATHS = {
"reticulum": lambda: Path(os.environ.get("RNS_SERVER_CONFIG_DIR", os.environ.get("RNS_CONFIG_DIR", str(Path.home() / ".reticulum")))) / "config",
"nomadnet": lambda: Path(os.environ.get("NOMADNET_CONFIG_DIR", str(Path.home() / ".nomadnetwork"))) / "config",
}
def _nomadnet_config_path() -> Path:
"""Return the path to the NomadNet config file."""
configdir = os.environ.get("NOMADNET_CONFIG_DIR", str(Path.home() / ".nomadnetwork"))
return Path(configdir) / "config"
def _config_path(kind: str) -> Path:
resolver = _CONFIG_PATHS.get(kind)
if not resolver:
raise ValueError(f"Unknown config kind: {kind}")
return resolver()
def _restart_nomadnet() -> bool:
@@ -405,46 +406,27 @@ async def _request_remote_page(hash_hex: str, path: str) -> str | None:
# Reticulum config endpoints
# ---------------------------------------------------------------------------
@router.get("/browse/config/reticulum")
async def get_reticulum_config():
"""Return the current Reticulum config file contents."""
path = _rns_config_path()
if not path.exists():
return {"content": ""}
return {"content": path.read_text(encoding="utf-8")}
@router.post("/browse/config/reticulum")
async def save_reticulum_config(body: dict):
"""Write Reticulum config."""
content = body.get("content", "")
path = _rns_config_path()
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content, encoding="utf-8")
return {"ok": True}
@router.get("/browse/config/nomadnet")
async def get_nomadnet_config():
"""Return the current NomadNet config file contents."""
path = _nomadnet_config_path()
if not path.exists():
return {"content": ""}
return {"content": path.read_text(encoding="utf-8")}
@router.post("/browse/config/nomadnet")
async def save_nomadnet_config(body: dict):
"""Write NomadNet config."""
content = body.get("content", "")
path = _nomadnet_config_path()
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content, encoding="utf-8")
return {"ok": True}
@router.post("/browse/config/restart")
@router.post("/browse/restart")
async def restart_services():
"""Restart NomadNet to apply config changes."""
restarted = _restart_nomadnet()
return {"ok": True, "nomadnet_restarted": restarted}
@router.get("/browse/config/{kind}")
async def get_config(kind: str):
"""Return config file contents for reticulum or nomadnet."""
path = _config_path(kind)
if not path.exists():
return {"content": ""}
return {"content": path.read_text(encoding="utf-8")}
@router.post("/browse/config/{kind}")
async def save_config(kind: str, body: dict):
"""Write config file for reticulum or nomadnet."""
content = body.get("content", "")
path = _config_path(kind)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content, encoding="utf-8")
return {"ok": True}