This commit is contained in:
Thomas Piccirello 2025-07-05 07:01:46 +03:00 committed by GitHub
commit 3b87217b7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 7 deletions

View file

@ -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)

View file

@ -1130,6 +1130,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)
@ -1137,10 +1139,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;
@ -1151,7 +1157,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
@ -1162,8 +1168,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);
} }

View file

@ -26,9 +26,11 @@
const searchParams = new URLSearchParams(window.location.search); const searchParams = new URLSearchParams(window.location.search);
const currentUrl = searchParams.get("url"); const currentUrl = searchParams.get("url");
if (currentUrl === null) const currentTier = searchParams.get("tier");
if ((currentUrl === null) || (currentTier === null))
return; return;
document.getElementById("trackerTier").value = currentTier;
document.getElementById("trackerUrl").value = currentUrl; document.getElementById("trackerUrl").value = currentUrl;
document.getElementById("trackerUrl").focus(); document.getElementById("trackerUrl").focus();
@ -41,7 +43,8 @@
body: new URLSearchParams({ body: new URLSearchParams({
hash: searchParams.get("hash"), hash: searchParams.get("hash"),
origUrl: currentUrl, origUrl: currentUrl,
newUrl: document.getElementById("trackerUrl").value newUrl: document.getElementById("trackerUrl").value,
tier: document.getElementById("trackerTier").value
}) })
}) })
.then((response) => { .then((response) => {
@ -63,6 +66,11 @@
<input type="text" id="trackerUrl" style="width: 90%;"> <input type="text" id="trackerUrl" style="width: 90%;">
</div> </div>
<br> <br>
<label for="trackerTier">QBT_TR(Tier:)QBT_TR[CONTEXT=TrackerListWidget]</label>
<div style="text-align: center; padding-top: 10px;">
<input type="number" id="trackerTier" style="width: 90%; max-width: 100px;" min="0" max="255">
</div>
<br>
<input type="button" value="QBT_TR(Edit)QBT_TR[CONTEXT=HttpServer]" id="editTrackerButton"> <input type="button" value="QBT_TR(Edit)QBT_TR[CONTEXT=HttpServer]" id="editTrackerButton">
</div> </div>
</body> </body>

View file

@ -209,13 +209,20 @@ window.qBittorrent.PropTrackers ??= (() => {
if (current_hash.length === 0) if (current_hash.length === 0)
return; 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({ new MochaUI.Window({
id: "trackersPage", id: "trackersPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Tracker editing)QBT_TR[CONTEXT=TrackerListWidget]", title: "QBT_TR(Tracker editing)QBT_TR[CONTEXT=TrackerListWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: `edittracker.html?hash=${current_hash}&url=${trackerUrl}`, contentURL: contentURL.toString(),
scrollbars: true, scrollbars: true,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
@ -223,7 +230,7 @@ window.qBittorrent.PropTrackers ??= (() => {
paddingVertical: 0, paddingVertical: 0,
paddingHorizontal: 0, paddingHorizontal: 0,
width: 500, width: 500,
height: 150, height: 200,
onCloseComplete: () => { onCloseComplete: () => {
updateData(); updateData();
} }