Skip to content

Commit

Permalink
SPIFFSEditor: Remove previous change and add an / if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
steff393 authored Dec 30, 2024
1 parent 0856b86 commit b211725
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/SPIFFSEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,12 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
} else
request->send(404);
} else if(request->method() == HTTP_POST){
// /*SF-begin*/ Add an optional parameter path to control the filename (for example add the /)
if (request->hasParam("data", true, true) && request->hasParam("path", true, true) && _fs.exists(request->getParam("path", true, true)->value())) {
request->send(200, "", "UPLOADED: "+request->getParam("path", true, true)->value());
} else /*SF-end*/ 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 @@ -534,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

0 comments on commit b211725

Please sign in to comment.