Refactors Calibre Wireless Device & Calibre Library (#404)

Our esp32 consistently dropped the last few packets of the TCP transfer
in the old implementation. Only about 1/5 transfers would complete. I've
refactored that entire system into an actual Calibre Device Plugin that
basically uses the exact same system as the web server's file transfer
protocol. I kept them separate so that we don't muddy up the existing
file transfer stuff even if it's basically the same at the end of the
day I didn't want to limit our ability to change it later.

I've also added basic auth to OPDS and renamed that feature to OPDS
Browser to just disassociate it from Calibre.

---------

Co-authored-by: Arthur Tazhitdinov <lisnake@gmail.com>
Co-authored-by: Dave Allie <dave@daveallie.com>
This commit is contained in:
Justin Mitchell
2026-01-27 06:02:38 -05:00
committed by GitHub
parent 13f0ebed96
commit 3a761b18af
20 changed files with 614 additions and 945 deletions

View File

@@ -2,7 +2,10 @@
#include <WebServer.h>
#include <WebSocketsServer.h>
#include <WiFiUdp.h>
#include <memory>
#include <string>
#include <vector>
// Structure to hold file information
@@ -15,6 +18,16 @@ struct FileInfo {
class CrossPointWebServer {
public:
struct WsUploadStatus {
bool inProgress = false;
size_t received = 0;
size_t total = 0;
std::string filename;
std::string lastCompleteName;
size_t lastCompleteSize = 0;
unsigned long lastCompleteAt = 0;
};
CrossPointWebServer();
~CrossPointWebServer();
@@ -25,11 +38,13 @@ class CrossPointWebServer {
void stop();
// Call this periodically to handle client requests
void handleClient() const;
void handleClient();
// Check if server is running
bool isRunning() const { return running; }
WsUploadStatus getWsUploadStatus() const;
// Get the port number
uint16_t getPort() const { return port; }
@@ -40,6 +55,8 @@ class CrossPointWebServer {
bool apMode = false; // true when running in AP mode, false for STA mode
uint16_t port = 80;
uint16_t wsPort = 81; // WebSocket port
WiFiUDP udp;
bool udpActive = false;
// WebSocket upload state
void onWebSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length);
@@ -56,6 +73,7 @@ class CrossPointWebServer {
void handleStatus() const;
void handleFileList() const;
void handleFileListData() const;
void handleDownload() const;
void handleUpload() const;
void handleUploadPost() const;
void handleCreateFolder() const;