From 5981831bc045951fea2decf45675819815694e99 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Thu, 22 Oct 2020 18:43:54 -0700 Subject: [PATCH] Fixed typo. Updated js library. Update root file handler. Typo fixed. I placed the latest javascript library files into the static folder. Updated the root file handler to be able to serve both compressed and uncompressed files. --- data/static/index.html | 18 ++++++++++++++++++ data/static/index.html.gz | Bin 212 -> 0 bytes src/meshwifi/meshhttp.cpp | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 data/static/index.html delete mode 100644 data/static/index.html.gz diff --git a/data/static/index.html b/data/static/index.html new file mode 100644 index 000000000..663203013 --- /dev/null +++ b/data/static/index.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/data/static/index.html.gz b/data/static/index.html.gz deleted file mode 100644 index 4880f9cab18fbcb2e384ad21f7b10462ad4a11cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 212 zcmV;_04x6=iwFpVFp^&c18Ht#Wq2-VbZu+^bx<*m0x=Bi_Z2=@cLkT0B1uEd8&K9U zY#^JUwL#+dWQjzBsAe=X){Ja_VkLcC877^xAM6T1Ifytcb#oSk9LmWd`k}cTq8|Y4 z%o>2Eun4Qen;th?d>NWFv$v+>uu4Kpx+=&*4vlEgL}q50G)SZWt)k_7$bZX^K|Z3^ ztaH{`V~vmAHQrQfffOB5Erm%BT|%gZa-z%I`29n_>lC!Y{=Eny-xIMl{jzOpRlTB- O*Posprint("" + String(file.name()).substring(1) + ""); } else { - res->print("" + String(file.name()).substring(1) + ""); + res->print("" + String(file.name()).substring(1) + + ""); } res->println(""); res->println(""); @@ -699,9 +700,35 @@ void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res) void handleRoot(HTTPRequest *req, HTTPResponse *res) { res->setHeader("Content-Type", "text/html"); - res->setHeader("Content-Encoding", "gzip"); - File file = SPIFFS.open("/static/index.html.gz"); + std::string filename = "/static/index.html"; + std::string filenameGzip = "/static/index.html.gz"; + + if (!SPIFFS.exists(filename.c_str()) && !SPIFFS.exists(filenameGzip.c_str())) { + // Send "404 Not Found" as response, as the file doesn't seem to exist + res->setStatusCode(404); + res->setStatusText("Not found"); + res->println("404 Not Found"); + res->printf("

File not found: %s

\n", filename.c_str()); + return; + } + + // Try to open the file from SPIFFS + File file; + + if (SPIFFS.exists(filename.c_str())) { + file = SPIFFS.open(filename.c_str()); + if (!file.available()) { + DEBUG_MSG("File not available - %s\n", filename.c_str()); + } + + } else if (SPIFFS.exists(filenameGzip.c_str())) { + file = SPIFFS.open(filenameGzip.c_str()); + res->setHeader("Content-Encoding", "gzip"); + if (!file.available()) { + DEBUG_MSG("File not available\n"); + } + } // Read the file from SPIFFS and write it to the HTTP response body size_t length = 0;