From 2f8bcaa29107a365ab29ebb573ed2f597a0b64a5 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Tue, 12 Nov 2024 11:58:56 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=BC=20Removes=20HttpEndpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ESP32-sveltekit/CameraSettingsService.h | 1 - esp32/lib/ESP32-sveltekit/HttpEndpoint.h | 75 ------------------- esp32/lib/ESP32-sveltekit/Peripherals.h | 1 - esp32/lib/ESP32-sveltekit/ServoController.h | 1 - 4 files changed, 78 deletions(-) delete mode 100644 esp32/lib/ESP32-sveltekit/HttpEndpoint.h diff --git a/esp32/lib/ESP32-sveltekit/CameraSettingsService.h b/esp32/lib/ESP32-sveltekit/CameraSettingsService.h index 4df09009..502a741b 100644 --- a/esp32/lib/ESP32-sveltekit/CameraSettingsService.h +++ b/esp32/lib/ESP32-sveltekit/CameraSettingsService.h @@ -8,7 +8,6 @@ namespace Camera { #include #include #include -#include #include #include #include diff --git a/esp32/lib/ESP32-sveltekit/HttpEndpoint.h b/esp32/lib/ESP32-sveltekit/HttpEndpoint.h deleted file mode 100644 index 280d3a9c..00000000 --- a/esp32/lib/ESP32-sveltekit/HttpEndpoint.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef HttpEndpoint_h -#define HttpEndpoint_h - -#include -#include - -#include - -#define HTTP_ENDPOINT_ORIGIN_ID "http" -#define HTTPS_ENDPOINT_ORIGIN_ID "https" - -template -class HttpEndpoint { - protected: - JsonStateReader _stateReader; - JsonStateUpdater _stateUpdater; - StatefulService *_statefulService; - size_t _bufferSize; - PsychicHttpServer *_server; - const char *_servicePath; - - public: - HttpEndpoint(JsonStateReader stateReader, JsonStateUpdater stateUpdater, StatefulService *statefulService, - PsychicHttpServer *server, const char *servicePath) - : _stateReader(stateReader), - _stateUpdater(stateUpdater), - _statefulService(statefulService), - _server(server), - _servicePath(servicePath) {} - - // register the web server on() endpoints - void begin() { -// OPTIONS (for CORS preflight) -#ifdef ENABLE_CORS - _server->on(_servicePath, HTTP_OPTIONS, [this](PsychicRequest *request) { return request->reply(200); }); -#endif - - // GET - _server->on(_servicePath, HTTP_GET, [this](PsychicRequest *request) { - PsychicJsonResponse response = PsychicJsonResponse(request, false); - JsonObject jsonObject = response.getRoot(); - _statefulService->read(jsonObject, _stateReader); - return response.send(); - }); - ESP_LOGV("HttpEndpoint", "Registered GET endpoint: %s", _servicePath); - - // POST - _server->on(_servicePath, HTTP_POST, [this](PsychicRequest *request, JsonVariant &json) { - if (!json.is()) { - return request->reply(400); - } - - JsonObject jsonObject = json.as(); - StateUpdateResult outcome = _statefulService->updateWithoutPropagation(jsonObject, _stateUpdater); - - if (outcome == StateUpdateResult::ERROR) { - return request->reply(400); - } else if ((outcome == StateUpdateResult::CHANGED)) { - // persist the changes to the FS - _statefulService->callUpdateHandlers(HTTP_ENDPOINT_ORIGIN_ID); - } - - PsychicJsonResponse response = PsychicJsonResponse(request, false); - jsonObject = response.getRoot(); - - _statefulService->read(jsonObject, _stateReader); - - return response.send(); - }); - - ESP_LOGV("HttpEndpoint", "Registered POST endpoint: %s", _servicePath); - } -}; - -#endif diff --git a/esp32/lib/ESP32-sveltekit/Peripherals.h b/esp32/lib/ESP32-sveltekit/Peripherals.h index de484cc4..99142ee9 100644 --- a/esp32/lib/ESP32-sveltekit/Peripherals.h +++ b/esp32/lib/ESP32-sveltekit/Peripherals.h @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/esp32/lib/ESP32-sveltekit/ServoController.h b/esp32/lib/ESP32-sveltekit/ServoController.h index 49b2a869..5efbd2b9 100644 --- a/esp32/lib/ESP32-sveltekit/ServoController.h +++ b/esp32/lib/ESP32-sveltekit/ServoController.h @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include