adding legacy support for "edit?list=/" command, fix indentation (#5092)

This commit is contained in:
Damian Schneider
2025-11-26 22:23:37 +01:00
committed by GitHub
parent fca921ee82
commit e761418531

View File

@@ -27,6 +27,7 @@ static const char s_accessdenied[] PROGMEM = "Access Denied";
static const char s_not_found[] PROGMEM = "Not found"; static const char s_not_found[] PROGMEM = "Not found";
static const char s_wsec[] PROGMEM = "wsec.json"; static const char s_wsec[] PROGMEM = "wsec.json";
static const char s_func[] PROGMEM = "func"; static const char s_func[] PROGMEM = "func";
static const char s_list[] PROGMEM = "list";
static const char s_path[] PROGMEM = "path"; static const char s_path[] PROGMEM = "path";
static const char s_cache_control[] PROGMEM = "Cache-Control"; static const char s_cache_control[] PROGMEM = "Cache-Control";
static const char s_no_store[] PROGMEM = "no-store"; static const char s_no_store[] PROGMEM = "no-store";
@@ -226,14 +227,18 @@ void createEditHandler() {
return; return;
} }
const String& func = request->arg(FPSTR(s_func)); const String& func = request->arg(FPSTR(s_func));
bool legacyList = false;
if (request->hasArg(FPSTR(s_list))) {
legacyList = true; // support for '?list=/'
}
if(func.length() == 0) { if(func.length() == 0 && !legacyList) {
// default: serve the editor page // default: serve the editor page
handleStaticContent(request, FPSTR(_edit_htm), 200, FPSTR(CONTENT_TYPE_HTML), PAGE_edit, PAGE_edit_length); handleStaticContent(request, FPSTR(_edit_htm), 200, FPSTR(CONTENT_TYPE_HTML), PAGE_edit, PAGE_edit_length);
return; return;
} }
if (func == "list") { if (func == FPSTR(s_list) || legacyList) {
bool first = true; bool first = true;
AsyncResponseStream* response = request->beginResponseStream(FPSTR(CONTENT_TYPE_JSON)); AsyncResponseStream* response = request->beginResponseStream(FPSTR(CONTENT_TYPE_JSON));
response->addHeader(FPSTR(s_cache_control), FPSTR(s_no_store)); response->addHeader(FPSTR(s_cache_control), FPSTR(s_no_store));
@@ -243,15 +248,15 @@ void createEditHandler() {
File rootdir = WLED_FS.open("/", "r"); File rootdir = WLED_FS.open("/", "r");
File rootfile = rootdir.openNextFile(); File rootfile = rootdir.openNextFile();
while (rootfile) { while (rootfile) {
String name = rootfile.name(); String name = rootfile.name();
if (name.indexOf(FPSTR(s_wsec)) >= 0) { if (name.indexOf(FPSTR(s_wsec)) >= 0) {
rootfile = rootdir.openNextFile(); // skip wsec.json rootfile = rootdir.openNextFile(); // skip wsec.json
continue; continue;
} }
if (!first) response->write(','); if (!first) response->write(',');
first = false; first = false;
response->printf_P(PSTR("{\"name\":\"%s\",\"type\":\"file\",\"size\":%u}"), name.c_str(), rootfile.size()); response->printf_P(PSTR("{\"name\":\"%s\",\"type\":\"file\",\"size\":%u}"), name.c_str(), rootfile.size());
rootfile = rootdir.openNextFile(); rootfile = rootdir.openNextFile();
} }
rootfile.close(); rootfile.close();
rootdir.close(); rootdir.close();