fix: allow first-run license activation
This commit is contained in:
1 parent
e315aaf80b
commit
407c3b37c2
10 files changed
+715
-23
No files matched your search
@@ -7,6 +7,7 @@ from urllib.parse import parse_qs
|
||||
|
||||
from douyin.core import path_config
|
||||
from douyin.license.license_manager import (
|
||||
check_license,
|
||||
get_default_activation_url,
|
||||
get_license_status_payload,
|
||||
install_license_or_activate,
|
||||
@@ -33,6 +34,23 @@ _EMPTY_PNG_BYTES = bytes.fromhex(
|
||||
"1f15c4890000000a49444154789c636000000200015dc1b2ea00000000"
|
||||
"49454e44ae426082"
|
||||
)
|
||||
_LICENSE_REQUIRED_POST_PATHS = {
|
||||
"/api/start-run",
|
||||
"/api/force-stop",
|
||||
"/api/pause",
|
||||
"/api/resume",
|
||||
"/api/back-key",
|
||||
"/api/wifi/enable",
|
||||
"/api/wifi/connect",
|
||||
"/api/wifi/disconnect",
|
||||
"/api/wifi/scan",
|
||||
"/api/wifi/last/clear",
|
||||
"/api/wifi/auto-reconnect",
|
||||
"/api/test-yanghao",
|
||||
"/api/test-comment",
|
||||
"/api/stop",
|
||||
"/api/screenshot",
|
||||
}
|
||||
|
||||
|
||||
def _is_local_request(handler) -> bool:
|
||||
@@ -72,6 +90,20 @@ def _license_activation_settings() -> tuple[str, int]:
|
||||
return activation_url, max(1, timeout_seconds)
|
||||
|
||||
|
||||
def _license_gate_payload() -> dict:
|
||||
status = check_license()
|
||||
payload = get_license_status_payload()
|
||||
payload.update(
|
||||
{
|
||||
"ok": False,
|
||||
"error": "license_required",
|
||||
"reason": status.reason,
|
||||
"message": status.message,
|
||||
}
|
||||
)
|
||||
return payload
|
||||
|
||||
|
||||
def _is_invalid_ports_spec(spec) -> bool:
|
||||
"""判断端口规格是否为明确非法输入。"""
|
||||
if spec is None:
|
||||
@@ -349,6 +381,8 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
return handler._send_json(
|
||||
{"ok": False, "error": "Invalid CSRF token"}, status=403
|
||||
)
|
||||
if u.path in _LICENSE_REQUIRED_POST_PATHS and not check_license().ok:
|
||||
return handler._send_json(_license_gate_payload(), status=403)
|
||||
|
||||
if u.path == "/api/config":
|
||||
body = handler._read_json()
|
||||
|
||||
Reference in new issue
Block a user