1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-22 04:00:55 +00:00

Fix all other occurences

Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
This commit is contained in:
Lukas Bachschwell 2020-09-27 13:20:14 +02:00
parent 8c0161b181
commit a6ddd48abb
Signed by: lbsadmin
GPG Key ID: CCC6AA87CC8DF425
2 changed files with 97 additions and 24 deletions

View File

@ -110,11 +110,19 @@ void listDir(const char* dirname, uint8_t levels)
void ESPUIClass::list() void ESPUIClass::list()
{ {
if (!LittleFS.begin()) #if defined(ESP32)
{ if (!SPIFFS.begin())
Serial.println(F("SPIFFS Mount Failed")); {
return; Serial.println(F("SPIFFS Mount Failed"));
} return;
}
#else
if (!LittleFS.begin())
{
Serial.println(F("LittleFS Mount Failed"));
return;
}
#endif
listDir("/", 1); listDir("/", 1);
#if defined(ESP32) #if defined(ESP32)
@ -133,6 +141,20 @@ void ESPUIClass::list()
void deleteFile(const char* path) void deleteFile(const char* path)
{ {
#if defined(ESP32)
bool exists = SPIFFS.exists(path);
#else
bool exists = LittleFS.exists(path);
#endif
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.print(exists);
}
#endif
if (!exists)
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -152,7 +174,14 @@ void deleteFile(const char* path)
return; return;
} }
#if defined(DEBUG_ESPUI) #if defined(ESP32)
bool didRemove = SPIFFS.remove(path);
#else
bool didRemove = LittleFS.remove(path);
#endif
if (didRemove)
{
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
Serial.printf_P(PSTR("Deleting file: %s\n"), path); Serial.printf_P(PSTR("Deleting file: %s\n"), path);
@ -181,6 +210,15 @@ void deleteFile(const char* path)
void writeFile(const char* path, const char* data) void writeFile(const char* path, const char* data)
{ {
#if defined(ESP32)
File file = SPIFFS.open(path, FILE_WRITE);
#else
File file = LittleFS.open(path, FILE_WRITE);
#endif
if (!file)
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -1012,19 +1050,35 @@ void ESPUIClass::jsonReload()
void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const char* password) void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const char* password)
{ {
ui_title = _title; ui_title = _title;
this->basicAuthUsername = username; this->basicAuthUsername = username;
this->basicAuthPassword = password; this->basicAuthPassword = password;
if (username == nullptr && password == nullptr) if (username == nullptr && password == nullptr)
{ {
basicAuth = false; basicAuth = false;
} }
else else
{ {
basicAuth = true; basicAuth = true;
} }
server = new AsyncWebServer(80);
ws = new AsyncWebSocket("/ws");
#if defined(ESP32)
bool fsBegin = SPIFFS.begin();
#else
bool fsBegin = LittleFS.begin();
#endif
if (!fsBegin)
{
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.println(F("FS Mount Failed, PLEASE CHECK THE README ON HOW TO PREPARE YOUR ESP!!!!!!!"));
}
#endif
server = new AsyncWebServer(80); server = new AsyncWebServer(80);
ws = new AsyncWebSocket("/ws"); ws = new AsyncWebSocket("/ws");
@ -1038,9 +1092,13 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
} }
#endif #endif
return; #if defined(ESP32)
} bool indexExists = SPIFFS.exists("/index.htm");
#else
bool indexExists = LittleFS.exists("/index.htm");
#endif
if (!indexExists)
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -1072,7 +1130,24 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
} }
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password); server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
} }
else #if defined(ESP32)
server->serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
#else
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
#endif
}
else
{
#if defined(ESP32)
server->serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm");
#else
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm");
#endif
}
// Heap for general Servertest
server->on("/heap", HTTP_GET, [](AsyncWebServerRequest *request) {
if (ESPUI.basicAuth && !request->authenticate(ESPUI.basicAuthUsername, ESPUI.basicAuthPassword))
{ {
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm"); server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm");
} }

View File

@ -6,15 +6,13 @@
#include "Arduino.h" #include "Arduino.h"
#include "ArduinoJson.h" #include "ArduinoJson.h"
#include "FS.h"
#include "stdlib_noniso.h" #include "stdlib_noniso.h"
#if defined(ESP32) #if defined(ESP32)
#include <AsyncTCP.h> #include <AsyncTCP.h>
#include <ESPAsyncWebServer.h> #include <ESPAsyncWebServer.h>
#include "FS.h" #include "SPIFFS.h"
#include "LittleFS.h"
#include "WiFi.h" #include "WiFi.h"
#else #else