From adfeb9ef558bce394d7a606adb9c382789500df1 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Wed, 28 Sep 2022 01:31:35 +0200 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/StandWebServer.h | 1 + src/Main.cpp | 6 +++ src/StandWebServer.cpp | 85 +++++++++++++++++++++------------------- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/include/StandWebServer.h b/include/StandWebServer.h index 29ce3b26..67281907 100644 --- a/include/StandWebServer.h +++ b/include/StandWebServer.h @@ -10,5 +10,6 @@ extern void handleFileUpload(); extern void handleFileDelete(); extern void handleFileCreate(); extern void handleFileList(); +void printDirectory(File dir, String& out); //#endif #endif diff --git a/src/Main.cpp b/src/Main.cpp index 9fd43e63..6a24c9a1 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -80,6 +80,12 @@ void setup() { // test Serial.println("-------test start--------"); + + // File dir = FileFS.open("/", "r"); + // String out; + // printDirectory(dir, out); + // Serial.println(out); + //=======проверка очереди из структур================= // myDB = new IoTDB; diff --git a/src/StandWebServer.cpp b/src/StandWebServer.cpp index 83139b5b..6a846158 100644 --- a/src/StandWebServer.cpp +++ b/src/StandWebServer.cpp @@ -11,42 +11,36 @@ void standWebServerInit() { HTTP.serveStatic("/bundle.css.gz", FileFS, "/", "max-age=31536000"); // кеширование на 1 год HTTP.serveStatic("/favicon.png", FileFS, "/", "max-age=31536000"); // кеширование на 1 год - HTTP.on("/devicelist.json", HTTP_GET, []() { - HTTP.send(200, "application/json", devListHeapJson); - }); - - HTTP.on("/settings.h.json", HTTP_GET, []() { - HTTP.send(200, "application/json", settingsFlashJson); - }); - - HTTP.on("/settings.f.json", HTTP_GET, []() { - HTTP.send(200, "application/json", readFile(F("settings.json"), 20000)); - }); - - HTTP.on("/params.json", HTTP_GET, []() { - String json = getParamsJson(); - HTTP.send(200, "application/json", json); - }); - - HTTP.on("/errors.json", HTTP_GET, []() { - HTTP.send(200, "application/json", errorsHeapJson); - }); - - HTTP.on("/config.json", HTTP_GET, []() { - HTTP.send(200, "application/json", readFile(F("config.json"), 20000)); - }); - - HTTP.on("/layout.json", HTTP_GET, []() { - HTTP.send(200, "application/json", readFile(F("layout.json"), 20000)); - }); - - HTTP.on("/restart", HTTP_GET, []() { - // ESP.restart(); - HTTP.send(200, "text/plain", "ok"); - }); + // HTTP.on("/devicelist.json", HTTP_GET, []() { + // HTTP.send(200, "application/json", devListHeapJson); + // }); + // HTTP.on("/settings.h.json", HTTP_GET, []() { + // HTTP.send(200, "application/json", settingsFlashJson); + // }); + // HTTP.on("/settings.f.json", HTTP_GET, []() { + // HTTP.send(200, "application/json", readFile(F("settings.json"), 20000)); + // }); + // HTTP.on("/params.json", HTTP_GET, []() { + // String json = getParamsJson(); + // HTTP.send(200, "application/json", json); + // }); + // HTTP.on("/errors.json", HTTP_GET, []() { + // HTTP.send(200, "application/json", errorsHeapJson); + // }); + // HTTP.on("/config.json", HTTP_GET, []() { + // HTTP.send(200, "application/json", readFile(F("config.json"), 20000)); + // }); + // HTTP.on("/layout.json", HTTP_GET, []() { + // HTTP.send(200, "application/json", readFile(F("layout.json"), 20000)); + // }); + // HTTP.on("/restart", HTTP_GET, []() { + // // ESP.restart(); + // HTTP.send(200, "text/plain", "ok"); + // }); // Добавляем функцию Update для перезаписи прошивки по WiFi при 1М(256K FileFS) и выше // httpUpdater.setup(&HTTP); + // Запускаем HTTP сервер HTTP.begin(); @@ -95,7 +89,6 @@ void standWebServerInit() { HTTP.send(200, "text/plain", ""); }, handleFileUpload); - //#endif // called when the url is not defined here HTTP.onNotFound([]() { @@ -155,7 +148,6 @@ String getContentType(String filename) { return "text/plain"; } -//#ifdef REST_FILE_OPERATIONS // Здесь функции для работы с файловой системой void handleFileUpload() { if (HTTP.uri() != "/edit") return; @@ -205,10 +197,6 @@ void handleFileCreate() { } void handleFileList() { - if (!HTTP.hasArg("list")) { - HTTP.send(500, "text/plain", "BAD ARGS"); - return; - } File dir = FileFS.open("/", "r"); String output = "["; File entry; @@ -226,5 +214,22 @@ void handleFileList() { Serial.println(output); HTTP.send(200, "text/json", output); } -//#endif + +void printDirectory(File dir, String& out) { + while (true) { + File entry = dir.openNextFile(); + if (!entry) { + break; + } + if (entry.isDirectory()) { + out += entry.name(); + out += "/"; + printDirectory(entry, out); + } else { + out += entry.name(); + out += "\r\n"; + } + } +} + #endif