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

@@ -91,3 +91,8 @@ void APIController::setResult(const QJsonObject &result)
{
m_result = QJsonDocument(result);
}
void APIController::setResult(const QByteArray &result)
{
m_result = result;
}

View File

@@ -55,6 +55,7 @@ protected:
void setResult(const QString &result);
void setResult(const QJsonArray &result);
void setResult(const QJsonObject &result);
void setResult(const QByteArray &result);
private:
StringMap m_params;

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());
}

View File

@@ -87,4 +87,5 @@ private slots:
void toggleFirstLastPiecePrioAction();
void renameFileAction();
void renameFolderAction();
void exportAction();
};