mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
update
- Fixed bug in request handler - needed to add support for non-param URL requests
This commit is contained in:
parent
2d1906c5cc
commit
c220bf6606
@ -65,10 +65,8 @@ void ProjectConfig::load()
|
||||
ESP.restart();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_d("Project config found - Config length: %d", configLen);
|
||||
}
|
||||
|
||||
log_d("Project config found - Config length: %d", configLen);
|
||||
|
||||
char buff[configLen];
|
||||
getBytes("config", buff, configLen);
|
||||
|
||||
@ -41,7 +41,6 @@ void APIServer::setupServer()
|
||||
routes.emplace("deleteRoute", &APIServer::deleteRoute);
|
||||
|
||||
// Camera Routes
|
||||
|
||||
|
||||
//! reserve enough memory for all routes - must be called after adding routes and before adding routes to route_map
|
||||
indexes.reserve(routes.size()); // this is done to avoid reallocation of memory and copying of data
|
||||
@ -80,46 +79,68 @@ void APIServer::handleRequest(AsyncWebServerRequest *request)
|
||||
{
|
||||
try
|
||||
{
|
||||
size_t params = request->params();
|
||||
// Get the route
|
||||
log_i("Request URL: %s", request->url().c_str());
|
||||
int params = request->params();
|
||||
auto it_map = route_map.find(request->pathArg(0).c_str());
|
||||
log_i("Request First Arg: %s", request->pathArg(0).c_str());
|
||||
auto it_method = it_map->second.find(request->pathArg(1).c_str());
|
||||
log_i("Request Second Arg: %s", request->pathArg(1).c_str());
|
||||
log_i("Request: %s", request->pathArg(0).c_str());
|
||||
log_i("Request: %s", request->pathArg(1).c_str());
|
||||
|
||||
for (int i = 0; i < params; i++)
|
||||
auto it_map = route_map.find(request->pathArg(0).c_str());
|
||||
auto it_method = it_map->second.find(request->pathArg(1).c_str());
|
||||
|
||||
log_d("Params: %d", params);
|
||||
if (params > 0)
|
||||
{
|
||||
AsyncWebParameter *param = request->getParam(i);
|
||||
log_d("We have params!");
|
||||
for (size_t i = 0; i < params; i++)
|
||||
{
|
||||
log_d("We are executing the for loop");
|
||||
AsyncWebParameter *param = request->getParam(i);
|
||||
if (it_map != route_map.end())
|
||||
{
|
||||
if (it_map != route_map.end())
|
||||
if (it_method != it_map->second.end())
|
||||
{
|
||||
if (it_method != it_map->second.end())
|
||||
{
|
||||
(*this.*(it_method->second))(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Command\"}");
|
||||
request->redirect("/");
|
||||
return;
|
||||
}
|
||||
(*this.*(it_method->second))(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Map Index\"}");
|
||||
request->redirect("/");
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Command\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Map Index\"}");
|
||||
return;
|
||||
}
|
||||
log_i("%s[%s]: %s\n", _networkMethodsMap[request->method()].c_str(), param->name().c_str(), param->value().c_str());
|
||||
}
|
||||
}
|
||||
request->send(200, MIMETYPE_JSON, "{\"msg\":\"Command executed\"}");
|
||||
else
|
||||
{
|
||||
log_d("No params, so we skipped the for loop");
|
||||
if (it_map != route_map.end())
|
||||
{
|
||||
if (it_method != it_map->second.end())
|
||||
{
|
||||
log_d("We are trying to execute the function");
|
||||
(*this.*(it_method->second))(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Command\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Map Index\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...) // catch all exceptions
|
||||
catch (...)
|
||||
{
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"An Error has occurred\"}");
|
||||
log_e("Error handling request");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user