23 std::vector<TreeNode*, AllocatorPSRAM<TreeNode*>>
children;
29 static void*
operator new(std::size_t
size) {
34 static void operator delete(
void* ptr) {
47 const std::vector<std::pair<std::string, std::string>>& rules) {
48 auto& tbl = mimeRulesTable();
50 tbl.reserve(rules.size());
51 for (
auto& r : rules) tbl.emplace_back(normalizeExt(r.first), r.second);
57 static void addMimeRule(
const std::string& ext,
const std::string& mime) {
58 mimeRulesTable().emplace_back(normalizeExt(ext), mime);
70 for (
unsigned char c :
file_name) lower.push_back((
char)std::tolower(c));
71 const auto& rules = mimeRulesTable();
72 for (
const auto& r : rules) {
73 const std::string& ext = r.first;
74 const std::string& mime = r.second;
75 if (lower.size() >= ext.size() &&
76 lower.compare(lower.size() - ext.size(), ext.size(), ext) == 0) {
93 if (parentPath.back() !=
'/') parentPath +=
'/';
114 static std::vector<std::pair<std::string, std::string>>& mimeRulesTable() {
115 static std::vector<std::pair<std::string, std::string>> rules = {
116 {
".mp3",
"audio/mpeg"}, {
".aac",
"audio/aac"}, {
".m4a",
"audio/aac"},
117 {
".wav",
"audio/wav"}, {
".flac",
"audio/flac"}, {
".ogg",
"audio/ogg"},
122 static std::string normalizeExt(std::string ext) {
123 if (ext.empty())
return ext;
125 if (ext[0] !=
'.') ext.insert(ext.begin(),
'.');
127 for (
auto& ch : ext) ch = (char)std::tolower((
unsigned char)ch);
Custom allocator that uses ESP32's PSRAM for memory allocation.
Definition: Allocator.h:24
pointer allocate(size_type n)
Allocate memory from PSRAM.
Definition: Allocator.h:55
void deallocate(pointer p, size_type) noexcept
Deallocate memory.
Definition: Allocator.h:81
Node in the directory tree representing either a file or a directory.
Definition: TreeNode.h:18
std::string getMime() const
Very basic MIME inference based on file extension.
Definition: TreeNode.h:66
static void setMimeRules(const std::vector< std::pair< std::string, std::string > > &rules)
Replace all MIME rules.
Definition: TreeNode.h:46
static void addMimeRule(const std::string &ext, const std::string &mime)
Add one MIME rule mapping extension -> MIME type.
Definition: TreeNode.h:57
uint32_t size
Definition: TreeNode.h:25
std::vector< TreeNode *, AllocatorPSRAM< TreeNode * > > children
Definition: TreeNode.h:23
stringPSRAM file_name
Definition: TreeNode.h:22
bool is_dir
Definition: TreeNode.h:27
bool is_expanded
Definition: TreeNode.h:26
int level() const
Returns the nesting level from the root.
Definition: TreeNode.h:102
std::string path() const
Computes the full path from the root to this node.
Definition: TreeNode.h:87
TreeNode * parent
Definition: TreeNode.h:24
Definition: Allocator.h:13
std::basic_string< char, std::char_traits< char >, AllocatorPSRAM< char > > stringPSRAM
Definition: Allocator.h:106