feat: add options to remember web upload settings & rename ebooks to {title} - {author} (#2534)

This commit is contained in:
Víctor Fernández
2026-07-15 14:43:42 -04:00
committed by GitHub
parent f3cad2f9e1
commit 35a45f9c1e
2 changed files with 255 additions and 48 deletions
+11 -13
View File
@@ -671,17 +671,15 @@ void CrossPointWebServer::handleUpload(UploadState& state) const {
LOG_DBG("WEB", "[UPLOAD] START: %s to path: %s", state.fileName.c_str(), state.path.c_str());
LOG_DBG("WEB", "[UPLOAD] Free heap: %d bytes", ESP.getFreeHeap());
// Create file path
String filePath = state.path;
if (!filePath.endsWith("/")) filePath += "/";
filePath += state.fileName;
// Check if file already exists - SD operations can be slow
esp_task_wdt_reset();
if (Storage.exists(filePath.c_str())) {
LOG_DBG("WEB", "[UPLOAD] Overwriting existing file: %s", filePath.c_str());
esp_task_wdt_reset();
Storage.remove(filePath.c_str());
state.error = "File already exists: " + state.fileName;
LOG_DBG("WEB", "[UPLOAD] Collision: %s", filePath.c_str());
return;
}
// Open file for writing - this can be slow due to FAT cluster allocation
@@ -749,7 +747,7 @@ void CrossPointWebServer::handleUpload(UploadState& state) const {
LOG_DBG("WEB", "[UPLOAD] Diagnostics: %d writes, total write time: %lu ms (%.1f%%)", writeCount, totalWriteTime,
writePercent);
// Clear epub cache to prevent stale metadata issues when overwriting files
// Clear epub cache after uploading the file
String filePath = state.path;
if (!filePath.endsWith("/")) filePath += "/";
filePath += state.fileName;
@@ -1624,20 +1622,20 @@ void CrossPointWebServer::onWebSocketEvent(uint8_t num, WStype_t type, uint8_t*
wsUploadPath = wsUploadPath.substring(0, wsUploadPath.length() - 1);
}
// Build file path
String filePath = wsUploadPath;
if (!filePath.endsWith("/")) filePath += "/";
filePath += wsUploadFileName;
LOG_DBG("WS", "Starting upload: %s (%d bytes) to %s", wsUploadFileName.c_str(), wsUploadSize,
filePath.c_str());
// Check if file exists and remove it
esp_task_wdt_reset();
if (Storage.exists(filePath.c_str())) {
Storage.remove(filePath.c_str());
LOG_DBG("WS", "Upload collision: %s", filePath.c_str());
wsServer->sendTXT(num, "ERROR:File already exists: " + wsUploadFileName);
return;
}
LOG_DBG("WS", "Starting upload: %s (%d bytes) to %s", wsUploadFileName.c_str(), wsUploadSize,
filePath.c_str());
// Open file for writing
esp_task_wdt_reset();
if (!Storage.openFileForWrite("WS", filePath, wsUploadFile)) {
@@ -1721,7 +1719,7 @@ void CrossPointWebServer::onWebSocketEvent(uint8_t num, WStype_t type, uint8_t*
LOG_DBG("WS", "Upload complete: %s (%d bytes in %lu ms, %.1f KB/s)", wsUploadFileName.c_str(), wsUploadSize,
elapsed, kbps);
// Clear epub cache to prevent stale metadata issues when overwriting files
// Clear epub cache after uploading the file
String filePath = wsUploadPath;
if (!filePath.endsWith("/")) filePath += "/";
filePath += wsUploadFileName;