From b211725a19775cdb921ad7d83476088f511c95c0 Mon Sep 17 00:00:00 2001 From: steff393 <73853447+steff393@users.noreply.github.com> Date: Tue, 31 Dec 2024 00:54:28 +0100 Subject: [PATCH] SPIFFSEditor: Remove previous change and add an / if needed --- src/SPIFFSEditor.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/SPIFFSEditor.cpp b/src/SPIFFSEditor.cpp index a88ec45c..625103fe 100644 --- a/src/SPIFFSEditor.cpp +++ b/src/SPIFFSEditor.cpp @@ -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){ @@ -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(); } }