platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
54
selective-vpn-gui/api/domains.py
Normal file
54
selective-vpn-gui/api/domains.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, cast
|
||||
|
||||
from .models import *
|
||||
|
||||
|
||||
class DomainsApiMixin:
|
||||
# Domains editor
|
||||
def domains_table(self) -> DomainsTable:
|
||||
data = cast(Dict[str, Any], self._json(self._request("GET", "/api/v1/domains/table")) or {})
|
||||
lines = data.get("lines") or []
|
||||
if not isinstance(lines, list):
|
||||
lines = []
|
||||
return DomainsTable(lines=[str(x) for x in lines])
|
||||
|
||||
def domains_file_get(
|
||||
self,
|
||||
name: Literal[
|
||||
"bases",
|
||||
"meta",
|
||||
"subs",
|
||||
"static",
|
||||
"smartdns",
|
||||
"last-ips-map",
|
||||
"last-ips-map-direct",
|
||||
"last-ips-map-wildcard",
|
||||
"wildcard-observed-hosts",
|
||||
],
|
||||
) -> DomainsFile:
|
||||
data = cast(
|
||||
Dict[str, Any],
|
||||
self._json(self._request("GET", "/api/v1/domains/file", params={"name": name})) or {},
|
||||
)
|
||||
content = str(data.get("content") or "")
|
||||
source = str(data.get("source") or "")
|
||||
return DomainsFile(name=name, content=content, source=source)
|
||||
|
||||
def domains_file_set(
|
||||
self,
|
||||
name: Literal[
|
||||
"bases",
|
||||
"meta",
|
||||
"subs",
|
||||
"static",
|
||||
"smartdns",
|
||||
"last-ips-map",
|
||||
"last-ips-map-direct",
|
||||
"last-ips-map-wildcard",
|
||||
"wildcard-observed-hosts",
|
||||
],
|
||||
content: str,
|
||||
) -> None:
|
||||
self._request("POST", "/api/v1/domains/file", json_body={"name": name, "content": content})
|
||||
Reference in New Issue
Block a user