mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-04-10 15:44:33 +00:00
Fix Indentations and Shutdown Handling
This commit is contained in:
parent
fd8cbf0c7d
commit
04421d84a3
@ -120,25 +120,34 @@ namespace confighttp
|
||||
response->write(data.str());
|
||||
});
|
||||
pt::ptree inputTree, fileTree;
|
||||
try {
|
||||
try
|
||||
{
|
||||
//TODO: Input Validation
|
||||
pt::read_json(ss, inputTree);
|
||||
pt::read_json(SUNSHINE_ASSETS_DIR "/" APPS_JSON, fileTree);
|
||||
auto &apps_node = fileTree.get_child("apps"s);
|
||||
int index = inputTree.get<int>("index");
|
||||
BOOST_LOG(info) << inputTree.get_child("prep-cmd").empty();
|
||||
if(inputTree.get_child("prep-cmd").empty())inputTree.erase("prep-cmd");
|
||||
if (inputTree.get_child("prep-cmd").empty())
|
||||
inputTree.erase("prep-cmd");
|
||||
inputTree.erase("index");
|
||||
if(index == -1){
|
||||
if (index == -1)
|
||||
{
|
||||
apps_node.push_back(std::make_pair("", inputTree));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
//Unfortuantely Boost PT does not allow to directly edit the array, copt should do the trick
|
||||
pt::ptree newApps;
|
||||
int i = 0;
|
||||
for (const auto& kv : apps_node) {
|
||||
if(i == index){
|
||||
for (const auto &kv : apps_node)
|
||||
{
|
||||
if (i == index)
|
||||
{
|
||||
newApps.push_back(std::make_pair("", inputTree));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
newApps.push_back(std::make_pair("", kv.second));
|
||||
}
|
||||
i++;
|
||||
@ -149,7 +158,9 @@ namespace confighttp
|
||||
pt::write_json(SUNSHINE_ASSETS_DIR "/" APPS_JSON, fileTree);
|
||||
outputTree.put("status", "true");
|
||||
proc::refresh(SUNSHINE_ASSETS_DIR "/" APPS_JSON);
|
||||
} catch (std::exception &e) {
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
BOOST_LOG(warning) << e.what();
|
||||
outputTree.put("status", "false");
|
||||
outputTree.put("error", "Invalid Input JSON");
|
||||
@ -167,21 +178,27 @@ namespace confighttp
|
||||
response->write(data.str());
|
||||
});
|
||||
pt::ptree fileTree;
|
||||
try {
|
||||
try
|
||||
{
|
||||
pt::read_json(SUNSHINE_ASSETS_DIR "/" APPS_JSON, fileTree);
|
||||
auto &apps_node = fileTree.get_child("apps"s);
|
||||
int index = stoi(request->path_match[1]);
|
||||
BOOST_LOG(info) << index;
|
||||
if(index <= 0){
|
||||
if (index <= 0)
|
||||
{
|
||||
outputTree.put("status", "false");
|
||||
outputTree.put("error", "Invalid Index");
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
//Unfortuantely Boost PT does not allow to directly edit the array, copt should do the trick
|
||||
pt::ptree newApps;
|
||||
int i = 0;
|
||||
for (const auto& kv : apps_node) {
|
||||
if(i != index){
|
||||
for (const auto &kv : apps_node)
|
||||
{
|
||||
if (i != index)
|
||||
{
|
||||
newApps.push_back(std::make_pair("", kv.second));
|
||||
}
|
||||
i++;
|
||||
@ -192,7 +209,9 @@ namespace confighttp
|
||||
pt::write_json(SUNSHINE_ASSETS_DIR "/" APPS_JSON, fileTree);
|
||||
outputTree.put("status", "true");
|
||||
proc::refresh(SUNSHINE_ASSETS_DIR "/" APPS_JSON);
|
||||
} catch (std::exception &e) {
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
BOOST_LOG(warning) << e.what();
|
||||
outputTree.put("status", "false");
|
||||
outputTree.put("error", "Invalid File JSON");
|
||||
@ -232,8 +251,25 @@ namespace confighttp
|
||||
shutdown_event->raise(true);
|
||||
return;
|
||||
}
|
||||
auto accept_and_run = [&](auto *http_server) {
|
||||
try
|
||||
{
|
||||
http_server->accept_and_run();
|
||||
}
|
||||
catch (boost::system::system_error &err)
|
||||
{
|
||||
// It's possible the exception gets thrown after calling http_server->stop() from a different thread
|
||||
if (shutdown_event->peek())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::thread tcp{&https_server_t::accept_and_run, &http_server};
|
||||
BOOST_LOG(fatal) << "Couldn't start Configuration HTTP server to ports ["sv << PORT_HTTPS << ", "sv << PORT_HTTP << "]: "sv << err.what();
|
||||
shutdown_event->raise(true);
|
||||
return;
|
||||
}
|
||||
};
|
||||
std::thread tcp{accept_and_run, &http_server};
|
||||
|
||||
// Wait for any event
|
||||
shutdown_event->view();
|
||||
|
Loading…
x
Reference in New Issue
Block a user