mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-12 15:20:44 +08:00
修复追剧日历页面当日更新标识热更新延迟的问题
- 问题:追剧日历页面当日更新标识热更新有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处理优化
This commit is contained in:
parent
7e12a2da9b
commit
3898c6d41c
@ -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)} 个",
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user