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
let rfidData = [];
let isLoading = false;
let DBUrl = "db.reptilfpv.de:3000";
var APIKey;
// Maximales Datum auf heute setzen
document.addEventListener('DOMContentLoaded', function() {
@@ -244,6 +246,7 @@
window.addEventListener('load', function() {
document.getElementById('uid').focus();
checkServerStatus();
loadLicence();
});
// Enter-Taste in UID Feld zum nächsten Feld springen
@@ -333,7 +336,7 @@
async function checkServerStatus() {
try {
const response = await fetch('/api/health');
const response = await fetch('/api/health');
const data = await response.json();
if (!data.status || data.status !== 'connected') {
@@ -348,6 +351,18 @@
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>
</body>
</html>

View File

@@ -264,14 +264,13 @@
// Einstellungen laden beim Seitenaufruf
window.onload = function () {
loadLicence();
loadSettings();
loadWifiSettings();
loadSystemInfo();
loadCurrentTime();
updateCurrentTimeDisplay();
loadLicence();
loadWifiSettings();
loadLocations();
};
// Aktuelle Zeit anzeigen (Live-Update)
@@ -460,7 +459,7 @@
.then((response) => response.json())
.then((data) => {
document.getElementById("licencekey").value = data.licence || "";
loadLocations();
})
.catch((error) =>
showMessage("Fehler beim Laden der Lizenz", "error")
@@ -790,33 +789,41 @@
//location functions
// Locations laden und Dropdown befüllen
function loadLocations() {
fetch("/api/location/")
.then((response) => response.json())
.then((data) => {
const select = document.getElementById("locationSelect");
// Vorhandene Optionen löschen (außer der ersten "Bitte wählen...")
while (select.children.length > 1) {
select.removeChild(select.lastChild);
}
// Neue Optionen aus Backend-Response hinzufügen
data.forEach((location) => {
const option = document.createElement("option");
option.value = location.id;
option.textContent = location.name;
select.appendChild(option);
});
// Aktuell gespeicherten Standort laden
loadCurrentLocation();
})
.catch((error) => {
console.log("Locations konnten nicht geladen werden:", error);
showMessage("Fehler beim Laden der Standorte", "error");
});
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((data) => {
const select = document.getElementById("locationSelect");
// Vorhandene Optionen löschen (außer der ersten "Bitte wählen...")
while (select.children.length > 1) {
select.removeChild(select.lastChild);
}
// Neue Optionen aus Backend-Response hinzufügen
// Neue Optionen aus Backend-Response hinzufügen
data.forEach((location) => {
const option = document.createElement("option");
option.value = location.id;
option.textContent = location.name;
select.appendChild(option);
});
// Aktuell gespeicherten Standort laden
loadCurrentLocation();
})
.catch((error) => {
console.log("Locations konnten nicht geladen werden:", error);
showMessage("Fehler beim Laden der Locations", "error");
});
}
// Aktuell gespeicherten Standort laden
function loadCurrentLocation() {
fetch("/api/get-location")