diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp index b9f462265..e4b4b166f 100644 --- a/src/meshwifi/meshhttp.cpp +++ b/src/meshwifi/meshhttp.cpp @@ -298,6 +298,86 @@ void middlewareSpeedUp160(HTTPRequest *req, HTTPResponse *res, std::functiongetParams(); + std::string paramValDelete; + + // Set a default content type + res->setHeader("Content-Type", "text/html"); + + if (params->getQueryParameter("delete", paramValDelete)) { + std::string pathDelete = "/" + paramValDelete; + if (SPIFFS.remove(pathDelete.c_str())) { + Serial.println(pathDelete.c_str()); + res->println("File " + "deleted!

File deleted!

"); + res->println("\n"); + res->println(""); + + return; + } else { + Serial.println(pathDelete.c_str()); + res->println("Error deleteing " + "file!

Error deleteing file!

"); + res->println("Error deleteing file!
"); + + return; + } + } + + res->println("

Upload new file

"); + res->println("

*** This interface is experimental ***

"); + res->println("

This form allows you to upload files. Keep your filenames very short and files small. Big filenames and big " + "files are a known problem.

"); + res->println("
"); + res->println("file:
"); + res->println(""); + res->println("
"); + + res->println("

All Files

"); + + File root = SPIFFS.open("/"); + if (root.isDirectory()) { + res->println(""); + + res->println(""); + File file = root.openNextFile(); + while (file) { + String filePath = String(file.name()); + if (filePath.indexOf("/static") == 0) { + res->println(""); + res->println(""); + res->println(""); + res->println(""); + } + + file = root.openNextFile(); + } + res->println("
"); + + if (String(file.name()).substring(1).endsWith(".gz")) { + String modifiedFile = String(file.name()).substring(1); + modifiedFile.remove((modifiedFile.length() - 3), 3); + res->print("" + String(file.name()).substring(1) + ""); + } else { + res->print("" + String(file.name()).substring(1) + + ""); + } + res->println(""); + res->print(String(file.size())); + res->println(""); + res->print("X"); + res->println("
"); + + res->print("
"); + res->print("Total : " + String(SPIFFS.totalBytes()) + " Bytes
"); + res->print("Used : " + String(SPIFFS.usedBytes()) + " Bytes
"); + res->print("Free : " + String(SPIFFS.totalBytes() - SPIFFS.usedBytes()) + " Bytes
"); + } +} void handleStaticPost(HTTPRequest *req, HTTPResponse *res) { @@ -831,7 +911,6 @@ void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res) */ void handleRoot(HTTPRequest *req, HTTPResponse *res) { - res->setHeader("Content-Type", "text/html"); randomSeed(millis()); @@ -873,6 +952,7 @@ void handleRoot(HTTPRequest *req, HTTPResponse *res) } } + // Read the file from SPIFFS and write it to the HTTP response body size_t length = 0; do { @@ -891,6 +971,7 @@ void handleFavicon(HTTPRequest *req, HTTPResponse *res) res->write(FAVICON_DATA, FAVICON_LENGTH); } + void replaceAll(std::string &str, const std::string &from, const std::string &to) { if (from.empty()) @@ -900,4 +981,5 @@ void replaceAll(std::string &str, const std::string &from, const std::string &to str.replace(start_pos, from.length(), to); start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' } -} \ No newline at end of file +} +