Skip to content

Commit e4b5d6d

Browse files
DedeHainetmindz
authored andcommitted
adding legacy support for "edit?list=/" command, fix indentation (#5092)
1 parent 830e5da commit e4b5d6d

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

wled00/wled_server.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static const char s_accessdenied[] PROGMEM = "Access Denied";
2727
static const char s_not_found[] PROGMEM = "Not found";
2828
static const char s_wsec[] PROGMEM = "wsec.json";
2929
static const char s_func[] PROGMEM = "func";
30+
static const char s_list[] PROGMEM = "list";
3031
static const char s_path[] PROGMEM = "path";
3132
static const char s_cache_control[] PROGMEM = "Cache-Control";
3233
static const char s_no_store[] PROGMEM = "no-store";
@@ -226,14 +227,18 @@ void createEditHandler() {
226227
return;
227228
}
228229
const String& func = request->arg(FPSTR(s_func));
230+
bool legacyList = false;
231+
if (request->hasArg(FPSTR(s_list))) {
232+
legacyList = true; // support for '?list=/'
233+
}
229234

230-
if(func.length() == 0) {
235+
if(func.length() == 0 && !legacyList) {
231236
// default: serve the editor page
232237
handleStaticContent(request, FPSTR(_edit_htm), 200, FPSTR(CONTENT_TYPE_HTML), PAGE_edit, PAGE_edit_length);
233238
return;
234239
}
235240

236-
if (func == "list") {
241+
if (func == FPSTR(s_list) || legacyList) {
237242
bool first = true;
238243
AsyncResponseStream* response = request->beginResponseStream(FPSTR(CONTENT_TYPE_JSON));
239244
response->addHeader(FPSTR(s_cache_control), FPSTR(s_no_store));
@@ -243,15 +248,15 @@ void createEditHandler() {
243248
File rootdir = WLED_FS.open("/", "r");
244249
File rootfile = rootdir.openNextFile();
245250
while (rootfile) {
246-
String name = rootfile.name();
247-
if (name.indexOf(FPSTR(s_wsec)) >= 0) {
248-
rootfile = rootdir.openNextFile(); // skip wsec.json
249-
continue;
250-
}
251-
if (!first) response->write(',');
252-
first = false;
253-
response->printf_P(PSTR("{\"name\":\"%s\",\"type\":\"file\",\"size\":%u}"), name.c_str(), rootfile.size());
254-
rootfile = rootdir.openNextFile();
251+
String name = rootfile.name();
252+
if (name.indexOf(FPSTR(s_wsec)) >= 0) {
253+
rootfile = rootdir.openNextFile(); // skip wsec.json
254+
continue;
255+
}
256+
if (!first) response->write(',');
257+
first = false;
258+
response->printf_P(PSTR("{\"name\":\"%s\",\"type\":\"file\",\"size\":%u}"), name.c_str(), rootfile.size());
259+
rootfile = rootdir.openNextFile();
255260
}
256261
rootfile.close();
257262
rootdir.close();

0 commit comments

Comments
 (0)