From 1954b9493ecbddc4538dd766e1b30f4757fa94c8 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Mon, 24 Oct 2022 12:01:02 +0200 Subject: [PATCH] cfg restore - align with upstream + small bugfix - align handleUpload() [wled_server.cpp] with upstream AC 0.14.0 - clearer message when presets were uploaded - small fix for cfg.json upload (first send reply, _then_ set doReboot=true) --- wled00/wled.h | 2 +- wled00/wled_server.cpp | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/wled00/wled.h b/wled00/wled.h index 23d80512..6db79319 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2210201 +#define VERSION 2210241 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 626c2708..b54b6abc 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -37,21 +37,30 @@ void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t return; } if (!index) { - request->_tempFile = WLED_FS.open(filename, "w"); + String finalname = filename; + if (finalname.charAt(0) != '/') { + finalname = "/" + finalname; // prepend slash if missing + } + + request->_tempFile = WLED_FS.open(finalname, "w"); DEBUG_PRINT("Uploading "); - DEBUG_PRINTLN(filename); - if (filename == F("/presets.json")) presetsModifiedTime = toki.second(); + DEBUG_PRINTLN(finalname); + if (finalname.equals("/presets.json")) presetsModifiedTime = toki.second(); // WLEDSR } if (len) { request->_tempFile.write(data,len); } if (final) { request->_tempFile.close(); - if (filename == F("/cfg.json")) { - doReboot = true; + if (filename.equalsIgnoreCase("/cfg.json") || filename.equalsIgnoreCase("cfg.json")) { // WLEDSR request->send(200, "text/plain", F("Configuration restore successful.\nRebooting...")); - } else - request->send(200, "text/plain", F("File Uploaded!")); + doReboot = true; + } else { + if (filename.equals("/presets.json") || filename.equals("presets.json")) { // WLEDSR + request->send(200, "text/plain", F("Presets File Uploaded!")); + } else + request->send(200, "text/plain", F("File Uploaded!")); + } cacheInvalidate++; } }