| 374 | } |
| 375 | |
| 376 | void CrossPointWebServer::scanFiles(const char* path, const std::function<void(FileInfo)>& callback) const { |
| 377 | HalFile root = Storage.open(path); |
| 378 | if (!root) { |
| 379 | LOG_DBG("WEB", "Failed to open directory: %s", path); |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | if (!root.isDirectory()) { |
| 384 | LOG_DBG("WEB", "Not a directory: %s", path); |
| 385 | root.close(); |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | LOG_DBG("WEB", "Scanning files in: %s", path); |
| 390 | |
| 391 | HalFile file = root.openNextFile(); |
| 392 | char name[500]; |
| 393 | while (file) { |
| 394 | file.getName(name, sizeof(name)); |
| 395 | auto fileName = String(name); |
| 396 | |
| 397 | // Skip hidden items (starting with ".") |
| 398 | bool shouldHide = !SETTINGS.showHiddenFiles && fileName.startsWith("."); |
| 399 | |
| 400 | // Check against explicitly hidden items list |
| 401 | if (!shouldHide) { |
| 402 | for (const auto* item : HIDDEN_ITEMS) { |
| 403 | if (fileName.equals(item)) { |
| 404 | shouldHide = true; |
| 405 | break; |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | if (!shouldHide) { |
| 411 | FileInfo info; |
| 412 | info.name = fileName; |
| 413 | info.isDirectory = file.isDirectory(); |
| 414 | |
| 415 | if (info.isDirectory) { |
| 416 | info.size = 0; |
| 417 | info.isEpub = false; |
| 418 | } else { |
| 419 | info.size = file.size(); |
| 420 | info.isEpub = isEpubFile(info.name); |
| 421 | } |
| 422 | |
| 423 | callback(info); |
| 424 | } |
| 425 | |
| 426 | file.close(); |
| 427 | yield(); // Yield to allow WiFi and other tasks to process during long scans |
| 428 | esp_task_wdt_reset(); // Reset watchdog to prevent timeout on large directories |
| 429 | file = root.openNextFile(); |
| 430 | } |
| 431 | root.close(); |
| 432 | } |
| 433 |
nothing calls this directly
no test coverage detected