Add support for exporting .torrent from WebUI

PR #16968.
This commit is contained in:
Tom Piccirello
2022-05-03 21:13:24 -07:00
committed by GitHub
parent 48fa4e116c
commit fb7f7d0c75
9 changed files with 55 additions and 1 deletions

View File

@@ -1414,3 +1414,19 @@ void TorrentsController::renameFolderAction()
throw APIError(APIErrorType::Conflict, error.message());
}
}
void TorrentsController::exportAction()
{
requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
const nonstd::expected<QByteArray, QString> result = torrent->exportToBuffer();
if (!result)
throw APIError(APIErrorType::Conflict, tr("Unable to export torrent file. Error: %1").arg(result.error()));
setResult(result.value());
}