** Function: listFiles ** list all of the files, if ishtml=true, return html rather than simple text **********************************************************************/
| 124 | ** list all of the files, if ishtml=true, return html rather than simple text |
| 125 | **********************************************************************/ |
| 126 | String listFiles(FS &fs, String folder) { |
| 127 | // log_i("Listfiles Start"); |
| 128 | String returnText = "pa:" + folder + ":0\n"; |
| 129 | // Serial.println("Listing files stored on SD"); |
| 130 | |
| 131 | _webFS = fs; |
| 132 | |
| 133 | File root = fs.open(folder); |
| 134 | uploadFolder = folder; |
| 135 | |
| 136 | while (true) { |
| 137 | bool isDir; |
| 138 | String fullPath = root.getNextFileName(&isDir); |
| 139 | String nameOnly = fullPath.substring(fullPath.lastIndexOf("/") + 1); |
| 140 | if (fullPath == "") { break; } |
| 141 | // Serial.printf("Path: %s (isDir: %d)\n", fullPath.c_str(), isDir); |
| 142 | |
| 143 | if (esp_get_free_heap_size() > (String("Fo:" + nameOnly + ":0\n").length()) + 1024) { |
| 144 | if (isDir) { |
| 145 | // Serial.printf("Directory: %s\n", fullPath.c_str()); |
| 146 | returnText += "Fo:" + nameOnly + ":0\n"; |
| 147 | } else { |
| 148 | // For files, we need to get the size, so we open the file briefly |
| 149 | // Serial.printf("Opening file for size check: %s\n", fullPath.c_str()); |
| 150 | File file = fs.open(fullPath); |
| 151 | // Serial.printf("File size: %llu bytes\n", file.size()); |
| 152 | if (file) { |
| 153 | returnText += "Fi:" + nameOnly + ":" + humanReadableSize(file.size()) + "\n"; |
| 154 | file.close(); |
| 155 | } |
| 156 | } |
| 157 | } else break; |
| 158 | esp_task_wdt_reset(); |
| 159 | } |
| 160 | root.close(); |
| 161 | // log_i("ListFiles End"); |
| 162 | return returnText; |
| 163 | } |
| 164 | |
| 165 | /********************************************************************** |
| 166 | ** Function: checkUserWebAuth |
no test coverage detected