platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
35
selective-vpn-gui/api/trace.py
Normal file
35
selective-vpn-gui/api/trace.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, cast
|
||||
|
||||
from .errors import ApiError
|
||||
from .models import *
|
||||
from .utils import strip_ansi
|
||||
|
||||
|
||||
class TraceApiMixin:
|
||||
# Trace
|
||||
def trace_get(self, mode: TraceMode = "full") -> TraceDump:
|
||||
m = str(mode).lower().strip()
|
||||
if m not in ("full", "gui", "smartdns"):
|
||||
m = "full"
|
||||
data = cast(
|
||||
Dict[str, Any],
|
||||
self._json(self._request("GET", "/api/v1/trace-json", params={"mode": m}, timeout=5.0)) or {},
|
||||
)
|
||||
lines = data.get("lines") or []
|
||||
if not isinstance(lines, list):
|
||||
lines = []
|
||||
return TraceDump(lines=[strip_ansi(str(x)) for x in lines])
|
||||
|
||||
def trace_append(self, kind: Literal["gui", "smartdns", "info"], line: str) -> None:
|
||||
try:
|
||||
self._request(
|
||||
"POST",
|
||||
"/api/v1/trace/append",
|
||||
json_body={"kind": kind, "line": str(line)},
|
||||
timeout=2.0,
|
||||
)
|
||||
except ApiError:
|
||||
# Logging must never crash UI.
|
||||
pass
|
||||
Reference in New Issue
Block a user