You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.7 KiB
60 lines
1.7 KiB
#ifndef _TR_TORRENT_HPP_ |
|
#define _TR_TORRENT_HPP_ |
|
|
|
#include <boost/filesystem.hpp> |
|
#include <http.hpp> |
|
#include <util.hpp> |
|
#include <libtorrent/sha1_hash.hpp> |
|
|
|
template <class torrent_t> |
|
static nlohmann::json to_json(torrent_t torrent) { |
|
std::stringstream ss; // TODO optimize |
|
ss << torrent.info_hash(); |
|
const std::string hash = ss.str(); |
|
const auto status = torrent.status( |
|
torrent.query_name | |
|
torrent.query_save_path); |
|
return {{"info_hash", hash}, |
|
{"paused", status.paused}, |
|
{"seeding", status.is_seeding}, |
|
{"state", status.state}, |
|
{"priority", status.priority}, |
|
{"up_limit", torrent.upload_limit()}, |
|
{"down_limit", torrent.download_limit()}, |
|
{"name", status.name}}; |
|
} |
|
|
|
namespace tr { |
|
namespace session { |
|
namespace torrents { |
|
namespace id { |
|
template <class torrent_session, class request, class response> |
|
void get(torrent_session &session, response resp, request req) { |
|
auto http_response = http::response(); |
|
const auto respond = [&](http::status status) { |
|
const auto response_code = http::code(status); |
|
http_response.set_body({{"code", response_code.first}, {"status", response_code.second}}); |
|
http_response.set_status(response_code.first); |
|
*resp << http_response; |
|
}; |
|
|
|
if (!session.is_valid()) { |
|
return respond(http::service_unavailable); |
|
} |
|
|
|
std::string hash = req->path.substr(18, req->path.size() - 18); |
|
|
|
http_response.set_body(nlohmann::json::object( |
|
{{"info_hash", hash}})); |
|
http_response.set_status(http::ok); |
|
*resp << http_response; |
|
} |
|
|
|
template <class settings, class torrent_session, class request, class response> |
|
void patch(settings opts, torrent_session &session, response resp, request req) { |
|
} |
|
} |
|
} |
|
} |
|
} |
|
#endif
|
|
|