From d47a9411b27a63555dca7020159c79d713ec9777 Mon Sep 17 00:00:00 2001 From: Shiitin Date: Mon, 13 Apr 2026 15:37:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=BD=93html?= =?UTF-8?q?=5Fonly=5Furl=E6=89=93=E5=BC=80=E6=97=B6=EF=BC=8CURL=E6=8B=BC?= =?UTF-8?q?=E6=8E=A5=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98=20(#169)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #169 * fix:修复了当html_only_url打开时,手动触发部分URL拼接错误问题 * fix:修复了当html_only_url打开时,自动触发部分URL拼接错误问题 * fix: ruff --------- Co-authored-by: SXP-Simon --- main.py | 30 ++++++++++++++++++++-- src/infrastructure/reporting/dispatcher.py | 29 +++++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index bf2096c..21e3af2 100644 --- a/main.py +++ b/main.py @@ -633,8 +633,34 @@ class GroupDailyAnalysis(Star): if is_only_url: if base_url and base_url.strip(): - filename = os.path.basename(html_path) - report_url = f"{base_url.rstrip('/')}/{filename}" + # 获取配置中的输出目录 + html_output_dir = self.config_manager.get_html_output_dir() + + # 若用户配置为空,使用默认目录 + if not html_output_dir: + try: + from astrbot.api.star import StarTools + + html_output_dir = os.path.join( + StarTools.get_data_dir(), "self_hosted_html_reports" + ) + except Exception: + from astrbot.core.utils.astrbot_path import ( + get_astrbot_data_path, + ) + + html_output_dir = os.path.join( + get_astrbot_data_path(), + "plugin_data", + "astrbot_plugin_qq_group_daily_analysis", + "self_hosted_html_reports", + ) + + # 计算相对路径并转换为URL + rel_path = os.path.relpath(html_path, html_output_dir) + url_path = rel_path.replace(os.sep, "/") + report_url = f"{base_url.rstrip('/')}/{url_path.lstrip('/')}" + yield event.plain_result( f"📊 今日群聊分析报告已生成:\n{report_url}" ) diff --git a/src/infrastructure/reporting/dispatcher.py b/src/infrastructure/reporting/dispatcher.py index 929146b..f173305 100644 --- a/src/infrastructure/reporting/dispatcher.py +++ b/src/infrastructure/reporting/dispatcher.py @@ -131,8 +131,33 @@ class ReportDispatcher: if is_only_url: if base_url and base_url.strip(): - filename = os.path.basename(html_path) - report_url = f"{base_url.rstrip('/')}/{filename}" + # 获取配置的目录 + html_output_dir = self.config_manager.get_html_output_dir() + + # 若用户配置为空,使用默认目录 + if not html_output_dir: + try: + from astrbot.api.star import StarTools + + html_output_dir = os.path.join( + StarTools.get_data_dir(), "self_hosted_html_reports" + ) + except Exception: + from astrbot.core.utils.astrbot_path import ( + get_astrbot_data_path, + ) + + html_output_dir = os.path.join( + get_astrbot_data_path(), + "plugin_data", + "astrbot_plugin_qq_group_daily_analysis", + "self_hosted_html_reports", + ) + + # 计算相对路径并转换为URL + rel_path = os.path.relpath(html_path, html_output_dir) + url_path = rel_path.replace(os.sep, "/") + report_url = f"{base_url.rstrip('/')}/{url_path.lstrip('/')}" sent = await self.message_sender.send_text( group_id,