修复福袋详情OCR v2与调试日志
This commit is contained in:
1 parent
2c6f024a24
commit
1d37d57c90
119 files changed
+5582
-767
No files matched your search
@@ -9,11 +9,18 @@ def send_json(handler: BaseHTTPRequestHandler, obj, status: int = 200) -> None:
|
||||
handler.send_header("Cache-Control", "no-store")
|
||||
handler.send_header("Content-Length", str(len(data)))
|
||||
handler.end_headers()
|
||||
handler.wfile.write(data)
|
||||
try:
|
||||
handler.wfile.write(data)
|
||||
except (BrokenPipeError, ConnectionAbortedError, ConnectionResetError):
|
||||
# 客户端已主动断开时不应把正常断链打成服务端 traceback。
|
||||
return None
|
||||
|
||||
|
||||
def read_json(handler: BaseHTTPRequestHandler) -> dict:
|
||||
n = int(handler.headers.get("Content-Length") or 0)
|
||||
try:
|
||||
n = int(handler.headers.get("Content-Length") or 0)
|
||||
except Exception:
|
||||
n = 0
|
||||
raw = handler.rfile.read(n) if n > 0 else b"{}"
|
||||
try:
|
||||
value = json.loads(raw.decode("utf-8"))
|
||||
|
||||
@@ -25,6 +25,14 @@ _TRUE_LITERALS = {"1", "true", "yes", "y", "on"}
|
||||
_FALSE_LITERALS = {"0", "false", "no", "n", "off", ""}
|
||||
|
||||
|
||||
def _is_local_request(handler) -> bool:
|
||||
try:
|
||||
host = str((handler.client_address or ("",))[0] or "").strip()
|
||||
except Exception:
|
||||
return False
|
||||
return host in {"127.0.0.1", "::1", "localhost"}
|
||||
|
||||
|
||||
def _coerce_bool(value) -> bool:
|
||||
"""把配置输入稳健地转为 bool。
|
||||
|
||||
@@ -77,6 +85,10 @@ def _is_invalid_ports_spec(spec) -> bool:
|
||||
|
||||
def handle_get(handler, u, runner, csrf_token: str) -> None:
|
||||
if u.path.startswith("/api/"):
|
||||
if not _is_local_request(handler):
|
||||
return handler._send_json(
|
||||
{"ok": False, "error": "Local access only"}, status=403
|
||||
)
|
||||
api_path = u.path.rstrip("/")
|
||||
if u.path == "/api/csrf-token":
|
||||
return handler._send_json({"token": csrf_token})
|
||||
@@ -230,6 +242,10 @@ def handle_get(handler, u, runner, csrf_token: str) -> None:
|
||||
return
|
||||
|
||||
if u.path.startswith("/pic/"):
|
||||
if not _is_local_request(handler):
|
||||
return handler._send_json(
|
||||
{"ok": False, "error": "Local access only"}, status=403
|
||||
)
|
||||
rel = u.path.lstrip("/")
|
||||
safe = os.path.normpath(rel).replace("\\", "/")
|
||||
if not safe.startswith("pic/"):
|
||||
@@ -255,10 +271,18 @@ def handle_get(handler, u, runner, csrf_token: str) -> None:
|
||||
handler.wfile.write(data)
|
||||
return
|
||||
|
||||
if not _is_local_request(handler):
|
||||
handler.send_error(HTTPStatus.FORBIDDEN)
|
||||
return
|
||||
|
||||
handler._serve_static(u.path)
|
||||
|
||||
|
||||
def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
if not _is_local_request(handler):
|
||||
return handler._send_json(
|
||||
{"ok": False, "error": "Local access only"}, status=403
|
||||
)
|
||||
if handler.headers.get("X-CSRF-Token", "") != csrf_token:
|
||||
return handler._send_json(
|
||||
{"ok": False, "error": "Invalid CSRF token"}, status=403
|
||||
@@ -356,6 +380,26 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
"fudai_quiet_hours_enabled",
|
||||
"high_value_fudai_enabled",
|
||||
"fudai_disable_content_recognition",
|
||||
"fudai_detail_ocr_content_enabled",
|
||||
"fudai_detail_ocr_value_enabled",
|
||||
"fudai_detail_ocr_countdown_enabled",
|
||||
"fudai_detail_ocr_task_enabled",
|
||||
"fudai_detail_ocr_task_count_enabled",
|
||||
"fudai_detail_ocr_button_enabled",
|
||||
"fudai_detail_ocr_participants_enabled",
|
||||
"fudai_detail_ocr_live_title_enabled",
|
||||
"pixel_detect_fudai_icon_enabled",
|
||||
"pixel_detect_coupon_popup_enabled",
|
||||
"pixel_detect_shopping_redpacket_enabled",
|
||||
"pixel_detect_lottery_result_enabled",
|
||||
"pixel_detect_attend_button_enabled",
|
||||
"pixel_detect_fansclub_join_enabled",
|
||||
"pixel_detect_fudai_detail_enabled",
|
||||
"pixel_detect_live_room_enabled",
|
||||
"ocr_lottery_result_enabled",
|
||||
"ocr_coupon_popup_enabled",
|
||||
"ocr_shopping_redpacket_enabled",
|
||||
"ocr_stage_page_enabled",
|
||||
"high_value_room_revisit_enabled",
|
||||
"high_value_room_revisit_only_current_run",
|
||||
"reservation_back_verify_enabled",
|
||||
@@ -397,6 +441,11 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
"yanghao_fallback_enter_live_x",
|
||||
"yanghao_fallback_enter_live_y",
|
||||
}
|
||||
enum_str_keys = {
|
||||
"reset_after_swipes_action",
|
||||
"reenter_live_entry_mode",
|
||||
"fudai_detail_ui_mode",
|
||||
}
|
||||
|
||||
def set_nested_value(obj, key, value):
|
||||
if "." in key:
|
||||
@@ -432,6 +481,18 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
set_nested_value(
|
||||
cfg, k, [str(x).strip() for x in str(v).splitlines() if str(x).strip()]
|
||||
)
|
||||
elif k in enum_str_keys:
|
||||
val = str(v or "").strip().lower()
|
||||
if k == "reset_after_swipes_action":
|
||||
if val not in ("swipe", "back"):
|
||||
continue
|
||||
if k == "reenter_live_entry_mode":
|
||||
if val not in ("follow_list", "screen_center"):
|
||||
continue
|
||||
if k == "fudai_detail_ui_mode":
|
||||
if val not in ("auto", "legacy", "v2_0"):
|
||||
continue
|
||||
set_nested_value(cfg, k, val)
|
||||
else:
|
||||
set_nested_value(cfg, k, v)
|
||||
write_config(cfg)
|
||||
@@ -535,7 +596,8 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
|
||||
last = get_last_wifi_target()
|
||||
last_target = str(last.get("target") or "")
|
||||
if last_target.startswith(ip):
|
||||
disconnect_target = ip if ":" in ip else f"{ip}:{port}"
|
||||
if last_target == disconnect_target:
|
||||
clear_last_wifi_target()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in new issue
Block a user