Update app.js
Browse files
app.js
CHANGED
|
@@ -290,7 +290,7 @@ const BackendAPI = {
|
|
| 290 |
|
| 291 |
// 6. 轮询任务状态
|
| 292 |
pollStatus: async function(taskId, callbacks, retries = 0) {
|
| 293 |
-
const MAX_RETRIES =
|
| 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 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 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)
|
|
|
|
|
|
|
|
|
|
| 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(() => {
|