From 3898c6d41c2dd7893e0aee54172d2b068f48808c Mon Sep 17 00:00:00 2001 From: x1ao4 Date: Sun, 12 Oct 2025 14:57:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=BD=E5=89=A7=E6=97=A5?= =?UTF-8?q?=E5=8E=86=E9=A1=B5=E9=9D=A2=E5=BD=93=E6=97=A5=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E7=83=AD=E6=9B=B4=E6=96=B0=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 问题:追剧日历页面当日更新标识热更新有60秒延迟,任务列表页面能实时更新 - 原因:转存记录创建/更新时未触发SSE通知,前端只能依赖轮询检测变化 - 解决: * 后端:转存记录创建/更新时触发SSE通知 (transfer_record_created/updated) * 后端:批量重命名完成时触发SSE通知 (batch_rename_completed) * 前端:SSE处理中优先更新今日更新数据 * 修复:添加安全的导入函数避免模块导入错误 - 效果:实现追剧日历页面当日更新标识实时热更新,与任务列表页面体验一致 涉及文件: - quark_auto_save.py: 添加SSE通知触发和安全导入函数 - app/run.py: 批量重命名SSE通知 - app/templates/index.html: 前端SSE处理优化 --- app/run.py | 4 ++++ app/templates/index.html | 5 +++++ quark_auto_save.py | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/app/run.py b/app/run.py index dca39f0..7818b65 100644 --- a/app/run.py +++ b/app/run.py @@ -3546,6 +3546,10 @@ def batch_rename(): "error": str(e) }) + # 如果有成功重命名的文件,触发SSE通知 + if success_count > 0: + notify_calendar_changed('batch_rename_completed') + return jsonify({ "success": True, "message": f"成功重命名 {success_count} 个文件,失败 {len(failed_files)} 个", diff --git a/app/templates/index.html b/app/templates/index.html index b0a92a1..e4791be 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -5705,6 +5705,11 @@ } } catch (e) {} + // 如果是转存记录相关的通知,立即刷新今日更新数据 + if (changeReason === 'transfer_record_created' || changeReason === 'transfer_record_updated' || changeReason === 'batch_rename_completed') { + try { await this.loadTodayUpdatesLocal(); } catch (e) {} + } + // 再仅本地读取并热更新日历/海报视图 await this.loadCalendarEpisodesLocal(); this.initializeCalendarDates(); diff --git a/quark_auto_save.py b/quark_auto_save.py index 0ed7e9f..02d6288 100644 --- a/quark_auto_save.py +++ b/quark_auto_save.py @@ -36,6 +36,22 @@ except ImportError: def close(self): pass +def notify_calendar_changed_safe(reason): + """安全地触发SSE通知,避免导入错误""" + try: + # 尝试导入notify_calendar_changed函数 + import sys + import os + # 添加app目录到Python路径 + app_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'app') + if app_dir not in sys.path: + sys.path.insert(0, app_dir) + + from run import notify_calendar_changed + notify_calendar_changed(reason) + except Exception as e: + print(f"触发SSE通知失败: {e}") + def advanced_filter_files(file_list, filterwords): """ 高级过滤函数,支持保留词和过滤词 @@ -2016,6 +2032,10 @@ class Quark: # 关闭数据库连接 db.close() + + # 触发SSE通知,让前端实时感知转存记录变化 + notify_calendar_changed_safe('transfer_record_created') + except Exception as e: print(f"保存转存记录失败: {e}") @@ -2075,6 +2095,10 @@ class Quark: # 关闭数据库连接 db.close() + # 如果更新成功,触发SSE通知 + if updated > 0: + notify_calendar_changed_safe('transfer_record_updated') + return updated > 0 except Exception as e: print(f"更新转存记录失败: {e}")