refactor: unify book cache clearing for epub, txt, and xtc files (#1875)

This commit is contained in:
WuTofu
2026-05-21 14:44:10 +03:00
committed by GitHub
parent dc404b41c7
commit 2dd491b62e
9 changed files with 77 additions and 32 deletions
+5 -11
View File
@@ -1,11 +1,12 @@
#include "WebDAVHandler.h"
#include <Epub.h>
#include <FsHelpers.h>
#include <HalStorage.h>
#include <Logging.h>
#include <esp_task_wdt.h>
#include "util/BookCacheUtils.h"
namespace {
constexpr const char* HIDDEN_ITEMS[] = {"System Volume Information", "XTCache"};
@@ -384,7 +385,7 @@ void WebDAVHandler::handlePut(WebServer& s) {
return;
}
clearEpubCacheIfNeeded(path);
clearBookCache(path.c_str());
s.send(_putExisted ? 204 : 201);
LOG_DBG("DAV", "PUT complete: %s", path.c_str());
}
@@ -433,7 +434,7 @@ void WebDAVHandler::handleDelete(WebServer& s) {
}
} else {
file.close();
clearEpubCacheIfNeeded(path);
clearBookCache(path.c_str());
if (Storage.remove(path.c_str())) {
s.send(204);
} else {
@@ -542,7 +543,7 @@ void WebDAVHandler::handleMove(WebServer& s) {
return;
}
clearEpubCacheIfNeeded(srcPath);
clearBookCache(srcPath.c_str());
bool success = file.rename(dstPath.c_str());
file.close();
@@ -797,13 +798,6 @@ bool WebDAVHandler::getOverwrite(WebServer& s) const {
return true; // Default is T
}
void WebDAVHandler::clearEpubCacheIfNeeded(const String& path) const {
if (FsHelpers::hasEpubExtension(path)) {
Epub(path.c_str(), "/.crosspoint").clearCache();
LOG_DBG("DAV", "Cleared epub cache for: %s", path.c_str());
}
}
String WebDAVHandler::getMimeType(const String& path) const {
if (FsHelpers::hasEpubExtension(path)) return "application/epub+zip";
if (FsHelpers::checkFileExtension(path, ".pdf")) return "application/pdf";