From 21de073784c5a80a94a033f9278fef7df5cadf44 Mon Sep 17 00:00:00 2001 From: ahadcove Date: Mon, 24 Oct 2022 11:13:33 -0400 Subject: [PATCH 1/5] fix: restoring cfg.json #2847 --- wled00/wled_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 6e779228..4c235cf3 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -52,7 +52,7 @@ void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t } if (final) { request->_tempFile.close(); - if (filename == "/cfg.json") { + if (filename == "/cfg.json" || filename == "cfg.json") { doReboot = true; request->send(200, "text/plain", F("Configuration restore successful.\nRebooting...")); } else From 92329a8dd0b586bccaa5c55ef5b0ce18a12cc94a Mon Sep 17 00:00:00 2001 From: ahadcove Date: Mon, 24 Oct 2022 11:34:56 -0400 Subject: [PATCH 2/5] chore: condense the if statement --- wled00/wled_server.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 4c235cf3..a5301c1a 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -45,14 +45,14 @@ void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t request->_tempFile = WLED_FS.open(finalname, "w"); DEBUG_PRINT("Uploading "); DEBUG_PRINTLN(finalname); - if (finalname == "/presets.json") presetsModifiedTime = toki.second(); + if (finalname.indexOf("presets.json") >= 0) presetsModifiedTime = toki.second(); } if (len) { request->_tempFile.write(data,len); } if (final) { request->_tempFile.close(); - if (filename == "/cfg.json" || filename == "cfg.json") { + if (filename.indexOf("cfg.json") >= 0) { doReboot = true; request->send(200, "text/plain", F("Configuration restore successful.\nRebooting...")); } else From 5ba1ebd525dd5ba7e3834e544a27ff002a4b49ea Mon Sep 17 00:00:00 2001 From: Christian Schwinne Date: Mon, 24 Oct 2022 18:44:11 +0200 Subject: [PATCH 3/5] equals for /presets.json instead of indexof --- wled00/wled_server.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index a5301c1a..71040093 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -45,14 +45,14 @@ void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t request->_tempFile = WLED_FS.open(finalname, "w"); DEBUG_PRINT("Uploading "); DEBUG_PRINTLN(finalname); - if (finalname.indexOf("presets.json") >= 0) presetsModifiedTime = toki.second(); + if (finalname.equals("/presets.json") >= 0) presetsModifiedTime = toki.second(); } if (len) { request->_tempFile.write(data,len); } if (final) { request->_tempFile.close(); - if (filename.indexOf("cfg.json") >= 0) { + if (filename.indexOf("cfg.json") >= 0) { // check for filename with or without slash doReboot = true; request->send(200, "text/plain", F("Configuration restore successful.\nRebooting...")); } else @@ -618,4 +618,4 @@ void serveSettings(AsyncWebServerRequest* request, bool post) response->addHeader(FPSTR(s_content_enc),"gzip"); setStaticContentCacheHeaders(response); request->send(response); -} \ No newline at end of file +} From 2000d0276875dcb4c9ff63678559ab8b04dceacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Kristan?= Date: Mon, 24 Oct 2022 18:49:02 +0200 Subject: [PATCH 4/5] Strings in flash --- wled00/wled_server.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 71040093..e9561aec 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -39,20 +39,20 @@ void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t if (!index) { String finalname = filename; if (finalname.charAt(0) != '/') { - finalname = "/" + finalname; // prepend slash if missing + finalname = '/' + finalname; // prepend slash if missing } request->_tempFile = WLED_FS.open(finalname, "w"); - DEBUG_PRINT("Uploading "); + DEBUG_PRINT(F("Uploading ")); DEBUG_PRINTLN(finalname); - if (finalname.equals("/presets.json") >= 0) presetsModifiedTime = toki.second(); + if (finalname.equals(F("/presets.json")) >= 0) presetsModifiedTime = toki.second(); } if (len) { request->_tempFile.write(data,len); } if (final) { request->_tempFile.close(); - if (filename.indexOf("cfg.json") >= 0) { // check for filename with or without slash + if (filename.indexOf(F("cfg.json")) >= 0) { // check for filename with or without slash doReboot = true; request->send(200, "text/plain", F("Configuration restore successful.\nRebooting...")); } else From ac57da87134fa514c5153d10e1b71d8181d0b35c Mon Sep 17 00:00:00 2001 From: Christian Schwinne Date: Mon, 24 Oct 2022 19:12:27 +0200 Subject: [PATCH 5/5] No F() and numeric comparison --- wled00/wled_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index e9561aec..61010484 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -45,7 +45,7 @@ void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t request->_tempFile = WLED_FS.open(finalname, "w"); DEBUG_PRINT(F("Uploading ")); DEBUG_PRINTLN(finalname); - if (finalname.equals(F("/presets.json")) >= 0) presetsModifiedTime = toki.second(); + if (finalname.equals("/presets.json")) presetsModifiedTime = toki.second(); } if (len) { request->_tempFile.write(data,len);