mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-12 07:48:04 +00:00
Merge pull request #14519 from glassez/add-torrent
Accept "share limits" when adding torrent using WebAPI
This commit is contained in:
commit
73e927ff19
@ -200,6 +200,26 @@ std::optional<bool> Utils::String::parseBool(const QString &string)
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<int> Utils::String::parseInt(const QString &string)
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
const int result = string.toInt(&ok);
|
||||||
|
if (ok)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<double> Utils::String::parseDouble(const QString &string)
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
const double result = string.toDouble(&ok);
|
||||||
|
if (ok)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
QString Utils::String::join(const QVector<QStringRef> &strings, const QString &separator)
|
QString Utils::String::join(const QVector<QStringRef> &strings, const QString &separator)
|
||||||
{
|
{
|
||||||
if (strings.empty())
|
if (strings.empty())
|
||||||
|
@ -67,6 +67,8 @@ namespace Utils::String
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::optional<bool> parseBool(const QString &string);
|
std::optional<bool> parseBool(const QString &string);
|
||||||
|
std::optional<int> parseInt(const QString &string);
|
||||||
|
std::optional<double> parseDouble(const QString &string);
|
||||||
|
|
||||||
QString join(const QVector<QStringRef> &strings, const QString &separator);
|
QString join(const QVector<QStringRef> &strings, const QString &separator);
|
||||||
|
|
||||||
|
@ -117,6 +117,8 @@ const char KEY_FILE_AVAILABILITY[] = "availability";
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using Utils::String::parseBool;
|
using Utils::String::parseBool;
|
||||||
|
using Utils::String::parseInt;
|
||||||
|
using Utils::String::parseDouble;
|
||||||
|
|
||||||
void applyToTorrents(const QStringList &hashes, const std::function<void (BitTorrent::Torrent *torrent)> &func)
|
void applyToTorrents(const QStringList &hashes, const std::function<void (BitTorrent::Torrent *torrent)> &func)
|
||||||
{
|
{
|
||||||
@ -601,6 +603,8 @@ void TorrentsController::pieceStatesAction()
|
|||||||
void TorrentsController::addAction()
|
void TorrentsController::addAction()
|
||||||
{
|
{
|
||||||
const QString urls = params()["urls"];
|
const QString urls = params()["urls"];
|
||||||
|
const QString cookie = params()["cookie"];
|
||||||
|
|
||||||
const bool skipChecking = parseBool(params()["skip_checking"]).value_or(false);
|
const bool skipChecking = parseBool(params()["skip_checking"]).value_or(false);
|
||||||
const bool seqDownload = parseBool(params()["sequentialDownload"]).value_or(false);
|
const bool seqDownload = parseBool(params()["sequentialDownload"]).value_or(false);
|
||||||
const bool firstLastPiece = parseBool(params()["firstLastPiecePrio"]).value_or(false);
|
const bool firstLastPiece = parseBool(params()["firstLastPiecePrio"]).value_or(false);
|
||||||
@ -608,10 +612,11 @@ void TorrentsController::addAction()
|
|||||||
const QString savepath = params()["savepath"].trimmed();
|
const QString savepath = params()["savepath"].trimmed();
|
||||||
const QString category = params()["category"];
|
const QString category = params()["category"];
|
||||||
const QSet<QString> tags = List::toSet(params()["tags"].split(',', QString::SkipEmptyParts));
|
const QSet<QString> tags = List::toSet(params()["tags"].split(',', QString::SkipEmptyParts));
|
||||||
const QString cookie = params()["cookie"];
|
|
||||||
const QString torrentName = params()["rename"].trimmed();
|
const QString torrentName = params()["rename"].trimmed();
|
||||||
const int upLimit = params()["upLimit"].toInt();
|
const int upLimit = parseInt(params()["upLimit"]).value_or(-1);
|
||||||
const int dlLimit = params()["dlLimit"].toInt();
|
const int dlLimit = parseInt(params()["dlLimit"]).value_or(-1);
|
||||||
|
const double ratioLimit = parseDouble(params()["ratioLimit"]).value_or(BitTorrent::Torrent::USE_GLOBAL_RATIO);
|
||||||
|
const int seedingTimeLimit = parseInt(params()["seedingTimeLimit"]).value_or(BitTorrent::Torrent::USE_GLOBAL_SEEDING_TIME);
|
||||||
const std::optional<bool> autoTMM = parseBool(params()["autoTMM"]);
|
const std::optional<bool> autoTMM = parseBool(params()["autoTMM"]);
|
||||||
|
|
||||||
const QString contentLayoutParam = params()["contentLayout"];
|
const QString contentLayoutParam = params()["contentLayout"];
|
||||||
@ -636,20 +641,22 @@ void TorrentsController::addAction()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BitTorrent::AddTorrentParams params;
|
BitTorrent::AddTorrentParams addTorrentParams;
|
||||||
// TODO: Check if destination actually exists
|
// TODO: Check if destination actually exists
|
||||||
params.skipChecking = skipChecking;
|
addTorrentParams.skipChecking = skipChecking;
|
||||||
params.sequential = seqDownload;
|
addTorrentParams.sequential = seqDownload;
|
||||||
params.firstLastPiecePriority = firstLastPiece;
|
addTorrentParams.firstLastPiecePriority = firstLastPiece;
|
||||||
params.addPaused = addPaused;
|
addTorrentParams.addPaused = addPaused;
|
||||||
params.contentLayout = contentLayout;
|
addTorrentParams.contentLayout = contentLayout;
|
||||||
params.savePath = savepath;
|
addTorrentParams.savePath = savepath;
|
||||||
params.category = category;
|
addTorrentParams.category = category;
|
||||||
params.tags = tags;
|
addTorrentParams.tags = tags;
|
||||||
params.name = torrentName;
|
addTorrentParams.name = torrentName;
|
||||||
params.uploadLimit = (upLimit > 0) ? upLimit : -1;
|
addTorrentParams.uploadLimit = upLimit;
|
||||||
params.downloadLimit = (dlLimit > 0) ? dlLimit : -1;
|
addTorrentParams.downloadLimit = dlLimit;
|
||||||
params.useAutoTMM = autoTMM;
|
addTorrentParams.seedingTimeLimit = seedingTimeLimit;
|
||||||
|
addTorrentParams.ratioLimit = ratioLimit;
|
||||||
|
addTorrentParams.useAutoTMM = autoTMM;
|
||||||
|
|
||||||
bool partialSuccess = false;
|
bool partialSuccess = false;
|
||||||
for (QString url : asConst(urls.split('\n')))
|
for (QString url : asConst(urls.split('\n')))
|
||||||
@ -658,7 +665,7 @@ void TorrentsController::addAction()
|
|||||||
if (!url.isEmpty())
|
if (!url.isEmpty())
|
||||||
{
|
{
|
||||||
Net::DownloadManager::instance()->setCookiesFromUrl(cookies, QUrl::fromEncoded(url.toUtf8()));
|
Net::DownloadManager::instance()->setCookiesFromUrl(cookies, QUrl::fromEncoded(url.toUtf8()));
|
||||||
partialSuccess |= BitTorrent::Session::instance()->addTorrent(url, params);
|
partialSuccess |= BitTorrent::Session::instance()->addTorrent(url, addTorrentParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,7 +678,7 @@ void TorrentsController::addAction()
|
|||||||
, tr("Error: '%1' is not a valid torrent file.").arg(it.key()));
|
, tr("Error: '%1' is not a valid torrent file.").arg(it.key()));
|
||||||
}
|
}
|
||||||
|
|
||||||
partialSuccess |= BitTorrent::Session::instance()->addTorrent(torrentInfo, params);
|
partialSuccess |= BitTorrent::Session::instance()->addTorrent(torrentInfo, addTorrentParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partialSuccess)
|
if (partialSuccess)
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
#include "base/utils/net.h"
|
#include "base/utils/net.h"
|
||||||
#include "base/utils/version.h"
|
#include "base/utils/version.h"
|
||||||
|
|
||||||
constexpr Utils::Version<int, 3, 2> API_VERSION {2, 8, 0};
|
constexpr Utils::Version<int, 3, 2> API_VERSION {2, 8, 1};
|
||||||
|
|
||||||
class APIController;
|
class APIController;
|
||||||
class WebApplication;
|
class WebApplication;
|
||||||
|
Loading…
Reference in New Issue
Block a user