fix web log

This commit is contained in:
proddy
2024-03-13 18:49:38 +01:00
parent bc232fcff2
commit 9af782c485
2 changed files with 14 additions and 20 deletions

View File

@@ -22,10 +22,8 @@ namespace emsesp {
WebLogService::WebLogService(AsyncWebServer * server, SecurityManager * securityManager)
: events_(EVENT_SOURCE_LOG_PATH) {
// set settings
server->on(LOG_SETTINGS_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { setValues(request, json); });
// get settings
server->on(LOG_SETTINGS_PATH, HTTP_GET, [this](AsyncWebServerRequest * request) { getValues(request); });
// get & set settings
server->on(LOG_SETTINGS_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { getSetValues(request, json); });
// for bring back the whole log - is a command, hence a POST
server->on(FETCH_LOG_PATH, HTTP_POST, [this](AsyncWebServerRequest * request) { fetchLog(request); });
@@ -203,11 +201,20 @@ void WebLogService::fetchLog(AsyncWebServerRequest * request) {
}
// sets the values like level after a POST
void WebLogService::setValues(AsyncWebServerRequest * request, JsonVariant json) {
if (!json.is<JsonObject>()) {
void WebLogService::getSetValues(AsyncWebServerRequest * request, JsonVariant json) {
if ((request->method() == HTTP_GET) || (!json.is<JsonObject>())) {
// GET - return the values
auto * response = new AsyncJsonResponse(false);
JsonObject root = response->getRoot();
root["level"] = log_level();
root["max_messages"] = maximum_log_messages();
root["compact"] = compact();
response->setLength();
request->send(response);
return;
}
// POST - write the settings
auto && body = json.as<JsonObject>();
uuid::log::Level level = body["level"];
@@ -222,15 +229,4 @@ void WebLogService::setValues(AsyncWebServerRequest * request, JsonVariant json)
request->send(200); // OK
}
// return the current value settings after a GET
void WebLogService::getValues(AsyncWebServerRequest * request) {
auto * response = new AsyncJsonResponse(false);
JsonObject root = response->getRoot();
root["level"] = log_level();
root["max_messages"] = maximum_log_messages();
root["compact"] = compact();
response->setLength();
request->send(response);
}
} // namespace emsesp