|
|
|
|
@ -18,18 +18,23 @@ void get(torrent_session &session, response resp, request req) {
|
|
|
|
|
http_response.set_status(response_code.first); |
|
|
|
|
*resp << http_response; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (!session.is_valid()) { |
|
|
|
|
return respond(http::service_unavailable); |
|
|
|
|
} |
|
|
|
|
auto torrents = session.get_torrents(); |
|
|
|
|
|
|
|
|
|
auto response_object = nlohmann::json::object(); |
|
|
|
|
|
|
|
|
|
auto torrents = session.get_torrents(); |
|
|
|
|
auto torrents_json = nlohmann::json::array(); |
|
|
|
|
for (auto &torrent : torrents) { |
|
|
|
|
if (torrent.is_valid()) { |
|
|
|
|
torrents_json.push_back(tr::torrent::to_json(torrent)); |
|
|
|
|
torrents_json.push_back(torrent::to_json(torrent)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
response_object["torrents"] = torrents_json; |
|
|
|
|
|
|
|
|
|
http_response.set_status(http::ok); |
|
|
|
|
http_response.set_body(response_object); |
|
|
|
|
*resp << http_response; |
|
|
|
|
@ -83,7 +88,7 @@ void del(torrent_session &session, response resp, request req) {
|
|
|
|
|
options = remove_files; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const auto handle = session.find_torrent(util::sha1::string(obj)); |
|
|
|
|
const auto handle = session.find_torrent(util::sha1::info_hash(obj)); |
|
|
|
|
|
|
|
|
|
if (handle.is_valid()) { |
|
|
|
|
session.remove_torrent(handle, options); |
|
|
|
|
@ -194,12 +199,9 @@ void post(settings opts, torrent_session &session, response resp, request req) {
|
|
|
|
|
params.name = obj; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::stringstream ss; |
|
|
|
|
ss << params.info_hash; |
|
|
|
|
|
|
|
|
|
session.async_add_torrent(params); |
|
|
|
|
|
|
|
|
|
http_response.add_header({"Location", "/session/torrents/" + ss.str()}); |
|
|
|
|
http_response.add_header({"Location", "/session/torrents/" + util::sha1::string(params.info_hash)}); |
|
|
|
|
return respond(http::created); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|