Files
AIcreat/app/static/guide.js
2026-04-28 19:16:27 +08:00

37 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}
});
}