In src/SPIFFSEditor.cpp:

using Arduino esp32 FS' LITTLEFS.mkdir(path) and LITTLEFS.rmdir(path) to get web file management working w/ LITTLEFS on ESP32.
It is slightly different than with esp8266 LittleFS.h library.
- On ESP32 w/ LITTLEFS, a new file can be created same way as with SPIFFS, /folder/folder/file.txt - folders are created silently, idea taken from:
https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.cpp#L55
- On ESP32 w/ LITTLEFS file remove - first delete the file, then folders if empty 
- For a compatibility, a folder alone cannot be purposely created. A file will be created instead.
- Note, a confuse may occur: /mystuff  could be a folder or a file, both will look same way on SPIFFSEditor web file tree.
This commit is contained in:
lorol
2020-07-03 16:47:21 -04:00
parent 0b6b4ca3dd
commit ea80883726
10 changed files with 25 additions and 2 deletions

View File

@@ -240,6 +240,9 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
}
} else if(request->method() == HTTP_DELETE){
if(request->hasParam("path", true)){
#ifdef ESP32
_fs.rmdir(request->getParam("path", true)->value()); // try rmdir for littlefs
#endif
_fs.remove(request->getParam("path", true)->value());
request->send(200, "", "DELETE: "+request->getParam("path", true)->value());
} else
@@ -275,7 +278,27 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
String filename = request->getParam("path", true)->value();
if(_fs.exists(filename)){
request->send(200);
} else {
} else {
/*******************************************************/
#ifdef ESP32
if (strchr(filename.c_str(), '/')) {
// For file creation, silently make subdirs as needed. If any fail,
// it will be caught by the real file open later on
char *pathStr = strdup(filename.c_str());
if (pathStr) {
// Make dirs up to the final fnamepart
char *ptr = strchr(pathStr, '/');
while (ptr) {
*ptr = 0;
_fs.mkdir(pathStr);
*ptr = '/';
ptr = strchr(ptr+1, '/');
}
}
free(pathStr);
}
#endif
/*******************************************************/
fs::File f = _fs.open(filename, "w");
if(f){
f.write((uint8_t)0x00);

View File

@@ -2,7 +2,7 @@
//File: edit.htm.gz, Size: 4503
#define edit_htm_gz_len 4503
const uint8_t edit_htm_gz[] PROGMEM = {
0x1F,0x8B,0x08,0x08,0x59,0xFA,0xF9,0x5E,0x02,0x00,0x65,0x64,0x69,0x74,0x2E,0x68,0x74,0x6D,0x00,0xB5,
0x1F,0x8B,0x08,0x08,0x0F,0x7A,0xFF,0x5E,0x02,0x00,0x65,0x64,0x69,0x74,0x2E,0x68,0x74,0x6D,0x00,0xB5,
0x1A,0x0B,0x5B,0xDB,0x36,0xF0,0xAF,0x18,0x6F,0x63,0xF6,0xE2,0x38,0x0E,0x50,0xD6,0x3A,0x18,0x16,0x1E,
0xEB,0xBB,0x50,0x12,0xDA,0xD1,0x8E,0xED,0x53,0x6C,0x25,0x56,0xB1,0x25,0xCF,0x96,0x09,0x34,0xCD,0x7F,
0xDF,0x49,0xF2,0x93,0x84,0xEE,0xF1,0x6D,0xA5,0x60,0x49,0xA7,0x3B,0xDD,0x9D,0xEE,0x25,0xD9,0x7B,0x1B,