feat: add settings
This commit is contained in:
@@ -177,6 +177,37 @@ def start_browser() -> None:
|
||||
log.warning("Failed to start RNS browser: %s", exc)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 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"
|
||||
|
||||
|
||||
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 _restart_nomadnet() -> bool:
|
||||
"""Restart the NomadNet container. Returns True on success."""
|
||||
try:
|
||||
from docker_utils import NOMADNET_CONTAINER
|
||||
import docker
|
||||
client = docker.from_env()
|
||||
container = client.containers.get(NOMADNET_CONTAINER)
|
||||
container.restart()
|
||||
log.info("NomadNet container restarted")
|
||||
return True
|
||||
except Exception as exc:
|
||||
log.info("NomadNet container not available: %s", exc)
|
||||
return False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# API endpoints
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -368,3 +399,52 @@ async def _request_remote_page(hash_hex: str, path: str) -> str | None:
|
||||
return await asyncio.wait_for(future, timeout=30.0)
|
||||
except asyncio.TimeoutError:
|
||||
return 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")
|
||||
async def restart_services():
|
||||
"""Restart NomadNet to apply config changes."""
|
||||
restarted = _restart_nomadnet()
|
||||
return {"ok": True, "nomadnet_restarted": restarted}
|
||||
|
||||
Reference in New Issue
Block a user