From f5743bd22869121d4427dfda21e95f4187168cf9 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Fri, 4 Jul 2025 14:52:51 -0700 Subject: [PATCH 1/2] WebAPI: Support setting tracker tier --- WebAPI_Changelog.md | 5 +++++ src/webui/api/torrentscontroller.cpp | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/WebAPI_Changelog.md b/WebAPI_Changelog.md index 375e24d69..ec792d03e 100644 --- a/WebAPI_Changelog.md +++ b/WebAPI_Changelog.md @@ -1,5 +1,10 @@ # 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 * [#21015](https://github.com/qbittorrent/qBittorrent/pull/21015) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index fc2d6d4cb..f9eba339b 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -1129,6 +1129,8 @@ void TorrentsController::editTrackerAction() const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_s]); const QString origUrl = params()[u"origUrl"_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); if (!torrent) @@ -1136,10 +1138,14 @@ void TorrentsController::editTrackerAction() const QUrl origTrackerUrl {origUrl}; const QUrl newTrackerUrl {newUrl}; - if (origTrackerUrl == newTrackerUrl) + const bool isTrackerUrlChanged = origTrackerUrl != newTrackerUrl; + const bool isNewTierSpecified = newTier >= 0; + if (!isTrackerUrlChanged && !isNewTierSpecified) return; if (!newTrackerUrl.isValid()) 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 currentTrackers = torrent->trackers(); QList entries; @@ -1150,7 +1156,7 @@ void TorrentsController::editTrackerAction() { const QUrl trackerUrl {tracker.url}; - if (trackerUrl == newTrackerUrl) + if (isTrackerUrlChanged && (trackerUrl == newTrackerUrl)) throw APIError(APIErrorType::Conflict, u"New tracker URL already exists"_s); BitTorrent::TrackerEntry entry @@ -1161,8 +1167,14 @@ void TorrentsController::editTrackerAction() if (trackerUrl == origTrackerUrl) { + const bool isTrackerTierChanged = tracker.tier != newTier; + if (!isTrackerUrlChanged && !isTrackerTierChanged) + return; + match = true; entry.url = newTrackerUrl.toString(); + if (isNewTierSpecified) + entry.tier = newTier; } entries.append(entry); } From dfcb16a7fdfa455b36a78e7ed88d83efc79e533a Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Fri, 4 Jul 2025 14:55:30 -0700 Subject: [PATCH 2/2] WebUI: Support editing tracker tier --- src/webui/www/private/edittracker.html | 12 ++++++++++-- src/webui/www/private/scripts/prop-trackers.js | 13 ++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/webui/www/private/edittracker.html b/src/webui/www/private/edittracker.html index b5aff329d..184d302ff 100644 --- a/src/webui/www/private/edittracker.html +++ b/src/webui/www/private/edittracker.html @@ -26,9 +26,11 @@ const searchParams = new URLSearchParams(window.location.search); const currentUrl = searchParams.get("url"); - if (currentUrl === null) + const currentTier = searchParams.get("tier"); + if ((currentUrl === null) || (currentTier === null)) return; + document.getElementById("trackerTier").value = currentTier; document.getElementById("trackerUrl").value = currentUrl; document.getElementById("trackerUrl").focus(); @@ -41,7 +43,8 @@ body: new URLSearchParams({ hash: searchParams.get("hash"), origUrl: currentUrl, - newUrl: document.getElementById("trackerUrl").value + newUrl: document.getElementById("trackerUrl").value, + tier: document.getElementById("trackerTier").value }) }) .then((response) => { @@ -63,6 +66,11 @@
+ +
+ +
+
diff --git a/src/webui/www/private/scripts/prop-trackers.js b/src/webui/www/private/scripts/prop-trackers.js index 945688aef..280e3c5b0 100644 --- a/src/webui/www/private/scripts/prop-trackers.js +++ b/src/webui/www/private/scripts/prop-trackers.js @@ -209,13 +209,20 @@ window.qBittorrent.PropTrackers ??= (() => { if (current_hash.length === 0) return; - const trackerUrl = encodeURIComponent(torrentTrackersTable.selectedRowsIds()[0]); + const tracker = torrentTrackersTable.getRow(torrentTrackersTable.getSelectedRowId()); + const contentURL = new URL("edittracker.html", window.location); + contentURL.search = new URLSearchParams({ + hash: current_hash, + url: tracker.full_data.url, + tier: tracker.full_data.tier + }); + new MochaUI.Window({ id: "trackersPage", icon: "images/qbittorrent-tray.svg", title: "QBT_TR(Tracker editing)QBT_TR[CONTEXT=TrackerListWidget]", loadMethod: "iframe", - contentURL: `edittracker.html?hash=${current_hash}&url=${trackerUrl}`, + contentURL: contentURL.toString(), scrollbars: true, resizable: false, maximizable: false, @@ -223,7 +230,7 @@ window.qBittorrent.PropTrackers ??= (() => { paddingVertical: 0, paddingHorizontal: 0, width: 500, - height: 150, + height: 200, onCloseComplete: () => { updateData(); }