Fixes in firmware
This commit is contained in:
@@ -17,6 +17,7 @@ namespace webdav_constants {
|
||||
FLASH_TEXT(RESOURCETYPE_START) = "<D:resourcetype>";
|
||||
FLASH_TEXT(RESOURCETYPE_END) = "</D:resourcetype>";
|
||||
FLASH_TEXT(RESOURCE_COLLECTION) = "<D:collection/>";
|
||||
FLASH_TEXT(HTTP_204_NO_CONTENT) = "HTTP/1.1 204 No Content";
|
||||
|
||||
FLASH_TEXT(CONTENTLEN_START) = "<D:getcontentlength>";
|
||||
FLASH_TEXT(CONTENTLEN_END) = "</D:getcontentlength>";
|
||||
@@ -31,8 +32,14 @@ void listFiles(AsyncResponseStream * response, const char *folderPath, Dir * dir
|
||||
{
|
||||
using namespace webdav_constants;
|
||||
response->println(MULTISTATUS_START);
|
||||
Serial.println("Before rewind");
|
||||
dir->rewind();
|
||||
Serial.println("After rewind");
|
||||
while (dir->next()) {
|
||||
Serial.println("Inside dir loop");
|
||||
Serial.println(folderPath);
|
||||
Serial.println(dir->fileName());
|
||||
|
||||
response->print(RESPONSE_START);
|
||||
response->print(HREF_START);
|
||||
response->print(folderPath);
|
||||
@@ -53,7 +60,7 @@ void listFiles(AsyncResponseStream * response, const char *folderPath, Dir * dir
|
||||
response->print(PROP_END);
|
||||
response->print(STATUS_OK);
|
||||
response->print(PROPSTAT_END);
|
||||
response->print(webdav_constants::RESPONSE_END);
|
||||
response->println(webdav_constants::RESPONSE_END);
|
||||
}
|
||||
response->println(MULTISTATUS_END);
|
||||
}
|
||||
@@ -75,14 +82,14 @@ public:
|
||||
|
||||
virtual void handleRequest(AsyncWebServerRequest *request) override final
|
||||
{
|
||||
if (request->url() == prefix_ && request->method() == HTTP_PROPFIND) {
|
||||
if (request->url() == prefix_ + "/" && request->method() == HTTP_PROPFIND) {
|
||||
Serial.println("Propfind start");
|
||||
AsyncResponseStream * response = request->beginResponseStream("application/xml");
|
||||
Dir dir = SPIFFS.openDir(folder_);
|
||||
listFiles(response, "/", &dir);
|
||||
request->send(response);
|
||||
} else if(request->url() == prefix_ && request->method() == HTTP_GET) {
|
||||
AsyncResponseStream * response = request->beginResponseStream("text/plain");
|
||||
} else if(request->url() == prefix_ + "/" && request->method() == HTTP_GET) {
|
||||
AsyncResponseStream * response = request->beginResponseStream("text/plain", 1460*10);
|
||||
Dir dir = SPIFFS.openDir(folder_);
|
||||
Serial.print("Opening folder ");
|
||||
Serial.println(folder_);
|
||||
@@ -95,15 +102,21 @@ public:
|
||||
}
|
||||
else if (request->method() == HTTP_GET) {
|
||||
auto path = folder_ + request->url().substring(prefix_.length());
|
||||
Serial.print("Testing if path exists: ");
|
||||
Serial.println(path);
|
||||
if (SPIFFS.exists(path)) {
|
||||
Serial.println("Exists!");
|
||||
request->send(SPIFFS, path, "application/x-msgpack");
|
||||
} else {
|
||||
Serial.println("Does not exist :(");
|
||||
request->send(404, "text/plain", "Webdav: File not found");
|
||||
}
|
||||
} else if (request->method() == HTTP_DELETE) {
|
||||
auto path = folder_ + request->url().substring(prefix_.length());
|
||||
if (SPIFFS.exists(path)) {
|
||||
if(SPIFFS.remove(path))
|
||||
request->send(204, "text/plain", "Success");
|
||||
else
|
||||
request->send(404, "text/plain", "Webdav: Invalid delete request");
|
||||
} else {
|
||||
request->send(404, "text/plain", "Webdav: File to delete not found");
|
||||
}
|
||||
} else {
|
||||
request->send(404, "text/plain", "Webdav: Invalid request");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user