#pragma once #include #include #include // Structure to hold file information struct FileInfo { String name; size_t size; bool isEpub; bool isDirectory; }; class CrossPointWebServer { public: CrossPointWebServer(); ~CrossPointWebServer(); // Start the web server (call after WiFi is connected) void begin(); // Stop the web server void stop(); // Call this periodically to handle client requests void handleClient() const; // Check if server is running bool isRunning() const { return running; } // Get the port number uint16_t getPort() const { return port; } private: std::unique_ptr server = nullptr; std::unique_ptr wsServer = nullptr; bool running = false; bool apMode = false; // true when running in AP mode, false for STA mode uint16_t port = 80; uint16_t wsPort = 81; // WebSocket port // WebSocket upload state void onWebSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length); static void wsEventCallback(uint8_t num, WStype_t type, uint8_t* payload, size_t length); // File scanning void scanFiles(const char* path, const std::function& callback) const; String formatFileSize(size_t bytes) const; bool isEpubFile(const String& filename) const; // Request handlers void handleRoot() const; void handleNotFound() const; void handleStatus() const; void handleFileList() const; void handleFileListData() const; void handleUpload() const; void handleUploadPost() const; void handleCreateFolder() const; void handleDelete() const; };