From 9da2c650189b82ab7c88a42baa8ca974a89b5023 Mon Sep 17 00:00:00 2001 From: dentra Date: Fri, 9 Aug 2024 18:07:22 +0300 Subject: [PATCH] settings: fix arduino compilation --- components/settings/settings.cpp | 33 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 3a46f93..4c9c77a 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -1,7 +1,6 @@ #include "esphome/core/log.h" #include "esphome/core/defines.h" #include "esphome/core/helpers.h" -// #include "esphome/" #include "json_writer.h" #include "settings.h" @@ -34,9 +33,18 @@ std::string Settings::url_(const char *path) { void Settings::redirect_home_(AsyncWebServerRequest *request) { if (*this->base_url_.rbegin() != '/') { - request->redirect(this->base_url_ + '/'); + const auto url = this->base_url_ + '/'; +#ifdef USE_ARDUINO + request->redirect(url.c_str()); +#else + request->redirect(url); +#endif } else { +#ifdef USE_ARDUINO + request->redirect(this->base_url_.c_str()); +#else request->redirect(this->base_url_); +#endif } } @@ -56,8 +64,15 @@ void Settings::handleRequest(AsyncWebServerRequest *request) { // NOLINT(readab return request->requestAuthentication(); } +#ifdef USE_ARDUINO + // arduino returns String but not std::string + const std::string url = request->url().c_str(); +#else + const std::string url = request->url(); +#endif + if (request->method() == HTTP_POST) { - if (request->url() == this->url_("reset")) { + if (url == this->url_("reset")) { this->handle_reset_(request); } else { this->handle_save_(request); @@ -69,23 +84,17 @@ void Settings::handleRequest(AsyncWebServerRequest *request) { // NOLINT(readab return; } - if (request->url() == this->url_("settings.json")) { + if (url == this->url_("settings.json")) { this->handle_json_(request); return; } - if (request->url() == this->url_("settings.js")) { + if (url == this->url_("settings.js")) { this->handle_js_(request); return; } -#ifdef USE_ARDUINO - // arduino returns String but not std::string - if (!request->url().endsWith("/")) -#else - if (*request->url().rbegin() != '/') -#endif - { + if (*url.rbegin() != '/') { this->redirect_home_(request); return; }