refactor: simplify to see/interact/exec and split server modules
All checks were successful
python-syntax / syntax-check (push) Successful in 6s
All checks were successful
python-syntax / syntax-check (push) Successful in 6s
This commit is contained in:
42
server/config.py
Normal file
42
server/config.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
load_dotenv(dotenv_path=".env", override=False)
|
||||
|
||||
|
||||
def _env_bool(name: str, default: bool) -> bool:
|
||||
raw = os.getenv(name)
|
||||
if raw is None:
|
||||
return default
|
||||
return raw.strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
def _parse_allowed_region() -> Optional[tuple[int, int, int, int]]:
|
||||
raw = os.getenv("CLICKTHROUGH_ALLOWED_REGION")
|
||||
if not raw:
|
||||
return None
|
||||
parts = [p.strip() for p in raw.split(",")]
|
||||
if len(parts) != 4:
|
||||
raise ValueError("CLICKTHROUGH_ALLOWED_REGION must be x,y,width,height")
|
||||
x, y, w, h = (int(p) for p in parts)
|
||||
if w <= 0 or h <= 0:
|
||||
raise ValueError("CLICKTHROUGH_ALLOWED_REGION width/height must be > 0")
|
||||
return x, y, w, h
|
||||
|
||||
|
||||
SETTINGS = {
|
||||
"host": os.getenv("CLICKTHROUGH_HOST", "127.0.0.1"),
|
||||
"port": int(os.getenv("CLICKTHROUGH_PORT", "8123")),
|
||||
"token": os.getenv("CLICKTHROUGH_TOKEN", "").strip(),
|
||||
"dry_run": _env_bool("CLICKTHROUGH_DRY_RUN", False),
|
||||
"allowed_region": _parse_allowed_region(),
|
||||
"exec_enabled": _env_bool("CLICKTHROUGH_EXEC_ENABLED", True),
|
||||
"exec_default_shell": os.getenv("CLICKTHROUGH_EXEC_DEFAULT_SHELL", "powershell").strip().lower(),
|
||||
"exec_default_timeout_s": int(os.getenv("CLICKTHROUGH_EXEC_TIMEOUT_S", "30")),
|
||||
"exec_max_timeout_s": int(os.getenv("CLICKTHROUGH_EXEC_MAX_TIMEOUT_S", "120")),
|
||||
"exec_max_output_chars": int(os.getenv("CLICKTHROUGH_EXEC_MAX_OUTPUT_CHARS", "20000")),
|
||||
"exec_secret": os.getenv("CLICKTHROUGH_EXEC_SECRET", "").strip(),
|
||||
}
|
||||
Reference in New Issue
Block a user