Xteink-X4-crosspoint-reader/src/network/CrossPointWebServer.h
2026-01-04 17:29:47 +02:00

58 lines
1.3 KiB
C++

#pragma once
#include <WebServer.h>
#include <vector>
// 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<WebServer> server = nullptr;
bool running = false;
bool apMode = false; // true when running in AP mode, false for STA mode
uint16_t port = 80;
// File scanning
void scanFiles(const char* path, const std::function<void(FileInfo)>& callback) const;
String formatFileSize(size_t bytes) const;
bool isEpubFile(const String& filename) const;
// Request handlers
void handleStatusPage() 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;
void handleMove() const;
};