merge all URI handlers into a single dispatch function

This commit is contained in:
proddy
2026-05-19 21:28:30 +02:00
parent d670bc2b07
commit 3fd0573339
10 changed files with 225 additions and 124 deletions

View File

@@ -25,10 +25,14 @@ uint16_t WebAPIService::api_fails_ = 0;
WebAPIService::WebAPIService(AsyncWebServer * server, SecurityManager * securityManager)
: _securityManager(securityManager) {
AsyncCallbackJsonWebHandler * jsonHandler = new AsyncCallbackJsonWebHandler(EMSESP_API_SERVICE_PATH);
jsonHandler->setMethod(HTTP_POST | HTTP_GET);
jsonHandler->onRequest([this](AsyncWebServerRequest * request, JsonVariant json) { webAPIService(request, json); });
server->addHandler(jsonHandler);
// parse() does its own per-request admin check (with notoken_api), so no predicate.
// /api also matches /api/<device>/<entity> via the route's backward-compatible URI matcher.
securityManager->addEndpoint(
server,
EMSESP_API_SERVICE_PATH,
AuthenticationPredicates::NONE_REQUIRED,
[this](AsyncWebServerRequest * request, JsonVariant json) { webAPIService(request, json); },
HTTP_POST | HTTP_GET);
}
// POST|GET api/

View File

@@ -32,9 +32,6 @@ WebLogService::WebLogService(AsyncWebServer * server, SecurityManager * security
[this](AsyncWebServerRequest * request, JsonVariant json) { getSetValues(request, json); },
HTTP_ANY);
// Add authentication filter to EventSource
// EventSource (SSE) cannot use custom headers, so authentication is done via URL parameter
// events_.setFilter(securityManager->filterRequest(AuthenticationPredicates::IS_AUTHENTICATED));
server->addHandler(&events_);
}
@@ -211,6 +208,7 @@ void WebLogService::getSetValues(AsyncWebServerRequest * request, JsonVariant js
return;
}
// POST - write the settings
level_ = json["level"];
maximum_log_messages_ = json["max_messages"];
@@ -234,6 +232,7 @@ void WebLogService::getSetValues(AsyncWebServerRequest * request, JsonVariant js
settings.weblog_buffer = maximum_log_messages_;
return StateUpdateResult::CHANGED;
});
request->send(200); // OK
}