Stream CrossPointWebServer data over JSON APIs (#97)

## Summary

* HTML files are now static, streamed directly to the client without
modification
* For any dynamic values, load via JSON APIs
* For files page, we stream the JSON content as we scan the directory to
avoid holding onto too much data

## Additional details

* We were previously building up a very large string all generated on
the X4 directly, we should be leveraging the browser
* Fixes https://github.com/daveallie/crosspoint-reader/issues/94
This commit is contained in:
Dave Allie
2025-12-22 03:19:49 +11:00
committed by GitHub
parent ce37c80c2d
commit 689b539c6b
7 changed files with 970 additions and 993 deletions

View File

@@ -24,7 +24,7 @@ class CrossPointWebServer {
void stop();
// Call this periodically to handle client requests
void handleClient();
void handleClient() const;
// Check if server is running
bool isRunning() const { return running; }
@@ -33,22 +33,23 @@ class CrossPointWebServer {
uint16_t getPort() const { return port; }
private:
WebServer* server = nullptr;
std::unique_ptr<WebServer> server = nullptr;
bool running = false;
uint16_t port = 80;
// File scanning
std::vector<FileInfo> scanFiles(const char* path = "/");
String formatFileSize(size_t bytes);
bool isEpubFile(const String& filename);
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 handleRoot();
void handleNotFound();
void handleStatus();
void handleFileList();
void handleUpload();
void handleUploadPost();
void handleCreateFolder();
void handleDelete();
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;
};