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}")