Files
ink-board/main/ui/apps/iotdis/web/web_handlers.h
GW_MC e467951b8c feat: Implement Discord app UI and settings management
- Added MainUI class for displaying voice state, status icon, and buttons.
- Introduced MainUIHandler to manage UI interactions and bridge communication.
- Created SettingsUI for displaying QR code and configuration instructions.
- Implemented SettingsUIHandler to manage settings and web server interactions.
- Developed WebHandler for handling HTTP requests for settings configuration.
- Updated AppRegistry to initialize with the new Discord app descriptor.
- Enhanced InteractionHandler to support keyboard interactions across app switches.
- Updated UIHandler to manage app switching and rendering of app icons.
- Enabled QR code support in LVGL configuration.
2026-02-02 20:47:27 +08:00

82 lines
2.2 KiB
C++

#pragma once
#include "esp_http_server.h"
#include <string>
#include "network/web_server_handler.h"
#include "ui/apps/iotdis/settings/settings_handler.h"
#include "ui/apps/iotdis/bridge/bridge.h"
/**
* @brief HTTP request handlers for Discord Bridge settings web interface
*
* These handlers serve the web configuration page and process
* settings updates and connection tests.
*/
class WebHandler {
public:
WebHandler(
SettingHandler* setting_handler,
IotDisBridge* bridge
) :
web_server_(std::make_unique<WebServerHandler>())
, setting_handler_(setting_handler)
, bridge_(bridge) { }
~WebHandler();
esp_err_t start_web_server();
esp_err_t stop_web_server();
std::string get_url() const;
std::string get_device_ip() const;
uint16_t get_port() const;
bool is_running() const {
return web_server_ && web_server_->is_running();
}
private:
std::string generate_auth_key_();
esp_err_t register_web_endpoints_();
/**
* @brief Serve the main settings configuration page
*
* Validates authentication and serves an HTML form with current settings.
* Requires auth query parameter matching the session key.
*
* @param req HTTP request object
* @return ESP_OK on success
*/
static esp_err_t settings_page_handler_(httpd_req_t* req);
/**
* @brief Save bridge connection settings
*
* Parses POST data containing ip, port, and localPort fields.
* Validates and persists settings to NVS storage.
*
* @param req HTTP request object
* @return ESP_OK on success
*/
static esp_err_t save_settings_handler_(httpd_req_t* req);
/**
* @brief Test connection to Discord bridge
*
* Creates temporary UDP client to test connectivity with provided settings.
* Returns JSON response indicating success or failure.
*
* @param req HTTP request object
* @return ESP_OK on success
*/
static esp_err_t test_connection_handler_(httpd_req_t* req);
std::unique_ptr<WebServerHandler> web_server_;
SettingHandler* setting_handler_ = nullptr; ///< Pointer to settings handler (not owned)
std::string auth_key_;
IotDisBridge* bridge_ = nullptr; ///< Pointer to IotDisBridge (not owned)
};