|
|
@ -70,8 +70,12 @@ namespace detail |
|
|
|
// API
|
|
|
|
// API
|
|
|
|
ResourceNode* nodeGetStatus = new ResourceNode("/api/status", "GET", &WebServer::HandleGetStatus_); |
|
|
|
ResourceNode* nodeGetStatus = new ResourceNode("/api/status", "GET", &WebServer::HandleGetStatus_); |
|
|
|
ResourceNode* nodePostInfo = new ResourceNode("/api/info", "POST", &WebServer::HandlePostInfo_); |
|
|
|
ResourceNode* nodePostInfo = new ResourceNode("/api/info", "POST", &WebServer::HandlePostInfo_); |
|
|
|
|
|
|
|
ResourceNode* nodeGetLogList = new ResourceNode("/api/log/list", "GET", &WebServer::HandleLogList_); |
|
|
|
|
|
|
|
ResourceNode* nodeGetLog = new ResourceNode("/api/log/*", "GET", &WebServer::HandleLog_); |
|
|
|
httpServer.registerNode(nodeGetStatus); |
|
|
|
httpServer.registerNode(nodeGetStatus); |
|
|
|
httpServer.registerNode(nodePostInfo); |
|
|
|
httpServer.registerNode(nodePostInfo); |
|
|
|
|
|
|
|
httpServer.registerNode(nodeGetLogList); |
|
|
|
|
|
|
|
httpServer.registerNode(nodeGetLog); |
|
|
|
|
|
|
|
|
|
|
|
// Default node (either a static file, if found, or a 404 error)
|
|
|
|
// Default node (either a static file, if found, or a 404 error)
|
|
|
|
ResourceNode* nodeDefault = new ResourceNode("", "GET", &WebServer::HandleDefault_); |
|
|
|
ResourceNode* nodeDefault = new ResourceNode("", "GET", &WebServer::HandleDefault_); |
|
|
@ -206,6 +210,45 @@ namespace detail |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WebServer::HandleLogList_(HTTPRequest * request, HTTPResponse * response) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
String json; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json = "{\"files\":["; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto logFolder = SPIFFS.open("/log"); |
|
|
|
|
|
|
|
auto file = logFolder.openNextFile(); |
|
|
|
|
|
|
|
bool first = true; |
|
|
|
|
|
|
|
while(file) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(!first) json += ","; |
|
|
|
|
|
|
|
json += "{\"n\":\"/api/log/"; |
|
|
|
|
|
|
|
//::DebugLog.println(file.name());
|
|
|
|
|
|
|
|
json += file.name(); |
|
|
|
|
|
|
|
json += "\",\"s\":"; |
|
|
|
|
|
|
|
json += file.size(); |
|
|
|
|
|
|
|
json += "}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
first = false; |
|
|
|
|
|
|
|
file = logFolder.openNextFile(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json += "]}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response->setHeader("Content-Type", "text/json"); |
|
|
|
|
|
|
|
response->print(json.c_str()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WebServer::HandleLog_(HTTPRequest * request, HTTPResponse * response) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto* params = request->getParams(); |
|
|
|
|
|
|
|
std::string path = params->getPathParameter(0); |
|
|
|
|
|
|
|
std::string fullPath = std::string("/log/") + path; |
|
|
|
|
|
|
|
File file = SPIFFS.open(fullPath.c_str()); |
|
|
|
|
|
|
|
SendContent_(file, response); |
|
|
|
|
|
|
|
file.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void WebServer::HandleDefault_(HTTPRequest * request, HTTPResponse * response) |
|
|
|
void WebServer::HandleDefault_(HTTPRequest * request, HTTPResponse * response) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Discard request body, if we received any
|
|
|
|
// Discard request body, if we received any
|
|
|
|