Browse Source

Add torrents path, now working though

master
Jørgen Lien Sellæg 9 years ago
parent
commit
83e55a5461
  1. 29
      toREST/src/main.cxx

29
toREST/src/main.cxx

@ -51,11 +51,24 @@ int main(int argc, char *argv[]) {
*resp << response; *resp << response;
}; };
http_server.resource["^/session/torrents(\\?.*)?\\/?$"]["GET"]=[&session](std::shared_ptr<HttpServer::Response> resp, std::shared_ptr<HttpServer::Request> req) { http_server.resource["^/session(\\?.*)?\\/?$"]["PATCH"]=[&](std::shared_ptr<HttpServer::Response> resp, std::shared_ptr<HttpServer::Request> req) {
auto response = http::response(); auto response = http::response();
auto content_type=req->header.find("Content-Type");
auto json=util::json::parse(req->content);
if (session.is_valid()) { if (session.is_valid()) {
const auto settings = session.get_settings();
response.set_body({ response.set_body({
{ { "torrents", nlohmann::json::array() } }, { "paused", session.is_paused() },
{ "port", session.listen_port() },
{ "dht_enabled", session.is_dht_running() },
{ "down_limit", settings.get_int(settings.download_rate_limit) },
{ "up_limit", settings.get_int(settings.upload_rate_limit) },
{ "torrents", session.get_torrents().size() }, //TODO Optimize
{ "default_download_dir", default_download_dir.filename().string() },
{ "root_dir", root_dir.string() },
}); });
} else { } else {
auto response_code = http::code(http::service_unavailable); auto response_code = http::code(http::service_unavailable);
@ -65,6 +78,18 @@ int main(int argc, char *argv[]) {
*resp << response; *resp << response;
}; };
http_server.resource["^/session/torrents(\\?.*)?\\/?$"]["GET"]=[&session](std::shared_ptr<HttpServer::Response> resp, std::shared_ptr<HttpServer::Request> req) {
auto response = http::response();
if (session.is_valid()) {
response.set_body(nlohmann::json::object({{"torrents",nlohmann::json::array()}}));
} else {
auto response_code = http::code(http::service_unavailable);
response.set_body({{response_code.first, response_code.second}});
response.set_status(response_code.first);
}
*resp << response;
};
std::thread server_thread([&http_server](){ std::thread server_thread([&http_server](){
http_server.start(); http_server.start();
}); });

Loading…
Cancel
Save