From 15b75e2bb76935e2b25f8e910c35d135d4cc8f2e Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 30 Sep 2026 22:03:43 -0400 Subject: [PATCH] handle magnetLink field --- libi2pd_client/TorrentsRPC.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libi2pd_client/TorrentsRPC.cpp b/libi2pd_client/TorrentsRPC.cpp index 950ff1b1..3ac27027 100644 --- a/libi2pd_client/TorrentsRPC.cpp +++ b/libi2pd_client/TorrentsRPC.cpp @@ -11,6 +11,9 @@ #include #if !defined(ANDROID) && (BOOST_VERSION >= 108100) // boost::json since 1.75, we allow it since 1.81 due to std::string_view compatibility #include +#include +#include +#include #define JSON_SUPPORTED #endif #include @@ -330,6 +333,28 @@ namespace torrents return boost::json::value(hexHash); } }, + { + "magnetLink", [](std::shared_ptr torrent) + { + std::string hexHash; + boost::algorithm::hex (torrent->GetInfoHash ().begin(), torrent->GetInfoHash ().end(), std::back_inserter(hexHash)); + std::string magnet("magnet:?xt=urn:btih:"); + magnet += hexHash; + if (!torrent->GetName ().empty ()) + { + magnet += "&dn="; + boost::urls::encoding_opts opts; + opts.space_as_plus = true; + magnet += boost::urls::encode (torrent->GetName (), boost::urls::grammar::alnum_chars, opts); + } + if (!torrent->GetAnnounce ().empty ()) + { + magnet += "&tr="; + magnet += boost::core::string_view (boost::urls::url (torrent->GetAnnounce ())); + } + return boost::json::value(magnet); + } + }, { "pieces", [](std::shared_ptr torrent) { auto [bitfield, have] = torrent->CreateBitfield ();