From 2835e6b021e550da6aa5dbf3a76e8f65d75718b9 Mon Sep 17 00:00:00 2001 From: "Gan, Jimmy" Date: Thu, 26 Feb 2026 03:11:13 +0800 Subject: [PATCH] feat: detect LAN client via /api/client-ip for smart sidebar links --- dashboard/backend/main.py | 4 ++++ dashboard/frontend/src/components/Sidebar.svelte | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dashboard/backend/main.py b/dashboard/backend/main.py index bc057fd..b123541 100644 --- a/dashboard/backend/main.py +++ b/dashboard/backend/main.py @@ -114,6 +114,10 @@ async def startup_event(): async def health(): return {"status": "ok"} +@app.get("/api/client-ip") +async def client_ip(request: Request): + return {"ip": request.client.host} + # Public auth endpoints app.include_router(auth.router, prefix="/api/auth", tags=["auth"]) diff --git a/dashboard/frontend/src/components/Sidebar.svelte b/dashboard/frontend/src/components/Sidebar.svelte index cbd8bb4..ac8b1a3 100644 --- a/dashboard/frontend/src/components/Sidebar.svelte +++ b/dashboard/frontend/src/components/Sidebar.svelte @@ -12,10 +12,10 @@ const TS_IP = "100.78.131.124"; let lanReachable = $state(false); - if (typeof window !== "undefined" && location.hostname !== LAN_IP) { - fetch(`http://${LAN_IP}:4000/`, { mode: "no-cors", signal: AbortSignal.timeout(1500) }) - .then(() => { lanReachable = true; }) - .catch(() => {}); + if (typeof window !== "undefined") { + fetch("/api/client-ip").then(r => r.json()).then(d => { + if (d.ip?.startsWith("192.168.31.")) lanReachable = true; + }).catch(() => {}); } const media = [