Smart LAN detection for sidebar service links

This commit is contained in:
Gan, Jimmy
2026-02-22 16:45:31 +08:00
parent 57f6780d7c
commit 3c186989b1
@@ -11,6 +11,15 @@
{ id: "settings", label: "Settings", icon: "settings" },
];
const LAN_IP = "192.168.1.173";
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(() => {});
}
const external = [
{ label: "Navidrome", href: "https://music.jimmygan.com", icon: "music" },
{ label: "Immich", port: 2283, icon: "image" },
@@ -20,6 +29,9 @@
];
function extHref(port) {
if (lanReachable && location.hostname !== LAN_IP) {
return `http://${LAN_IP}:${port}`;
}
return `${location.protocol}//${location.hostname}:${port}`;
}