add HTTP/Delete method handler for SPIFFS

1.2-legacy
Charles Crossan 2020-12-21 21:10:53 -05:00
rodzic 5c70f36aa5
commit 47ccfb6106
1 zmienionych plików z 29 dodań i 0 usunięć

Wyświetl plik

@ -55,6 +55,7 @@ void handleFavicon(HTTPRequest *req, HTTPResponse *res);
void handleRoot(HTTPRequest *req, HTTPResponse *res);
void handleStaticBrowse(HTTPRequest *req, HTTPResponse *res);
void handleStaticPost(HTTPRequest *req, HTTPResponse *res);
void handleStaticDelete(HTTPRequest *req, HTTPResponse *res);
void handleStatic(HTTPRequest *req, HTTPResponse *res);
void handleRestart(HTTPRequest *req, HTTPResponse *res);
void handle404(HTTPRequest *req, HTTPResponse *res);
@ -240,6 +241,7 @@ void initWebServer()
ResourceNode *nodeRoot = new ResourceNode("/", "GET", &handleRoot);
ResourceNode *nodeStaticBrowse = new ResourceNode("/static", "GET", &handleStaticBrowse);
ResourceNode *nodeStaticPOST = new ResourceNode("/static", "POST", &handleStaticPost);
ResourceNode *nodeStaticDelete = new ResourceNode("/static", "DELETE", &handleStaticDelete);
ResourceNode *nodeStatic = new ResourceNode("/static/*", "GET", &handleStatic);
ResourceNode *nodeRestart = new ResourceNode("/restart", "POST", &handleRestart);
ResourceNode *node404 = new ResourceNode("", "GET", &handle404);
@ -257,6 +259,7 @@ void initWebServer()
secureServer->registerNode(nodeRoot);
secureServer->registerNode(nodeStaticBrowse);
secureServer->registerNode(nodeStaticPOST);
secureServer->registerNode(nodeStaticDelete);
secureServer->registerNode(nodeStatic);
secureServer->registerNode(nodeRestart);
secureServer->registerNode(nodeFormUpload);
@ -276,6 +279,7 @@ void initWebServer()
insecureServer->registerNode(nodeRoot);
insecureServer->registerNode(nodeStaticBrowse);
insecureServer->registerNode(nodeStaticPOST);
insecureServer->registerNode(nodeStaticDelete);
insecureServer->registerNode(nodeStatic);
insecureServer->registerNode(nodeRestart);
insecureServer->registerNode(nodeFormUpload);
@ -389,6 +393,31 @@ void handleStaticPost(HTTPRequest *req, HTTPResponse *res)
res->println("</body></html>");
}
void handleStaticDelete(HTTPRequest *req, HTTPResponse *res)
{
ResourceParameters *params = req->getParams();
std::string paramValDelete;
res->setHeader("Content-Type", "application/json");
if (params->getQueryParameter("delete", paramValDelete)) {
std::string pathDelete = "/" + paramValDelete;
if (SPIFFS.remove(pathDelete.c_str())) {
Serial.println(pathDelete.c_str());
res->println("{");
res->println("\"status\": \"ok\"");
res->println("}");
return;
} else {
Serial.println(pathDelete.c_str());
res->println("{");
res->println("\"status\": \"Error\"");
res->println("}");
return;
}
}
}
void handleSpiffsBrowseStatic(HTTPRequest *req, HTTPResponse *res)
{
// jm