fix: invalidate cache on web uploads and opds downloads

This commit is contained in:
Logan Garbarini 2026-01-15 23:11:51 -08:00
parent 6d68466891
commit 24866e16ef
2 changed files with 30 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include "OpdsBookBrowserActivity.h" #include "OpdsBookBrowserActivity.h"
#include <Epub.h>
#include <GfxRenderer.h> #include <GfxRenderer.h>
#include <HardwareSerial.h> #include <HardwareSerial.h>
#include <WiFi.h> #include <WiFi.h>
@ -355,6 +356,12 @@ void OpdsBookBrowserActivity::downloadBook(const OpdsEntry& book) {
if (result == HttpDownloader::OK) { if (result == HttpDownloader::OK) {
Serial.printf("[%lu] [OPDS] Download complete: %s\n", millis(), filename.c_str()); 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; state = BrowserState::BROWSING;
updateRequired = true; updateRequired = true;
} else { } else {

View File

@ -1,6 +1,7 @@
#include "CrossPointWebServer.h" #include "CrossPointWebServer.h"
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <Epub.h>
#include <FsHelpers.h> #include <FsHelpers.h>
#include <SDCardManager.h> #include <SDCardManager.h>
#include <WiFi.h> #include <WiFi.h>
@ -28,6 +29,16 @@ size_t wsUploadSize = 0;
size_t wsUploadReceived = 0; size_t wsUploadReceived = 0;
unsigned long wsUploadStartTime = 0; unsigned long wsUploadStartTime = 0;
bool wsUploadInProgress = false; 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 } // namespace
// File listing page template - now using generated headers: // File listing page template - now using generated headers:
@ -500,6 +511,12 @@ void CrossPointWebServer::handleUpload() const {
uploadFileName.c_str(), uploadSize, elapsed, avgKbps); uploadFileName.c_str(), uploadSize, elapsed, avgKbps);
Serial.printf("[%lu] [WEB] [UPLOAD] Diagnostics: %d writes, total write time: %lu ms (%.1f%%)\n", millis(), Serial.printf("[%lu] [WEB] [UPLOAD] Diagnostics: %d writes, total write time: %lu ms (%.1f%%)\n", millis(),
writeCount, totalWriteTime, writePercent); 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) { } 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(), Serial.printf("[%lu] [WS] Upload complete: %s (%d bytes in %lu ms, %.1f KB/s)\n", millis(),
wsUploadFileName.c_str(), wsUploadSize, elapsed, kbps); 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"); wsServer->sendTXT(num, "DONE");
lastProgressSent = 0; lastProgressSent = 0;
} }