mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 13:23:34 -07:00
WebAPI: Support setting tracker tier
This commit is contained in:
parent
4f94eac235
commit
f5743bd228
2 changed files with 19 additions and 2 deletions
|
@ -1,5 +1,10 @@
|
||||||
# WebAPI Changelog
|
# WebAPI Changelog
|
||||||
|
|
||||||
|
## 2.11.10
|
||||||
|
|
||||||
|
* [#22963](https://github.com/qbittorrent/qBittorrent/pull/22963)
|
||||||
|
* `torrents/editTracker` endpoint now supports setting a tracker's tier via `tier` parameter
|
||||||
|
|
||||||
## 2.11.9
|
## 2.11.9
|
||||||
|
|
||||||
* [#21015](https://github.com/qbittorrent/qBittorrent/pull/21015)
|
* [#21015](https://github.com/qbittorrent/qBittorrent/pull/21015)
|
||||||
|
|
|
@ -1129,6 +1129,8 @@ void TorrentsController::editTrackerAction()
|
||||||
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_s]);
|
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_s]);
|
||||||
const QString origUrl = params()[u"origUrl"_s];
|
const QString origUrl = params()[u"origUrl"_s];
|
||||||
const QString newUrl = params()[u"newUrl"_s];
|
const QString newUrl = params()[u"newUrl"_s];
|
||||||
|
// min tier is 0, so -1 indicates to keep tier unchanged
|
||||||
|
const int newTier = parseInt(params()[u"tier"_s]).value_or(-1);
|
||||||
|
|
||||||
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id);
|
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id);
|
||||||
if (!torrent)
|
if (!torrent)
|
||||||
|
@ -1136,10 +1138,14 @@ void TorrentsController::editTrackerAction()
|
||||||
|
|
||||||
const QUrl origTrackerUrl {origUrl};
|
const QUrl origTrackerUrl {origUrl};
|
||||||
const QUrl newTrackerUrl {newUrl};
|
const QUrl newTrackerUrl {newUrl};
|
||||||
if (origTrackerUrl == newTrackerUrl)
|
const bool isTrackerUrlChanged = origTrackerUrl != newTrackerUrl;
|
||||||
|
const bool isNewTierSpecified = newTier >= 0;
|
||||||
|
if (!isTrackerUrlChanged && !isNewTierSpecified)
|
||||||
return;
|
return;
|
||||||
if (!newTrackerUrl.isValid())
|
if (!newTrackerUrl.isValid())
|
||||||
throw APIError(APIErrorType::BadParams, u"New tracker URL is invalid"_s);
|
throw APIError(APIErrorType::BadParams, u"New tracker URL is invalid"_s);
|
||||||
|
if ((newTier < -1) || (newTier > 255))
|
||||||
|
throw APIError(APIErrorType::BadParams, u"New tier must be between 0 and 255"_s);
|
||||||
|
|
||||||
const QList<BitTorrent::TrackerEntryStatus> currentTrackers = torrent->trackers();
|
const QList<BitTorrent::TrackerEntryStatus> currentTrackers = torrent->trackers();
|
||||||
QList<BitTorrent::TrackerEntry> entries;
|
QList<BitTorrent::TrackerEntry> entries;
|
||||||
|
@ -1150,7 +1156,7 @@ void TorrentsController::editTrackerAction()
|
||||||
{
|
{
|
||||||
const QUrl trackerUrl {tracker.url};
|
const QUrl trackerUrl {tracker.url};
|
||||||
|
|
||||||
if (trackerUrl == newTrackerUrl)
|
if (isTrackerUrlChanged && (trackerUrl == newTrackerUrl))
|
||||||
throw APIError(APIErrorType::Conflict, u"New tracker URL already exists"_s);
|
throw APIError(APIErrorType::Conflict, u"New tracker URL already exists"_s);
|
||||||
|
|
||||||
BitTorrent::TrackerEntry entry
|
BitTorrent::TrackerEntry entry
|
||||||
|
@ -1161,8 +1167,14 @@ void TorrentsController::editTrackerAction()
|
||||||
|
|
||||||
if (trackerUrl == origTrackerUrl)
|
if (trackerUrl == origTrackerUrl)
|
||||||
{
|
{
|
||||||
|
const bool isTrackerTierChanged = tracker.tier != newTier;
|
||||||
|
if (!isTrackerUrlChanged && !isTrackerTierChanged)
|
||||||
|
return;
|
||||||
|
|
||||||
match = true;
|
match = true;
|
||||||
entry.url = newTrackerUrl.toString();
|
entry.url = newTrackerUrl.toString();
|
||||||
|
if (isNewTierSpecified)
|
||||||
|
entry.tier = newTier;
|
||||||
}
|
}
|
||||||
entries.append(entry);
|
entries.append(entry);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue