added restapi

This commit is contained in:
2026-11-02 16:46:20 +03:00
parent 9d74d06ce3
commit 588c2e0135
74 changed files with 7253 additions and 129 deletions
+22 -1
View File
@@ -8,7 +8,7 @@ import time
from pathlib import Path
from typing import Any, Dict, List, Optional
from config import UI_LOG_LIMIT, cmd_path, status_path, ui_log_path
from config import UI_LOG_LIMIT, cmd_path, history_path, status_path, ui_log_path
log = logging.getLogger("collector.ui")
@@ -23,6 +23,27 @@ def write_status(status: dict) -> None:
log.error("status write failed: %s", e)
def write_history(data: dict) -> None:
path = history_path()
tmp = Path(str(path) + ".tmp")
try:
tmp.write_text(json.dumps(data, ensure_ascii=False), encoding="utf-8")
tmp.replace(path)
except OSError as e:
log.error("history write failed: %s", e)
def read_history() -> dict:
path = history_path()
if not path.exists():
return {}
try:
raw = json.loads(path.read_text(encoding="utf-8"))
except (OSError, ValueError):
return {}
return raw if isinstance(raw, dict) else {}
def append_ui_log(level: str, message: str, **extra: Any) -> None:
path = ui_log_path()
entry = {