|
|
|
@ -3,9 +3,12 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <boost/filesystem.hpp> |
|
|
|
#include <boost/filesystem.hpp> |
|
|
|
#include <http.hpp> |
|
|
|
#include <http.hpp> |
|
|
|
#include <util.hpp> |
|
|
|
|
|
|
|
#include <libtorrent/sha1_hash.hpp> |
|
|
|
#include <libtorrent/sha1_hash.hpp> |
|
|
|
|
|
|
|
#include <util.hpp> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace tr { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace torrent { |
|
|
|
template <class torrent_t> |
|
|
|
template <class torrent_t> |
|
|
|
static nlohmann::json to_json(torrent_t torrent) { |
|
|
|
static nlohmann::json to_json(torrent_t torrent) { |
|
|
|
std::stringstream ss; // TODO optimize
|
|
|
|
std::stringstream ss; // TODO optimize
|
|
|
|
@ -23,8 +26,8 @@ static nlohmann::json to_json(torrent_t torrent) { |
|
|
|
{"down_limit", torrent.download_limit()}, |
|
|
|
{"down_limit", torrent.download_limit()}, |
|
|
|
{"name", status.name}}; |
|
|
|
{"name", status.name}}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
namespace tr { |
|
|
|
|
|
|
|
namespace session { |
|
|
|
namespace session { |
|
|
|
namespace torrents { |
|
|
|
namespace torrents { |
|
|
|
namespace id { |
|
|
|
namespace id { |
|
|
|
@ -42,10 +45,14 @@ void get(torrent_session &session, response resp, request req) { |
|
|
|
return respond(http::service_unavailable); |
|
|
|
return respond(http::service_unavailable); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string hash = req->path.substr(18, req->path.size() - 18); |
|
|
|
const auto hash = req->path.substr(18, req->path.size() - 18); //TODO hacky
|
|
|
|
|
|
|
|
const auto torrent = session.find_torrent(util::sha1::string(hash)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!torrent.is_valid()) { |
|
|
|
|
|
|
|
return respond(http::bad_request); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
http_response.set_body(nlohmann::json::object( |
|
|
|
http_response.set_body(torrent::to_json(torrent)); |
|
|
|
{{"info_hash", hash}})); |
|
|
|
|
|
|
|
http_response.set_status(http::ok); |
|
|
|
http_response.set_status(http::ok); |
|
|
|
*resp << http_response; |
|
|
|
*resp << http_response; |
|
|
|
} |
|
|
|
} |
|
|
|
|