Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

ESP32: SPIFFSEditor: Use path() instead of name() to keep '/' before filename (#1210) #1220

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AsyncWebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer)

IPAddress AsyncWebSocketClient::remoteIP() {
if(!_client) {
return IPAddress(0U);
return IPAddress((uint32_t)0U);
}
return _client->remoteIP();
}
Expand Down
19 changes: 17 additions & 2 deletions src/SPIFFSEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,11 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
output += "{\"type\":\"";
output += "file";
output += "\",\"name\":\"";
#ifdef ESP32
output += String(entry.path());
#else
output += String(entry.name());
#endif
output += "\",\"size\":";
output += String(entry.size());
output += "}";
Expand Down Expand Up @@ -501,8 +505,12 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
} else
request->send(404);
} else if(request->method() == HTTP_POST){
if(request->hasParam("data", true, true) && _fs.exists(request->getParam("data", true, true)->value()))
if(request->hasParam("data", true, true) && (_fs.exists(request->getParam("data", true, true)->value())))
request->send(200, "", "UPLOADED: "+request->getParam("data", true, true)->value());
/*SF-begin*/ // add an / if needed
else if (request->hasParam("data", true, true) && (_fs.exists('/' + request->getParam("data", true, true)->value())))
request->send(200, "", "UPLOADED: /"+request->getParam("data", true, true)->value());
/*SF-end*/
else
request->send(500);
} else if(request->method() == HTTP_PUT){
Expand All @@ -527,9 +535,16 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){

void SPIFFSEditor::handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final){
if(!index){
/*SF-begin*/
String filePath = filename; // Initial filename
if (!filePath.startsWith("/")) { // Check if filename starts with '/', if not, prepend '/'
filePath = "/" + filePath; // Prepend '/' if not present
}
/*SF-end*/
if(!_username.length() || request->authenticate(_username.c_str(),_password.c_str())){
_authenticated = true;
request->_tempFile = _fs.open(filename, "w");
//request->_tempFile = _fs.open(filename, "w");
request->_tempFile = _fs.open(filePath, "w"); /*SF-begin*/
_startTime = millis();
}
}
Expand Down