feat: add functionality to remove Bambu credentials and update API handling
This commit is contained in:
parent
024056cb7d
commit
e459b53472
@ -57,6 +57,26 @@
|
||||
toggleOctoFields();
|
||||
};
|
||||
|
||||
function removeBambuCredentials() {
|
||||
fetch('/api/bambu?remove=true')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
document.getElementById('bambuIp').value = '';
|
||||
document.getElementById('bambuSerial').value = '';
|
||||
document.getElementById('bambuCode').value = '';
|
||||
document.getElementById('autoSend').checked = false;
|
||||
document.getElementById('autoSendTime').value = '';
|
||||
document.getElementById('bambuStatusMessage').innerText = 'Bambu Credentials removed!';
|
||||
} else {
|
||||
document.getElementById('bambuStatusMessage').innerText = 'Error while removing Bambu Credentials.';
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
document.getElementById('bambuStatusMessage').innerText = 'Error while removing: ' + error.message;
|
||||
});
|
||||
}
|
||||
|
||||
function checkSpoolmanInstance() {
|
||||
const url = document.getElementById('spoolmanUrl').value;
|
||||
const spoolmanOctoEnabled = document.getElementById('spoolmanOctoEnabled').checked;
|
||||
@ -162,6 +182,7 @@
|
||||
</div>
|
||||
|
||||
<button style="margin: 0;" onclick="saveBambuCredentials()">Save Bambu Credentials</button>
|
||||
<button style="margin: 0;" onclick="removeBambuCredentials()">Remove Bambu Credentials</button>
|
||||
<p id="bambuStatusMessage"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -38,6 +38,32 @@ int ams_count = 0;
|
||||
String amsJsonData; // Speichert das fertige JSON für WebSocket-Clients
|
||||
AMSData ams_data[MAX_AMS]; // Definition des Arrays;
|
||||
|
||||
bool removeBambuCredentials() {
|
||||
if (BambuMqttTask) {
|
||||
vTaskDelete(BambuMqttTask);
|
||||
}
|
||||
|
||||
if (!removeJsonValue("/bambu_credentials.json")) {
|
||||
Serial.println("Fehler beim Löschen der Bambu-Credentials.");
|
||||
return false;
|
||||
}
|
||||
// Löschen der globalen Variablen
|
||||
g_bambu_ip = "";
|
||||
g_bambu_accesscode = "";
|
||||
g_bambu_serialnr = "";
|
||||
bambu_ip = nullptr;
|
||||
bambu_accesscode = nullptr;
|
||||
bambu_serialnr = nullptr;
|
||||
autoSendToBambu = false;
|
||||
autoSetToBambuSpoolId = 0;
|
||||
ams_count = 0;
|
||||
amsJsonData = "";
|
||||
|
||||
bambuDisabled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool saveBambuCredentials(const String& ip, const String& serialnr, const String& accesscode, bool autoSend, const String& autoSendTime) {
|
||||
if (BambuMqttTask) {
|
||||
vTaskDelete(BambuMqttTask);
|
||||
|
@ -32,6 +32,7 @@ extern bool autoSendToBambu;
|
||||
extern int autoSetToBambuSpoolId;
|
||||
extern bool bambuDisabled;
|
||||
|
||||
bool removeBambuCredentials();
|
||||
bool loadBambuCredentials();
|
||||
bool saveBambuCredentials(const String& bambu_ip, const String& bambu_serialnr, const String& bambu_accesscode, const bool autoSend, const String& autoSendTime);
|
||||
bool setupMqtt();
|
||||
|
@ -1,6 +1,20 @@
|
||||
#include "commonFS.h"
|
||||
#include <LittleFS.h>
|
||||
|
||||
bool removeJsonValue(const char* filename) {
|
||||
File file = LittleFS.open(filename, "r");
|
||||
if (!file) {
|
||||
return true;
|
||||
}
|
||||
file.close();
|
||||
if (!LittleFS.remove(filename)) {
|
||||
Serial.print("Fehler beim Löschen der Datei: ");
|
||||
Serial.println(filename);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool saveJsonValue(const char* filename, const JsonDocument& doc) {
|
||||
File file = LittleFS.open(filename, "w");
|
||||
if (!file) {
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <LittleFS.h>
|
||||
|
||||
bool removeJsonValue(const char* filename);
|
||||
bool saveJsonValue(const char* filename, const JsonDocument& doc);
|
||||
bool loadJsonValue(const char* filename, JsonDocument& doc);
|
||||
void initializeFileSystem();
|
||||
|
@ -313,6 +313,15 @@ void setupWebserver(AsyncWebServer &server) {
|
||||
|
||||
// Route für das Überprüfen der Bambu-Instanz
|
||||
server.on("/api/bambu", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
if (request->hasParam("remove")) {
|
||||
if (removeBambuCredentials()) {
|
||||
request->send(200, "application/json", "{\"success\": true}");
|
||||
} else {
|
||||
request->send(500, "application/json", "{\"success\": false, \"error\": \"Fehler beim Löschen der Bambu-Credentials\"}");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!request->hasParam("bambu_ip") || !request->hasParam("bambu_serialnr") || !request->hasParam("bambu_accesscode")) {
|
||||
request->send(400, "application/json", "{\"success\": false, \"error\": \"Missing parameter\"}");
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user