// ======================= ФАЙЛОВЫЙ МЕНЕДЖЕР =======================
void _href(const String& url, const String& text) {
*_GPP += F("<a style='text-decoration:none' href='");
*_GPP += url;
*_GPP += F("'>");
*_GPP += text;
*_GPP += F("</a>");
}
void _fileRow(const String& fpath, const String& fname, int size, int i) {
*_GPP += "<tr>";
*_GPP += F("<td align='left' style='padding-right:5px'>");
*_GPP += String(i) + ". ";
_href(fpath+fname, fname);
*_GPP += F("<td>");
*_GPP += '[';
*_GPP += String(size / 1000.0, 1);
*_GPP += F(" kB]");
*_GPP += "<td>";
_href(String("?GP_delete=") + fpath+""+fname, "❌");
}
void _showFiles(fs::FS *fs, const String& path, __attribute__((unused)) uint8_t levels = 0) {
#ifdef ESP8266
yield();
Dir dir = fs->openDir(path);
while (dir.next()) {
if (dir.isFile() && dir.fileName().length()) {
String fpath = '/' + path + dir.fileName();
_fileRow(fpath, dir.fileSize());
}
if (dir.isDirectory()) {
String p = path;
p += dir.fileName();
p += '/';
Dir sdir = fs->openDir(p);
_showFiles(fs, p);
}
}
#else // ESP32
File root = fs->open(path.length() ? path.c_str() : ("/"));
if (!root || !root.isDirectory()) return;
File file;
int i=0;
while (file = root.openNextFile()) {
if (file.isDirectory()) {
//if (levels) _showFiles(fs, file.path(), levels - 1);
} else {
_fileRow(path +'/', file.name(), file.size(), i);
i++;
}
}
#endif
}
void FILE_MANAGER(fs::FS *fs, const String workPath) {
*_GPP += F("<table>");
_showFiles(fs, workPath, 5 );