waveshaker commited on
Commit
e8df6e1
·
verified ·
1 Parent(s): fcd13f5

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +20 -9
app.js CHANGED
@@ -290,7 +290,7 @@ const BackendAPI = {
290
 
291
  // 6. 轮询任务状态
292
  pollStatus: async function(taskId, callbacks, retries = 0) {
293
- const MAX_RETRIES = 240;
294
 
295
  try {
296
  const res = await fetch(`${API_BASE_URL}/api/status/${taskId}`, {
@@ -839,13 +839,13 @@ async function performHealthCheck() {
839
  setUIState(false);
840
  dot.className = "status-dot online";
841
  wrapper.title = "Backend online, ready to generate!";
842
- // ✅ 只在"从未成功加载过数据"时做全量初始化;
843
- // offline→online 的抖动不再清空用户已选角色 / 触发词面板 / 图库
844
- if (!backendState.hasInitData) {
845
- await loadInitialData();
846
- } else {
847
- console.log("🔄 后端恢复连接,保留当前选中角色与图库");
848
- }
849
  }
850
  } else {
851
  backendState.isReady = false;
@@ -866,8 +866,13 @@ function startHealthPolling() {
866
  backendState.healthInterval = setTimeout(tick, 3000);
867
  }
868
 
 
 
869
  async function loadInitialData() {
870
- if (isInitializing) return;
 
 
 
871
  isInitializing = true;
872
  console.log("🟢 [Init] 开始初始化...");
873
  document.getElementById('unet-select').disabled = true;
@@ -1106,6 +1111,12 @@ async function loadInitialData() {
1106
  } finally {
1107
  isInitializing = false; // ← 新增:允许重连后重新初始化
1108
  document.getElementById('unet-select').disabled = false;
 
 
 
 
 
 
1109
 
1110
  // 等待数据就绪后,平滑移除全局 Loading 遮罩
1111
  const waitForDataAndHideMask = setInterval(() => {
 
290
 
291
  // 6. 轮询任务状态
292
  pollStatus: async function(taskId, callbacks, retries = 0) {
293
+ const MAX_RETRIES = 600;
294
 
295
  try {
296
  const res = await fetch(`${API_BASE_URL}/api/status/${taskId}`, {
 
839
  setUIState(false);
840
  dot.className = "status-dot online";
841
  wrapper.title = "Backend online, ready to generate!";
842
+ console.log("🔄 后端恢复连接");
843
+ }
844
+ // ✅ 初始化与"是否刚恢复连接"解耦:只要还没成功初始化过,每次心跳都给它一次机会。
845
+ // 否则首轮 init 在 isInitializing 期间被丢弃时,这里再也不会重试(永久离线态)。
846
+ // hasInitData=true 后走 else,保留用户已选角色 / 触发词面板 / 图库。
847
+ if (!backendState.hasInitData) {
848
+ await loadInitialData();
849
  }
850
  } else {
851
  backendState.isReady = false;
 
866
  backendState.healthInterval = setTimeout(tick, 3000);
867
  }
868
 
869
+ let _pendingInitRetry = false;
870
+
871
  async function loadInitialData() {
872
+ if (isInitializing) {
873
+ _pendingInitRetry = true; // ← 不丢弃,记一笔
874
+ return;
875
+ }
876
  isInitializing = true;
877
  console.log("🟢 [Init] 开始初始化...");
878
  document.getElementById('unet-select').disabled = true;
 
1111
  } finally {
1112
  isInitializing = false; // ← 新增:允许重连后重新初始化
1113
  document.getElementById('unet-select').disabled = false;
1114
+
1115
+ // ✅ 初始化期间被丢弃的重试,收尾时补一次
1116
+ if (_pendingInitRetry) {
1117
+ _pendingInitRetry = false;
1118
+ if (!backendState.hasInitData) setTimeout(() => loadInitialData(), 0);
1119
+ }
1120
 
1121
  // 等待数据就绪后,平滑移除全局 Loading 遮罩
1122
  const waitForDataAndHideMask = setInterval(() => {