#ifndef _TR_TORRENTS_HPP_ #define _TR_TORRENTS_HPP_ #include namespace tr { namespace session { namespace torrents { template void get(torrent_session &session, response resp, request req) { auto http_response = http::response(); if (session.is_valid()) { auto torrents = session.get_torrents(); auto response_object = nlohmann::json::object(); auto torrents_json = nlohmann::json::array(); for (auto &torrent : torrents) { if (torrent.is_valid()) { const auto hash = torrent.info_hash().to_string(); const auto status = torrent.status( torrent.query_name | torrent.query_save_path); torrents_json.push_back({{"hash", hash}, {"paused", status.paused}, {"seeding", status.is_seeding}, {"state", status.state}, {"priority", status.priority}, {"name", status.name}}); } } response_object["torrents"] = torrents_json; http_response.set_status(http::ok); http_response.set_body(response_object); } else { auto response_code = http::code(http::service_unavailable); http_response.set_body({{"code", response_code.first}, {"status", response_code.second}}); http_response.set_status(response_code.first); } *resp << http_response; } } } } #endif