Consolidate cache directories
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
#include <FsHelpers.h>
|
||||
#include <HalStorage.h>
|
||||
#include <Logging.h>
|
||||
#include <Txt.h>
|
||||
#include <WiFi.h>
|
||||
#include <Xtc.h>
|
||||
#include <esp_task_wdt.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -58,16 +60,25 @@ String wsLastCompleteName;
|
||||
size_t wsLastCompleteSize = 0;
|
||||
unsigned long wsLastCompleteAt = 0;
|
||||
|
||||
// Helper function to clear epub cache after upload
|
||||
void clearEpubCacheIfNeeded(const String& filePath) {
|
||||
void clearBookCacheIfNeeded(const String& filePath) {
|
||||
if (FsHelpers::hasEpubExtension(filePath)) {
|
||||
Epub(filePath.c_str(), "/.crosspoint").clearCache();
|
||||
LOG_DBG("WEB", "Cleared epub cache for: %s", filePath.c_str());
|
||||
} else if (FsHelpers::hasXtcExtension(filePath)) {
|
||||
Xtc(filePath.c_str(), "/.crosspoint").clearCache();
|
||||
LOG_DBG("WEB", "Cleared xtc cache for: %s", filePath.c_str());
|
||||
} else if (FsHelpers::hasTxtExtension(filePath) || FsHelpers::hasMarkdownExtension(filePath)) {
|
||||
const Txt txt(filePath.c_str(), "/.crosspoint");
|
||||
const String cachePath = txt.getCachePath().c_str();
|
||||
if (Storage.exists(cachePath.c_str())) {
|
||||
Storage.removeDir(cachePath.c_str());
|
||||
LOG_DBG("WEB", "Cleared txt cache for: %s", filePath.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively clear epub caches for all EPUBs inside a directory
|
||||
void clearEpubCachesInDirectory(const String& dirPath) {
|
||||
// Recursively clear book caches for all ebooks inside a directory
|
||||
void clearBookCachesInDirectory(const String& dirPath) {
|
||||
esp_task_wdt_reset();
|
||||
yield();
|
||||
FsFile dir = Storage.open(dirPath.c_str());
|
||||
@@ -86,10 +97,10 @@ void clearEpubCachesInDirectory(const String& dirPath) {
|
||||
childPath += name;
|
||||
if (entry.isDirectory()) {
|
||||
entry.close();
|
||||
clearEpubCachesInDirectory(childPath);
|
||||
clearBookCachesInDirectory(childPath);
|
||||
} else {
|
||||
entry.close();
|
||||
clearEpubCacheIfNeeded(childPath);
|
||||
clearBookCacheIfNeeded(childPath);
|
||||
}
|
||||
entry = dir.openNextFile();
|
||||
}
|
||||
@@ -1210,7 +1221,7 @@ void CrossPointWebServer::handleDelete() const {
|
||||
// It's a file (or couldn't open as dir) — remove file
|
||||
if (f) f.close();
|
||||
success = Storage.remove(itemPath.c_str());
|
||||
clearEpubCacheIfNeeded(itemPath);
|
||||
clearBookCacheIfNeeded(itemPath);
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
|
||||
Reference in New Issue
Block a user