mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-23 00:47:21 -06:00
Add WebAPI for downloading torrent metadata
Signed-off-by: Thomas Piccirello <thomas@piccirello.com>
This commit is contained in:
@@ -141,6 +141,22 @@ catch (const lt::system_error &err)
|
||||
return nonstd::make_unexpected(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
|
||||
nonstd::expected<QByteArray, QString> BitTorrent::TorrentDescriptor::saveToBuffer() const
|
||||
try
|
||||
{
|
||||
const lt::entry torrentEntry = lt::write_torrent_file(m_ltAddTorrentParams);
|
||||
// usually torrent size should be smaller than 1 MB,
|
||||
// however there are >100 MB v2/hybrid torrent files out in the wild
|
||||
QByteArray buffer;
|
||||
buffer.reserve(1024 * 1024);
|
||||
lt::bencode(std::back_inserter(buffer), torrentEntry);
|
||||
return buffer;
|
||||
}
|
||||
catch (const lt::system_error &err)
|
||||
{
|
||||
return nonstd::make_unexpected(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
|
||||
BitTorrent::TorrentDescriptor::TorrentDescriptor(lt::add_torrent_params ltAddTorrentParams)
|
||||
: m_ltAddTorrentParams {std::move(ltAddTorrentParams)}
|
||||
{
|
||||
|
||||
@@ -69,6 +69,7 @@ namespace BitTorrent
|
||||
static nonstd::expected<TorrentDescriptor, QString> loadFromFile(const Path &path) noexcept;
|
||||
static nonstd::expected<TorrentDescriptor, QString> parse(const QString &str) noexcept;
|
||||
nonstd::expected<void, QString> saveToFile(const Path &path) const;
|
||||
nonstd::expected<QByteArray, QString> saveToBuffer() const;
|
||||
|
||||
const lt::add_torrent_params <AddTorrentParams() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user