37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
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;
|
||
}
|
||
});
|
||
}
|