From d86decdf45969b268408812d7bc3a98cc6a0f40b Mon Sep 17 00:00:00 2001 From: Holger Lembke Date: Thu, 24 Aug 2023 20:39:04 +0200 Subject: [PATCH] up --- README.md | 9 +-- examples/advanced/ESPFMfGKdropin.ino | 104 +++++++++++++++++++++++++++ examples/advanced/advanced.ino | 53 ++++++++++++++ src/ESPFMfGK.h | 2 +- 4 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 examples/advanced/ESPFMfGKdropin.ino create mode 100644 examples/advanced/advanced.ino diff --git a/README.md b/README.md index 72f35ad..03e675b 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,14 @@ ESP32 File Manager for Generation Klick -[image](https://github.com/holgerlembke/ESPFMfGK/blob/main/img/bild1.jpg) - -![this is it](https://raw.githubusercontent.com/holgerlembke/ESPFMfGK/main/img/bild1.png) +![this is it](https://raw.githubusercontent.com/holgerlembke/ESPFMfGK/main/img/bild1.jpg) ESPFMfGK is a simple to use web interface that allows you to upload files with drag and drop, download files, edit files, move files and much more within your ESP32 file space. It supports all file systems (FFAT, SD, SD-MMC, LittleFS, SPIFFS) and an unlimited number of devices all at the same time. -[image](https://github.com/holgerlembke/ESPFMfGK/blob/main/img/bild2.jpg) - -[image](https://github.com/holgerlembke/ESPFMfGK/blob/main/img/bild3.jpg) +![this is it](https://raw.githubusercontent.com/holgerlembke/ESPFMfGK/main/img/bild2.jpg) +![this is it](https://raw.githubusercontent.com/holgerlembke/ESPFMfGK/main/img/bild3.jpg) ESPFMfGK is the successor of Award Winning https://github.com/holgerlembke/ESPxWebFlMgr. diff --git a/examples/advanced/ESPFMfGKdropin.ino b/examples/advanced/ESPFMfGKdropin.ino new file mode 100644 index 0000000..0d19750 --- /dev/null +++ b/examples/advanced/ESPFMfGKdropin.ino @@ -0,0 +1,104 @@ +// Adds the filé systems +void addFileSystems(void) { + // This adds the Storage into the Filemanager. You have to at least call one of those. + // If you don't, begin() will fail. Because a Filemanager without files is useless. + + /**/ //<-- Addd space there like this /** / + if (FFat.begin(true)) { + if (!filemgr.AddFS(FFat, "Flash/FFat", false)) { + Serial.println(F("Adding FFAT failed.")); + } + } else { + Serial.println(F("FFat File System not inited.")); + } + /**/ + + /**/ + if (SD_MMC.begin("/sdcard", true)) { + if (!filemgr.AddFS(SD_MMC, "SD-MMC-Card", false)) { + Serial.println(F("Adding SD_MMC failed.")); + } + } else { + Serial.println(F("SD_MMC File System not inited.")); + } + /**/ + + /**/ + const byte SS = 5; // D8 + if (SD.begin(SS)) { + if (!filemgr.AddFS(SD, "SD-Card", false)) { + Serial.println(F("Adding SD failed.")); + } + } else { + Serial.println(F("SD File System not inited.")); + } + /**/ +} + +uint32_t checkFileFlags(fs::FS &fs, String filename, uint32_t flags) { + + // this will hide system files (in my world, system files start with a dot) + if (filename.startsWith("/.")) { + // no other flags, file is invisible and nothing allowed + return ESPFMfGK::flagIsNotVisible; + } + + // Checks if target file name is valid for action. This will simply allow everything by returning the queried flag + if (flags & ESPFMfGK::flagIsValidAction) { + return flags & (~ESPFMfGK::flagIsValidAction); + } + + // Checks if target file name is valid for action. + if (flags & ESPFMfGK::flagIsValidTargetFilename) { + return flags & (~ESPFMfGK::flagIsValidTargetFilename); + } + + // Default actions + uint32_t defaultflags = ESPFMfGK::flagCanDelete | ESPFMfGK::flagCanRename | ESPFMfGK::flagCanGZip | // ^t + ESPFMfGK::flagCanDownload | ESPFMfGK::flagCanUpload; // ^t + + // editable files. + const String extedit[] PROGMEM = { ".html", ".css", ".js", ".txt", ".json", ".ino" }; + + filename.toLowerCase(); + // I simply assume, that editable files are also allowed to be previewd + for (int i = 0; i < sizeof(extedit) / sizeof(extedit[0]); i++) { + if (filename.endsWith(String(extedit[i]))) { + defaultflags |= ESPFMfGK::flagCanEdit | ESPFMfGK::flagAllowPreview; + break; + } + } + + const String extpreview[] PROGMEM = { ".jpg", ".png" }; + for (int i = 0; i < sizeof(extpreview) / sizeof(extpreview[0]); i++) { + if (filename.endsWith(String(extpreview[i]))) { + defaultflags |= ESPFMfGK::flagAllowPreview; + break; + } + } + + + return defaultflags; +} + +void setupFilemanager(void) { + // See above. + filemgr.checkFileFlags = checkFileFlags; + + filemgr.WebPageTitle = "FileManager"; + filemgr.BackgroundColor = "white"; + filemgr.textareaCharset = "accept-charset=\"utf-8\""; + + if ((WiFi.status() == WL_CONNECTED) && (filemgr.begin())) { + Serial.print(F("Open Filemanager with http://")); + Serial.print(WiFi.localIP()); + Serial.print(F(":")); + Serial.print(filemanagerport); + Serial.print(F("/")); + Serial.println(); + } else { + Serial.print(F("Filemanager: did not start")); + } +} + +// \ No newline at end of file diff --git a/examples/advanced/advanced.ino b/examples/advanced/advanced.ino new file mode 100644 index 0000000..8c61d5c --- /dev/null +++ b/examples/advanced/advanced.ino @@ -0,0 +1,53 @@ +/* + + This example is a plain vanilla ESPFMfGK totally open and active features for anything. + + It might be good solution for everything that will be used on the bench only. But keep + in mind: it is open as f*ck and anyone can delete/modify/see everything. + +*/ + +#include +#include +// Remove the file systems that are not needed. +#include +#include +#include +#include +#include +// the thing. +#include + +// have a look at this concept to keep your private data safe! +// https://github.com/holgerlembke/privatedata +// #include + + +const word filemanagerport = 8080; +// we want a different port than the webserver +ESPFMfGK filemgr(filemanagerport); + + +void setup() { + Serial.begin(115200); + delay(1000); + Serial.println("\n\nESPFMfGK plain demo"); + + // login into WiFi + // Change needed! + WiFi.begin("change", "here"); + while (WiFi.status() != WL_CONNECTED) { + delay(10); + } + + addFileSystems(); + setupFilemanager(); + + +} + +void loop() { + filemgr.handleClient(); +} + +// \ No newline at end of file diff --git a/src/ESPFMfGK.h b/src/ESPFMfGK.h index 8bd480c..263760d 100644 --- a/src/ESPFMfGK.h +++ b/src/ESPFMfGK.h @@ -82,7 +82,7 @@ For compatibility reasons, the fileManagerServerStaticsInternally is activated by default. */ -// #define fileManagerServerStaticsInternally +#define fileManagerServerStaticsInternally // #define fileManagerServerStaticsInternallyDeflate