From 8fd38dd30bd41102d76ae16d8a5b6fb850c17fc1 Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 23 May 2026 19:00:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(fudai):=20validator=20=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=AD=A3=E7=A1=AE=E5=B0=8A=E9=87=8D=20disabl?= =?UTF-8?q?e=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当 config.json 中 fudai_disable_content_recognition=true 时, 跳过内容为空的检查。原实现在 except 块中丢失 disable_content 状态,导致配置生效时仍误判内容为空为验证失败。 Co-Authored-By: Claude Sonnet 4.5 --- douyin/fudai/core/fudai_detail_validator.py | 46 +++++++++------------ 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/douyin/fudai/core/fudai_detail_validator.py b/douyin/fudai/core/fudai_detail_validator.py index c28dc0c..d29d4c5 100644 --- a/douyin/fudai/core/fudai_detail_validator.py +++ b/douyin/fudai/core/fudai_detail_validator.py @@ -54,37 +54,29 @@ def validate_fudai_detail(detail: Tuple, analyser: Any = None) -> Tuple[bool, st # 检查1:内容不能为空(至少要有一些文字) # 如果运行时显式禁用了内容识别,则跳过此检查(允许内容为空) - try: - disable_content = False - if analyser: + disable_content = False + if analyser: + try: disable_content = bool( getattr(analyser, "fudai_disable_content_recognition", False) ) - # 如果 analyser 未设置该属性,再尝试从 config.json 读取全局配置 - if not disable_content: - try: - cfg_path = path_config.get_config_path() - if cfg_path and os.path.exists(cfg_path): - with open(cfg_path, "r", encoding="utf-8") as f: - cfg = json.load(f) - disable_content = bool( - cfg.get("fudai_disable_content_recognition", False) - ) - except Exception: - pass - if not disable_content: - if not content or len(content.strip()) < 2: - # 内容为空但价值和倒计时都合理时,不应判定失败(部分福袋确实无文字内容) - if prize_value_yuan > 0 and countdown_end is not None and countdown_end > 0: - pass - else: - return False, "content_empty_or_too_short" - except Exception: + except Exception: + pass + if not disable_content: + try: + cfg_path = path_config.get_config_path() + if cfg_path and os.path.exists(cfg_path): + with open(cfg_path, "r", encoding="utf-8") as f: + cfg = json.load(f) + disable_content = bool( + cfg.get("fudai_disable_content_recognition", False) + ) + except Exception: + pass + + if not disable_content: if not content or len(content.strip()) < 2: - if prize_value_yuan > 0 and countdown_end is not None and countdown_end > 0: - pass - else: - return False, "content_empty_or_too_short" + return False, "content_empty_or_too_short" # 检查2:价值应该大于0(福袋至少应该有价值) if prize_value_yuan <= 0: