From 8304d8e8fd3b2d9d46b962462807a00c19cfab90 Mon Sep 17 00:00:00 2001 From: x1ao4 Date: Wed, 27 Aug 2025 02:32:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A8=E9=80=81=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E7=B1=BB=E5=9E=8B=E9=80=89=E6=8B=A9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增推送通知类型配置选项 - 支持三种模式: - 完整信息(转存成功、转存失败、资源失效) - 仅成功信息(仅转存成功) - 排除失效信息(转存成功、转存失败) - 优化通知过滤逻辑,提升用户体验 --- app/run.py | 8 ++++++++ app/templates/index.html | 11 +++++++++++ quark_auto_save.py | 37 ++++++++++++++++++++++++++++++++----- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/run.py b/app/run.py index d4f168f..bdacb41 100644 --- a/app/run.py +++ b/app/run.py @@ -515,6 +515,10 @@ def get_data(): } } + # 初始化推送通知类型配置(如果不存在) + if "push_notify_type" not in data: + data["push_notify_type"] = "full" + # 初始化搜索来源默认结构 if "source" not in data or not isinstance(data.get("source"), dict): data["source"] = {} @@ -1730,6 +1734,10 @@ def init(): } } + # 初始化推送通知类型配置(如果不存在) + if "push_notify_type" not in config_data: + config_data["push_notify_type"] = "full" + # 同步更新任务的插件配置 sync_task_plugins_config() diff --git a/app/templates/index.html b/app/templates/index.html index 35b9d38..e9f145b 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -515,6 +515,16 @@ +
+
+ 推送通知 +
+ +
@@ -2134,6 +2144,7 @@ formData: { cookie: [], push_config: {}, + push_notify_type: 'full', media_servers: {}, tasklist: [], magic_regex: {}, diff --git a/quark_auto_save.py b/quark_auto_save.py index 0f94ed4..4d4afd7 100644 --- a/quark_auto_save.py +++ b/quark_auto_save.py @@ -829,6 +829,28 @@ def add_notify(text): # 防止重复添加相同的通知 if text in NOTIFYS: return text + + # 检查推送通知类型配置 + push_notify_type = CONFIG_DATA.get("push_notify_type", "full") + + # 如果设置为仅推送成功信息,则过滤掉失败和错误信息 + if push_notify_type == "success_only": + # 检查是否包含失败或错误相关的关键词 + failure_keywords = ["❌", "❗", "失败", "失效", "错误", "异常", "无效", "登录失败"] + if any(keyword in text for keyword in failure_keywords): + # 只打印到控制台,不添加到通知列表 + print(text) + return text + + # 如果设置为排除失效信息,则过滤掉资源失效信息,但保留转存失败信息 + elif push_notify_type == "exclude_invalid": + # 检查是否包含资源失效相关的关键词(主要是分享资源失效) + invalid_keywords = ["分享资源已失效", "分享详情获取失败", "分享为空", "文件已被分享者删除"] + if any(keyword in text for keyword in invalid_keywords): + # 只打印到控制台,不添加到通知列表 + print(text) + return text + NOTIFYS.append(text) print(text) return text @@ -4485,7 +4507,7 @@ def do_save(account, tasklist=[]): # 添加成功通知,带文件数量图标 # 这个通知会在下面的新逻辑中添加,这里注释掉 - # add_notify(f"✅《{task['taskname']}》添加追更:") + # add_notify(f"✅《{task['taskname']}》新增文件:") # add_notify(f"/{task['savepath']}") # 移除调试信息 @@ -4767,7 +4789,7 @@ def do_save(account, tasklist=[]): pass else: # 添加基本通知 - add_notify(f"✅《{task['taskname']}》添加追更:") + add_notify(f"✅《{task['taskname']}》新增文件:") add_notify(f"{re.sub(r'/{2,}', '/', f'/{task['savepath']}')}") # 修正首次运行时对子目录的处理 - 只有在首次运行且有新增的子目录时才显示子目录内容 @@ -5098,7 +5120,7 @@ def do_save(account, tasklist=[]): # 添加成功通知 - 修复问题:确保在有文件时添加通知 if display_files: - add_notify(f"✅《{task['taskname']}》添加追更:") + add_notify(f"✅《{task['taskname']}》新增文件:") add_notify(f"{re.sub(r'/{2,}', '/', f'/{task['savepath']}')}") @@ -5188,7 +5210,7 @@ def do_save(account, tasklist=[]): display_files = [file["file_name"] for file in file_nodes] # 添加成功通知 - add_notify(f"✅《{task['taskname']}》添加追更:") + add_notify(f"✅《{task['taskname']}》新增文件:") add_notify(f"{re.sub(r'/{2,}', '/', f'/{task['savepath']}')}") # 打印文件列表 @@ -5339,7 +5361,12 @@ def main(): if NOTIFYS: notify_body = "\n".join(NOTIFYS) print(f"===============推送通知===============") - send_ql_notify("【夸克自动追更】", notify_body) + send_ql_notify("【夸克自动转存】", notify_body) + print() + else: + # 如果没有通知内容,显示统一提示 + print(f"===============推送通知===============") + print("📭 本次运行没有新的转存,未推送通知") print() if cookie_form_file: # 更新配置