refactor(notify): 重构企业微信群机器人图片推送功能

-将图片压缩、存在性检查、Base64编码和MD5计算移至 CompanyWebHookBotPushImage 方法内部
- 优化错误处理和日志记录
- 简化调用接口,提高代码可读性和维护性
This commit is contained in:
2025-06-11 20:54:45 +08:00
parent 87857fd499
commit f60b276916
2 changed files with 59 additions and 74 deletions

View File

@@ -2000,34 +2000,14 @@ class MaaManager(QObject):
Config.get(Config.notify_CompanyWebHookBotUrl),
)
app_path = Config.app_path
image_path = app_path / "resources/images/notification/six_star.png"
# 压缩后得到的仍然是字符串路径
final_image_path = ImageUtils.compress_image_if_needed(
str(image_path)
image_path = (
app_path / "resources/images/notification/six_star.png"
)
# 转回Path对象方便exists判断
final_image_path = Path(
final_image_path
Notify.CompanyWebHookBotPushImage(
image_path,
Config.get(Config.notify_CompanyWebHookBotUrl),
)
if final_image_path.exists():
image_base64 = ImageUtils.get_base64_from_file(
str(final_image_path)
)
image_md5 = ImageUtils.calculate_md5_from_file(
str(final_image_path)
)
Notify.CompanyWebHookBotPushImage(
image_base64,
image_md5,
user_data["Notify"]["CompanyWebHookBotUrl"],
)
else:
logger.error(
f"{self.name} | 图片不存在或者压缩失败,请检查图片路径是否正确"
)
# 发送用户单独通知
if user_data["Notify"]["Enabled"] and user_data["Notify"]["IfSendSixStar"]: