auto-save 2026-05-09 17:19 (~2)

This commit is contained in:
2026-05-09 17:19:17 +08:00
parent a08ef20e7f
commit 4c4885669c
2 changed files with 43 additions and 23 deletions

View File

@@ -11,6 +11,7 @@ from __future__ import annotations
import json
import logging
import os
import hashlib
import threading
import time
import traceback
@@ -175,13 +176,34 @@ def resolve_app_id(path: str, body: dict[str, Any] | None = None) -> str:
return Config.default_feishu_app_id
def callback_token(body: dict[str, Any]) -> str:
return str(body.get("token") or body.get("header", {}).get("token") or "")
def token_digest(value: str) -> str:
if not value:
return "(empty)"
return f"len={len(value)} sha256={hashlib.sha256(value.encode('utf-8')).hexdigest()[:12]}"
def verify_callback_token(body: dict[str, Any], app_id: str) -> bool:
app = Config.feishu_apps.get(app_id, {})
expected = app.get("verification_token", "")
if not expected:
return True
token = body.get("token") or body.get("header", {}).get("token")
return token == expected
token = callback_token(body)
ok = token == expected
if not ok:
logging.warning(
"invalid Feishu verification token app_id=%s got=%s expected=%s body_keys=%s header_keys=%s event_keys=%s",
app_id,
token_digest(token),
token_digest(expected),
sorted(body.keys()),
sorted(body.get("header", {}).keys()) if isinstance(body.get("header"), dict) else [],
sorted(body.get("event", {}).keys()) if isinstance(body.get("event"), dict) else [],
)
return ok
def remember_event(event_id: str) -> bool: