Conversation
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并且给出了一些整体性的反馈:
- 目前解析 SSL 启用环境变量有两套实现(
server.py中的_parse_env_bool,以及_is_dashboard_ssl_enabled中的内联逻辑);建议将这两者集中到一个共享的辅助函数中,以避免行为出现差异。 - dashboard SSL 是否启用是从配置中推导出来的,但
server.run(在有字典类型检查的情况下使用bool(ssl_config.get("enable", False)))和_is_dashboard_ssl_enabled(直接嵌套get并使用宽泛的except)之间的逻辑略有不同;如果能统一这些代码路径,将会使行为更加可预测,并在配置格式不正确时减少意料之外的差异。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- There are two separate implementations for parsing the SSL enable env vars (`_parse_env_bool` in `server.py` and inline logic in `_is_dashboard_ssl_enabled`); consider centralizing this into a single shared helper to avoid divergence in behavior.
- The way dashboard SSL enablement is derived from config differs slightly between `server.run` (uses `bool(ssl_config.get("enable", False))` with a dict-type guard) and `_is_dashboard_ssl_enabled` (direct nested `get` with a broad `except`); aligning these code paths would make behavior more predictable and reduce surprising differences if the config is malformed.
## Individual Comments
### Comment 1
<location> `astrbot/core/utils/webhook_utils.py:24-32` </location>
<code_context>
return 6185
+def _is_dashboard_ssl_enabled() -> bool:
+ env_ssl = os.environ.get("DASHBOARD_SSL_ENABLE") or os.environ.get(
+ "ASTRBOT_DASHBOARD_SSL_ENABLE"
+ )
+ if env_ssl is not None:
+ return env_ssl.strip().lower() in {"1", "true", "yes", "on"}
+
+ try:
+ return bool(astrbot_config.get("dashboard", {}).get("ssl", {}).get("enable"))
+ except Exception as e:
+ logger.error(f"获取 dashboard SSL 配置失败: {e!s}")
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `bool(config_value)` here may treat non-boolean config values (e.g. non-empty strings) as enabled.
Config marks `dashboard.ssl.enable` as a bool, but this code still does a generic `bool(...)` cast. If the value ever becomes a non-empty string like "false" or "0", it will still evaluate to `True`. To align with `server.run` and make this robust, consider reusing the same `_parse_env_bool`-style logic (normalize strings and check explicit truthy values) for the config value instead of relying on general truthiness.
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- There are two separate implementations for parsing the SSL enable env vars (
_parse_env_boolinserver.pyand inline logic in_is_dashboard_ssl_enabled); consider centralizing this into a single shared helper to avoid divergence in behavior. - The way dashboard SSL enablement is derived from config differs slightly between
server.run(usesbool(ssl_config.get("enable", False))with a dict-type guard) and_is_dashboard_ssl_enabled(direct nestedgetwith a broadexcept); aligning these code paths would make behavior more predictable and reduce surprising differences if the config is malformed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- There are two separate implementations for parsing the SSL enable env vars (`_parse_env_bool` in `server.py` and inline logic in `_is_dashboard_ssl_enabled`); consider centralizing this into a single shared helper to avoid divergence in behavior.
- The way dashboard SSL enablement is derived from config differs slightly between `server.run` (uses `bool(ssl_config.get("enable", False))` with a dict-type guard) and `_is_dashboard_ssl_enabled` (direct nested `get` with a broad `except`); aligning these code paths would make behavior more predictable and reduce surprising differences if the config is malformed.
## Individual Comments
### Comment 1
<location> `astrbot/core/utils/webhook_utils.py:24-32` </location>
<code_context>
return 6185
+def _is_dashboard_ssl_enabled() -> bool:
+ env_ssl = os.environ.get("DASHBOARD_SSL_ENABLE") or os.environ.get(
+ "ASTRBOT_DASHBOARD_SSL_ENABLE"
+ )
+ if env_ssl is not None:
+ return env_ssl.strip().lower() in {"1", "true", "yes", "on"}
+
+ try:
+ return bool(astrbot_config.get("dashboard", {}).get("ssl", {}).get("enable"))
+ except Exception as e:
+ logger.error(f"获取 dashboard SSL 配置失败: {e!s}")
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `bool(config_value)` here may treat non-boolean config values (e.g. non-empty strings) as enabled.
Config marks `dashboard.ssl.enable` as a bool, but this code still does a generic `bool(...)` cast. If the value ever becomes a non-empty string like "false" or "0", it will still evaluate to `True`. To align with `server.run` and make this robust, consider reusing the same `_parse_env_bool`-style logic (normalize strings and check explicit truthy values) for the config value instead of relying on general truthiness.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| def _is_dashboard_ssl_enabled() -> bool: | ||
| env_ssl = os.environ.get("DASHBOARD_SSL_ENABLE") or os.environ.get( | ||
| "ASTRBOT_DASHBOARD_SSL_ENABLE" | ||
| ) | ||
| if env_ssl is not None: | ||
| return env_ssl.strip().lower() in {"1", "true", "yes", "on"} | ||
|
|
||
| try: | ||
| return bool(astrbot_config.get("dashboard", {}).get("ssl", {}).get("enable")) |
There was a problem hiding this comment.
issue (bug_risk): 这里使用 bool(config_value) 可能会把非布尔类型的配置值(例如非空字符串)当作启用状态。
配置中将 dashboard.ssl.enable 标注为布尔值,但这里的代码仍然只是做了一个通用的 bool(...) 转换。如果该值变成诸如 "false" 或 "0" 之类的非空字符串,它仍然会被评估为 True。为了与 server.run 保持一致并增强健壮性,建议对配置值也复用 _parse_env_bool 式的逻辑(先规范化字符串并只检查显式的真值),而不是依赖通用的真值判断。
Original comment in English
issue (bug_risk): Using bool(config_value) here may treat non-boolean config values (e.g. non-empty strings) as enabled.
Config marks dashboard.ssl.enable as a bool, but this code still does a generic bool(...) cast. If the value ever becomes a non-empty string like "false" or "0", it will still evaluate to True. To align with server.run and make this robust, consider reusing the same _parse_env_bool-style logic (normalize strings and check explicit truthy values) for the config value instead of relying on general truthiness.
Modifications / 改动点
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Summary by Sourcery
为 WebUI 仪表盘添加可配置的 SSL 支持,并使相关的 URL 和日志与 HTTP/HTTPS 的使用保持一致。
新特性:
改进:
dashboard_config映射来获取配置。Original summary in English
Summary by Sourcery
Add configurable SSL support for the WebUI dashboard and align related URLs and logging with HTTP/HTTPS usage.
New Features:
Enhancements: