fix: bug
This commit is contained in:
36
app/static/guide.js
Normal file
36
app/static/guide.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const guideGetServerIpBtn = document.getElementById("getServerIpBtn");
|
||||
|
||||
async function showGuideAlert(message, title = "提示") {
|
||||
if (typeof window.uiAlert === "function") {
|
||||
await window.uiAlert(message, title);
|
||||
return;
|
||||
}
|
||||
window.alert(message);
|
||||
}
|
||||
|
||||
if (guideGetServerIpBtn) {
|
||||
guideGetServerIpBtn.addEventListener("click", async () => {
|
||||
const idleText = "获取服务器IP";
|
||||
guideGetServerIpBtn.disabled = true;
|
||||
guideGetServerIpBtn.textContent = "获取中...";
|
||||
try {
|
||||
const res = await fetch("/api/tools/server-ip");
|
||||
const data = await res.json();
|
||||
if (!res.ok || !data.ok) {
|
||||
await showGuideAlert((data && data.detail) || "获取服务器IP失败,请稍后重试", "获取失败");
|
||||
return;
|
||||
}
|
||||
const ip = String(data.ip || "").trim();
|
||||
if (!ip) {
|
||||
await showGuideAlert("服务器IP为空,请稍后重试", "获取失败");
|
||||
return;
|
||||
}
|
||||
await showGuideAlert(`当前服务器IP:${ip}`, "API IP白名单");
|
||||
} catch {
|
||||
await showGuideAlert("获取服务器IP失败,请稍后重试", "获取失败");
|
||||
} finally {
|
||||
guideGetServerIpBtn.disabled = false;
|
||||
guideGetServerIpBtn.textContent = idleText;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user