changed direct backend access

This commit is contained in:
Carsten Graf
2025-06-13 23:11:58 +02:00
parent b6fa2d69e7
commit abedcc8fb1
5 changed files with 58 additions and 30 deletions

View File

@@ -66,6 +66,8 @@
// Globale Variablen // Globale Variablen
let rfidData = []; let rfidData = [];
let isLoading = false; let isLoading = false;
let DBUrl = "db.reptilfpv.de:3000";
var APIKey;
// Maximales Datum auf heute setzen // Maximales Datum auf heute setzen
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
@@ -244,6 +246,7 @@
window.addEventListener('load', function() { window.addEventListener('load', function() {
document.getElementById('uid').focus(); document.getElementById('uid').focus();
checkServerStatus(); checkServerStatus();
loadLicence();
}); });
// Enter-Taste in UID Feld zum nächsten Feld springen // Enter-Taste in UID Feld zum nächsten Feld springen
@@ -348,6 +351,18 @@
return false; return false;
} }
} }
function loadLicence() {
fetch("/api/get-licence")
.then((response) => response.json())
.then((data) => {
APIKey = data.licence || "";
})
.catch((error) =>
showMessage("Fehler beim Laden der Lizenz", "error")
);
}
</script> </script>
</body> </body>
</html> </html>

View File

@@ -264,14 +264,13 @@
// Einstellungen laden beim Seitenaufruf // Einstellungen laden beim Seitenaufruf
window.onload = function () { window.onload = function () {
loadLicence();
loadSettings(); loadSettings();
loadWifiSettings(); loadWifiSettings();
loadSystemInfo(); loadSystemInfo();
loadCurrentTime(); loadCurrentTime();
updateCurrentTimeDisplay(); updateCurrentTimeDisplay();
loadLicence();
loadWifiSettings(); loadWifiSettings();
loadLocations();
}; };
// Aktuelle Zeit anzeigen (Live-Update) // Aktuelle Zeit anzeigen (Live-Update)
@@ -460,7 +459,7 @@
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
document.getElementById("licencekey").value = data.licence || ""; document.getElementById("licencekey").value = data.licence || "";
loadLocations();
}) })
.catch((error) => .catch((error) =>
showMessage("Fehler beim Laden der Lizenz", "error") showMessage("Fehler beim Laden der Lizenz", "error")
@@ -790,9 +789,16 @@
//location functions //location functions
// Locations laden und Dropdown befüllen // Locations laden und Dropdown befüllen
function loadLocations() { function loadLocations() {
fetch("/api/location/") const licence = document.getElementById("licencekey").value; // Get the licence key from the input field
fetch("http://db.reptilfpv.de:3000/api/location/", {
method: "GET",
headers: {
Authorization: `Bearer ${licence}`, // Add Bearer token using licenkey
},
})
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
const select = document.getElementById("locationSelect"); const select = document.getElementById("locationSelect");
// Vorhandene Optionen löschen (außer der ersten "Bitte wählen...") // Vorhandene Optionen löschen (außer der ersten "Bitte wählen...")
@@ -800,6 +806,7 @@
select.removeChild(select.lastChild); select.removeChild(select.lastChild);
} }
// Neue Optionen aus Backend-Response hinzufügen
// Neue Optionen aus Backend-Response hinzufügen // Neue Optionen aus Backend-Response hinzufügen
data.forEach((location) => { data.forEach((location) => {
const option = document.createElement("option"); const option = document.createElement("option");
@@ -813,9 +820,9 @@
}) })
.catch((error) => { .catch((error) => {
console.log("Locations konnten nicht geladen werden:", error); console.log("Locations konnten nicht geladen werden:", error);
showMessage("Fehler beim Laden der Standorte", "error"); showMessage("Fehler beim Laden der Locations", "error");
}); });
} }
// Aktuell gespeicherten Standort laden // Aktuell gespeicherten Standort laden
function loadCurrentLocation() { function loadCurrentLocation() {

View File

@@ -5,9 +5,13 @@
const char* BACKEND_SERVER = "http://db.reptilfpv.de:3000"; const char* BACKEND_SERVER = "http://db.reptilfpv.de:3000";
const char* BACKEND_TOKEN = "a4514dc0-15f5-4299-8826-fffb3139d39c"; String BACKEND_TOKEN = licence; // Use the licence as the token for authentication
bool backendOnline() { bool backendOnline() {
Serial.println(licence);
if (WiFi.status() != WL_CONNECTED) { if (WiFi.status() != WL_CONNECTED) {
Serial.println("No WiFi connection."); Serial.println("No WiFi connection.");
return false; return false;

View File

@@ -287,6 +287,7 @@ void setup() {
loadBestTimes(); loadBestTimes();
loadSettings(); loadSettings();
loadWifiSettings(); loadWifiSettings();
loadLocationSettings();
setupWifi(); // WiFi initialisieren setupWifi(); // WiFi initialisieren
setupOTA(&server); setupOTA(&server);

View File

@@ -240,6 +240,7 @@ server.on("/api/set-location", HTTP_POST, [](AsyncWebServerRequest *request) {
server.on("/api/get-location", HTTP_GET, [](AsyncWebServerRequest *request){ server.on("/api/get-location", HTTP_GET, [](AsyncWebServerRequest *request){
DynamicJsonDocument doc(128); DynamicJsonDocument doc(128);
loadLocationSettings();
doc["locationid"] = masterlocation ? masterlocation : ""; doc["locationid"] = masterlocation ? masterlocation : "";
String result; String result;
serializeJson(doc, result); serializeJson(doc, result);