Fix hub AI save: background PM2 restart after JSON response.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-08 23:06:31 +08:00
parent 823aeda42a
commit aaa72c7961
5 changed files with 32 additions and 21 deletions
+15 -3
View File
@@ -4409,6 +4409,16 @@
return values;
}
async function parseApiJson(r) {
const ct = (r.headers.get("content-type") || "").toLowerCase();
if (!ct.includes("application/json")) {
const text = await r.text();
const snippet = (text || "").replace(/\s+/g, " ").trim().slice(0, 120);
throw new Error(snippet ? `服务返回非 JSON${snippet}` : `HTTP ${r.status}`);
}
return r.json();
}
async function saveHubAiEnv() {
const status = document.getElementById("hub-ai-env-save-status");
const setStatus = (msg, err) => {
@@ -4423,15 +4433,17 @@
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ values: collectHubAiEnvValues(), restart: true }),
});
const j = await r.json();
const j = await parseApiJson(r);
if (!r.ok) throw new Error(j.detail || j.msg || "保存失败");
if (!j.changed || !Object.keys(j.changed).length) {
setStatus("未修改(与当前配置相同)");
showToast("未修改");
return;
}
setStatus("已同步三所,服务重启中…");
await waitHubHealth();
if (j.restart_required) {
setStatus("已同步三所,服务重启中…");
await waitHubHealth();
}
setStatus("AI 配置已保存并同步至三所实例");
showToast("AI 配置已保存并同步");
await loadHubAiEnvSettings();
+1 -1
View File
@@ -1192,6 +1192,6 @@
<script src="/assets/time_close_ui.js?v=3"></script>
<script src="/assets/options_expiry_countdown.js?v=1"></script>
<script src="/assets/backup.js?v=1"></script>
<script src="/assets/app.js?v=20260708-hub-tp-profit"></script>
<script src="/assets/app.js?v=20260708-hub-ai-save"></script>
</body>
</html>