feat: add simple license activation server
This commit is contained in:
1 parent
b2db5ed499
commit
05be83d289
17 files changed
+1053
-6
No files matched your search
@@ -7,8 +7,9 @@ from typing import Callable
|
||||
|
||||
from douyin.license.license_manager import (
|
||||
get_license_status_payload,
|
||||
install_license_text,
|
||||
install_license_or_activate,
|
||||
)
|
||||
from gui.config_io import read_config
|
||||
|
||||
|
||||
def _format_status(payload: dict) -> str:
|
||||
@@ -24,6 +25,20 @@ def _format_status(payload: dict) -> str:
|
||||
return " | ".join(parts)
|
||||
|
||||
|
||||
def _activation_settings() -> tuple[str, int]:
|
||||
try:
|
||||
cfg = read_config()
|
||||
except Exception:
|
||||
cfg = {}
|
||||
section = cfg.get("license") if isinstance(cfg.get("license"), dict) else {}
|
||||
activation_url = str(section.get("activation_url") or "").strip()
|
||||
try:
|
||||
timeout_seconds = int(section.get("timeout_seconds") or 10)
|
||||
except (TypeError, ValueError):
|
||||
timeout_seconds = 10
|
||||
return activation_url, max(1, timeout_seconds)
|
||||
|
||||
|
||||
def setup_license_tab(
|
||||
parent: ttk.Notebook,
|
||||
*,
|
||||
@@ -81,7 +96,12 @@ def setup_license_tab(
|
||||
if not raw:
|
||||
on_line("[授权] 请输入卡密")
|
||||
return
|
||||
status = install_license_text(raw)
|
||||
activation_url, timeout_seconds = _activation_settings()
|
||||
status = install_license_or_activate(
|
||||
raw,
|
||||
activation_url=activation_url,
|
||||
timeout_seconds=timeout_seconds,
|
||||
)
|
||||
refresh_status()
|
||||
if status.ok:
|
||||
text.delete("1.0", "end")
|
||||
|
||||
@@ -8,7 +8,7 @@ from urllib.parse import parse_qs
|
||||
from douyin.core import path_config
|
||||
from douyin.license.license_manager import (
|
||||
get_license_status_payload,
|
||||
install_license_text,
|
||||
install_license_or_activate,
|
||||
)
|
||||
from gui.web_gui_pkg import (
|
||||
_wg_log,
|
||||
@@ -60,6 +60,17 @@ def _coerce_bool(value) -> bool:
|
||||
return bool(value)
|
||||
|
||||
|
||||
def _license_activation_settings() -> tuple[str, int]:
|
||||
cfg = read_config()
|
||||
section = cfg.get("license") if isinstance(cfg.get("license"), dict) else {}
|
||||
activation_url = str(section.get("activation_url") or "").strip()
|
||||
try:
|
||||
timeout_seconds = int(section.get("timeout_seconds") or 10)
|
||||
except (TypeError, ValueError):
|
||||
timeout_seconds = 10
|
||||
return activation_url, max(1, timeout_seconds)
|
||||
|
||||
|
||||
def _is_invalid_ports_spec(spec) -> bool:
|
||||
"""判断端口规格是否为明确非法输入。"""
|
||||
if spec is None:
|
||||
@@ -620,7 +631,12 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
{"ok": False, "error": "missing license_text"},
|
||||
status=400,
|
||||
)
|
||||
status = install_license_text(text)
|
||||
activation_url, timeout_seconds = _license_activation_settings()
|
||||
status = install_license_or_activate(
|
||||
text,
|
||||
activation_url=activation_url,
|
||||
timeout_seconds=timeout_seconds,
|
||||
)
|
||||
payload = get_license_status_payload()
|
||||
payload.update(
|
||||
{"ok": status.ok, "reason": status.reason, "message": status.message}
|
||||
|
||||
Reference in new issue
Block a user