From 24866e16ef4e5503a93c9b5cb523d3fefcd3c2ae Mon Sep 17 00:00:00 2001 From: Logan Garbarini Date: Thu, 15 Jan 2026 23:11:51 -0800 Subject: [PATCH] fix: invalidate cache on web uploads and opds downloads --- .../browser/OpdsBookBrowserActivity.cpp | 7 ++++++ src/network/CrossPointWebServer.cpp | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/activities/browser/OpdsBookBrowserActivity.cpp b/src/activities/browser/OpdsBookBrowserActivity.cpp index 4e0a08d..677f9ca 100644 --- a/src/activities/browser/OpdsBookBrowserActivity.cpp +++ b/src/activities/browser/OpdsBookBrowserActivity.cpp @@ -1,5 +1,6 @@ #include "OpdsBookBrowserActivity.h" +#include #include #include #include @@ -355,6 +356,12 @@ void OpdsBookBrowserActivity::downloadBook(const OpdsEntry& book) { if (result == HttpDownloader::OK) { Serial.printf("[%lu] [OPDS] Download complete: %s\n", millis(), filename.c_str()); + + // Invalidate any existing cache for this file to prevent stale metadata issues + Epub epub(filename, "/.crosspoint"); + epub.clearCache(); + Serial.printf("[%lu] [OPDS] Cleared cache for: %s\n", millis(), filename.c_str()); + state = BrowserState::BROWSING; updateRequired = true; } else { diff --git a/src/network/CrossPointWebServer.cpp b/src/network/CrossPointWebServer.cpp index 23ba36b..b869398 100644 --- a/src/network/CrossPointWebServer.cpp +++ b/src/network/CrossPointWebServer.cpp @@ -1,6 +1,7 @@ #include "CrossPointWebServer.h" #include +#include #include #include #include @@ -28,6 +29,16 @@ size_t wsUploadSize = 0; size_t wsUploadReceived = 0; unsigned long wsUploadStartTime = 0; bool wsUploadInProgress = false; + +// Helper function to clear epub cache after upload +void clearEpubCacheIfNeeded(const String& filePath) { + // Only clear cache for .epub files + if (filePath.endsWith(".epub") || filePath.endsWith(".EPUB")) { + Epub epub(filePath.c_str(), "/.crosspoint"); + epub.clearCache(); + Serial.printf("[%lu] [WEB] Cleared epub cache for: %s\n", millis(), filePath.c_str()); + } +} } // namespace // File listing page template - now using generated headers: @@ -500,6 +511,12 @@ void CrossPointWebServer::handleUpload() const { uploadFileName.c_str(), uploadSize, elapsed, avgKbps); Serial.printf("[%lu] [WEB] [UPLOAD] Diagnostics: %d writes, total write time: %lu ms (%.1f%%)\n", millis(), writeCount, totalWriteTime, writePercent); + + // Clear epub cache to prevent stale metadata issues when overwriting files + String filePath = uploadPath; + if (!filePath.endsWith("/")) filePath += "/"; + filePath += uploadFileName; + clearEpubCacheIfNeeded(filePath); } } } else if (upload.status == UPLOAD_FILE_ABORTED) { @@ -787,6 +804,12 @@ void CrossPointWebServer::onWebSocketEvent(uint8_t num, WStype_t type, uint8_t* Serial.printf("[%lu] [WS] Upload complete: %s (%d bytes in %lu ms, %.1f KB/s)\n", millis(), wsUploadFileName.c_str(), wsUploadSize, elapsed, kbps); + // Clear epub cache to prevent stale metadata issues when overwriting files + String filePath = wsUploadPath; + if (!filePath.endsWith("/")) filePath += "/"; + filePath += wsUploadFileName; + clearEpubCacheIfNeeded(filePath); + wsServer->sendTXT(num, "DONE"); lastProgressSent = 0; }