Cleanup extension checking
This commit is contained in:
parent
d05f3f4681
commit
a46f41f934
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "html/FilesPageHtml.generated.h"
|
#include "html/FilesPageHtml.generated.h"
|
||||||
#include "html/HomePageHtml.generated.h"
|
#include "html/HomePageHtml.generated.h"
|
||||||
|
#include "util/StringUtils.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// Folders/files to hide from the web interface file browser
|
// Folders/files to hide from the web interface file browser
|
||||||
@ -33,9 +34,8 @@ bool wsUploadInProgress = false;
|
|||||||
// Helper function to clear epub cache after upload
|
// Helper function to clear epub cache after upload
|
||||||
void clearEpubCacheIfNeeded(const String& filePath) {
|
void clearEpubCacheIfNeeded(const String& filePath) {
|
||||||
// Only clear cache for .epub files
|
// Only clear cache for .epub files
|
||||||
if (filePath.endsWith(".epub") || filePath.endsWith(".EPUB")) {
|
if (StringUtils::checkFileExtension(filePath, ".epub")) {
|
||||||
Epub epub(filePath.c_str(), "/.crosspoint");
|
Epub(filePath.c_str(), "/.crosspoint").clearCache();
|
||||||
epub.clearCache();
|
|
||||||
Serial.printf("[%lu] [WEB] Cleared epub cache for: %s\n", millis(), filePath.c_str());
|
Serial.printf("[%lu] [WEB] Cleared epub cache for: %s\n", millis(), filePath.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,6 +49,19 @@ bool checkFileExtension(const std::string& fileName, const char* extension) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool checkFileExtension(const String& fileName, const char* extension) {
|
||||||
|
if (fileName.length() < strlen(extension)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String localFile(fileName);
|
||||||
|
String localExtension(extension);
|
||||||
|
localFile.toLowerCase();
|
||||||
|
localExtension.toLowerCase();
|
||||||
|
return localFile.endsWith(localExtension);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t utf8RemoveLastChar(std::string& str) {
|
size_t utf8RemoveLastChar(std::string& str) {
|
||||||
if (str.empty()) return 0;
|
if (str.empty()) return 0;
|
||||||
size_t pos = str.size() - 1;
|
size_t pos = str.size() - 1;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <WString.h>
|
||||||
|
|
||||||
namespace StringUtils {
|
namespace StringUtils {
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ std::string sanitizeFilename(const std::string& name, size_t maxLength = 100);
|
|||||||
* Check if the given filename ends with the specified extension (case-insensitive).
|
* Check if the given filename ends with the specified extension (case-insensitive).
|
||||||
*/
|
*/
|
||||||
bool checkFileExtension(const std::string& fileName, const char* extension);
|
bool checkFileExtension(const std::string& fileName, const char* extension);
|
||||||
|
bool checkFileExtension(const String& fileName, const char* extension);
|
||||||
|
|
||||||
// UTF-8 safe string truncation - removes one character from the end
|
// UTF-8 safe string truncation - removes one character from the end
|
||||||
// Returns the new size after removing one UTF-8 character
|
// Returns the new size after removing one UTF-8 character
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user