From 07277985b1dd06196c0ff3dfa50be15b1b90faaa Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sat, 10 Jan 2026 08:46:16 +1100 Subject: [PATCH] FE: refactor apiBase Signed-off-by: jokob-sk --- docs/DEBUG_INVALID_JSON.md | 1 - front/deviceDetails.php | 4 +- front/deviceDetailsEdit.php | 10 ++--- front/deviceDetailsEvents.php | 4 +- front/deviceDetailsPresence.php | 4 +- front/deviceDetailsSessions.php | 4 +- front/deviceDetailsTools.php | 38 +++++----------- front/php/server/devices.php | 36 --------------- front/plugins/_publisher_mqtt/mqtt.py | 2 +- front/presence.php | 65 ++++++++++++++++++++------- 10 files changed, 76 insertions(+), 92 deletions(-) diff --git a/docs/DEBUG_INVALID_JSON.md b/docs/DEBUG_INVALID_JSON.md index 00b82b0b..c6ef3ad2 100755 --- a/docs/DEBUG_INVALID_JSON.md +++ b/docs/DEBUG_INVALID_JSON.md @@ -9,7 +9,6 @@ Check the the HTTP response of the failing backend call by following these steps - Copy the URL causing the error and enter it in the address bar of your browser directly and hit enter. The copied URLs could look something like this (notice the query strings at the end): - `http://:20211/api/table_devices.json?nocache=1704141103121` - - `http://:20211/php/server/devices.php?action=getDevicesTotals` - Post the error response in the existing issue thread on GitHub or create a new issue and include the redacted response of the failing query. diff --git a/front/deviceDetails.php b/front/deviceDetails.php index 36a77b85..7c9f3e2d 100755 --- a/front/deviceDetails.php +++ b/front/deviceDetails.php @@ -418,8 +418,8 @@ async function renderSmallBoxes() { // Get data from the server const apiToken = getSetting("API_TOKEN"); - const apiBase = getApiBase(); - const url = `${apiBase}/device/${getMac()}?period=${encodeURIComponent(period)}`; + const apiBaseUrl = getApiBase(); + const url = `${apiBaseUrl}/device/${getMac()}?period=${encodeURIComponent(period)}`; const response = await fetch(url, { method: "GET", diff --git a/front/deviceDetailsEdit.php b/front/deviceDetailsEdit.php index cd654b4e..caade6da 100755 --- a/front/deviceDetailsEdit.php +++ b/front/deviceDetailsEdit.php @@ -46,8 +46,8 @@ function getDeviceData() { const apiToken = getSetting("API_TOKEN"); let period = $("#period").val() - const apiBase = getApiBase(); - const url = `${apiBase}/device/${mac}?period=${encodeURIComponent(period)}`; + const apiBaseUrl = getApiBase(); + const url = `${apiBaseUrl}/device/${mac}?period=${encodeURIComponent(period)}`; // get data from server $.ajax({ @@ -89,7 +89,7 @@ function getDeviceData() { ] }; - const graphQlUrl = `${apiBase}/graphql`; + const graphQlUrl = `${apiBaseUrl}/graphql`; $.ajax({ url: graphQlUrl, @@ -354,7 +354,7 @@ function setDeviceData(direction = '', refreshCallback = '') { showSpinner(); const apiToken = getSetting("API_TOKEN"); // dynamic token - const apiBase = getApiBase(); + const apiBaseUrl = getApiBase(); mac = $('#NEWDEV_devMac').val(); @@ -402,7 +402,7 @@ function setDeviceData(direction = '', refreshCallback = '') { $.ajax({ - url: `${apiBase}/device/${encodeURIComponent(mac)}`, + url: `${apiBaseUrl}/device/${encodeURIComponent(mac)}`, type: "POST", headers: { "Authorization": "Bearer " + apiToken, diff --git a/front/deviceDetailsEvents.php b/front/deviceDetailsEvents.php index 69a6d96d..b11e4b52 100755 --- a/front/deviceDetailsEvents.php +++ b/front/deviceDetailsEvents.php @@ -50,8 +50,8 @@ function loadEventsData() { const apiToken = getSetting("API_TOKEN"); - const apiBase = getApiBase(); - const url = `${apiBase}/dbquery/read`; + const apiBaseUrl = getApiBase(); + const url = `${apiBaseUrl}/dbquery/read`; $.ajax({ url: url, diff --git a/front/deviceDetailsPresence.php b/front/deviceDetailsPresence.php index e8bdbae7..7c4833f2 100755 --- a/front/deviceDetailsPresence.php +++ b/front/deviceDetailsPresence.php @@ -38,8 +38,8 @@ function loadPresenceData() { const apiToken = getSetting("API_TOKEN"); - const apiBase = getApiBase(); - const url = `${apiBase}/sessions/calendar`; + const apiBaseUrl = getApiBase(); + const url = `${apiBaseUrl}/sessions/calendar`; $('#calendar').fullCalendar('removeEventSources'); diff --git a/front/deviceDetailsSessions.php b/front/deviceDetailsSessions.php index ddb5806c..ed9a0487 100755 --- a/front/deviceDetailsSessions.php +++ b/front/deviceDetailsSessions.php @@ -105,8 +105,8 @@ function loadSessionsData() { // Build API base const apiToken = getSetting("API_TOKEN"); - const apiBase = getApiBase(); - const url = `${apiBase}/sessions/${getMac()}?period=${encodeURIComponent(period)}`; + const apiBaseUrl = getApiBase(); + const url = `${apiBaseUrl}/sessions/${getMac()}?period=${encodeURIComponent(period)}`; // Call API with Authorization header $.ajax({ diff --git a/front/deviceDetailsTools.php b/front/deviceDetailsTools.php index 469a645a..0c0756ac 100755 --- a/front/deviceDetailsTools.php +++ b/front/deviceDetailsTools.php @@ -211,22 +211,16 @@