refactor(app): 重构图片压缩功能并优化类型注解

- 使用 Path 对象替换字符串表示文件路径,提高代码可读性和功能
- 优化类型注解,包括函数参数和返回值- 重构 ImageUtils.compress_image_if_needed 方法,简化逻辑并提高性能
- 更新 notification.py 中使用该方法的代码,直接返回压缩后的 Path 对象
This commit is contained in:
2025-06-11 22:14:09 +08:00
parent f60b276916
commit 4d4d6dbedf
2 changed files with 23 additions and 28 deletions

View File

@@ -273,12 +273,11 @@ class Notification(QObject):
)
return f"使用企业微信群机器人推送通知时出错:{err}"
def CompanyWebHookBotPushImage(self, image_path: str, webhook_url: str) -> bool:
def CompanyWebHookBotPushImage(self, image_path: Path, webhook_url: str) -> bool:
"""使用企业微信群机器人推送图片通知"""
try:
# 压缩图片
final_image_path = ImageUtils.compress_image_if_needed(str(image_path))
final_image_path = Path(final_image_path)
final_image_path = ImageUtils.compress_image_if_needed(image_path)
# 检查图片是否存在
if not final_image_path.exists():