From 4d7634ac673ad6739df2b2dd60a9f532fa997ea7 Mon Sep 17 00:00:00 2001 From: Wendelin <12148533+wendevlin@users.noreply.github.com> Date: Fri, 21 Feb 2025 07:14:10 +0100 Subject: [PATCH] Landing-page: ping supervisor before get network infos (#24330) * Ping supervisor before get network infos * Rename supervisor proxy prefix --- .../src/components/landing-page-network.ts | 24 ++++++++++++++++++- landing-page/src/data/supervisor.ts | 12 ++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/landing-page/src/components/landing-page-network.ts b/landing-page/src/components/landing-page-network.ts index 7e32877c84..bf5a7e9115 100644 --- a/landing-page/src/components/landing-page-network.ts +++ b/landing-page/src/components/landing-page-network.ts @@ -17,6 +17,7 @@ import "../../../src/components/ha-alert"; import { ALTERNATIVE_DNS_SERVERS, getSupervisorNetworkInfo, + pingSupervisor, setSupervisorNetworkDns, } from "../data/supervisor"; import { fireEvent } from "../../../src/common/dom/fire_event"; @@ -85,7 +86,28 @@ class LandingPageNetwork extends LitElement { protected firstUpdated(_changedProperties: PropertyValues): void { super.firstUpdated(_changedProperties); - this._fetchSupervisorInfo(); + this._pingSupervisor(); + } + + private _schedulePingSupervisor() { + setTimeout( + () => this._pingSupervisor(), + SCHEDULE_FETCH_NETWORK_INFO_SECONDS * 1000 + ); + } + + private async _pingSupervisor() { + try { + const response = await pingSupervisor(); + if (!response.ok) { + throw new Error("Failed to ping supervisor, assume update in progress"); + } + this._fetchSupervisorInfo(); + } catch (err) { + // eslint-disable-next-line no-console + console.error(err); + this._schedulePingSupervisor(); + } } private _scheduleFetchSupervisorInfo() { diff --git a/landing-page/src/data/supervisor.ts b/landing-page/src/data/supervisor.ts index 8b75f3f753..41c28297e0 100644 --- a/landing-page/src/data/supervisor.ts +++ b/landing-page/src/data/supervisor.ts @@ -18,7 +18,7 @@ export const ALTERNATIVE_DNS_SERVERS: { ]; export async function getSupervisorLogs(lines = 100) { - return fetch(`/supervisor/supervisor/logs?lines=${lines}`, { + return fetch(`/supervisor-api/supervisor/logs?lines=${lines}`, { headers: { Accept: "text/plain", }, @@ -26,22 +26,26 @@ export async function getSupervisorLogs(lines = 100) { } export async function getSupervisorLogsFollow(lines = 500) { - return fetch(`/supervisor/supervisor/logs/follow?lines=${lines}`, { + return fetch(`/supervisor-api/supervisor/logs/follow?lines=${lines}`, { headers: { Accept: "text/plain", }, }); } +export async function pingSupervisor() { + return fetch("/supervisor-api/supervisor/ping"); +} + export async function getSupervisorNetworkInfo() { - return fetch("/supervisor/network/info"); + return fetch("/supervisor-api/network/info"); } export const setSupervisorNetworkDns = async ( dnsServerIndex: number, primaryInterface: string ) => - fetch(`/supervisor/network/interface/${primaryInterface}/update`, { + fetch(`/supervisor-api/network/interface/${primaryInterface}/update`, { method: "POST", body: JSON.stringify({ ipv4: {