WebUI: Add ability to add/remove tracker from selected torrents
Some checks failed
CI - File health / Check (push) Has been cancelled
CI - macOS / Build (push) Has been cancelled
CI - Python / Check (push) Has been cancelled
CI - Ubuntu / Build (push) Has been cancelled
CI - WebUI / Check (push) Has been cancelled
CI - Windows / Build (push) Has been cancelled

Closes #22618.
PR #22698.
This commit is contained in:
Bark 2025-06-28 09:06:03 +03:00 committed by GitHub
parent e447baa04a
commit 690a139538
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 32 deletions

View file

@ -8,6 +8,10 @@
* Add `torrents/saveMetadata` endpoint for saving retrieved torrent metadata to a .torrent file * Add `torrents/saveMetadata` endpoint for saving retrieved torrent metadata to a .torrent file
* `torrents/add` allows adding a torrent with metadata previously retrieved via `torrents/fetchMetadata` or `torrents/parseMetadata` * `torrents/add` allows adding a torrent with metadata previously retrieved via `torrents/fetchMetadata` or `torrents/parseMetadata`
* `torrents/add` allows specifying a torrent's file priorities * `torrents/add` allows specifying a torrent's file priorities
* [#22698](https://github.com/qbittorrent/qBittorrent/pull/22698)
* `torrents/addTrackers` and `torrents/removeTrackers` now accept `hash=all` and adds/removes the tracker to/from *all* torrents
* For compatibility, `torrents/removeTrackers` still accepts `hash=*` internally we transform it into `all`
* Allow passing a pipe (`|`) separated list of hashes in `hash` for `torrents/addTrackers` and `torrents/removeTrackers`
## 2.11.8 ## 2.11.8

View file

@ -1116,16 +1116,10 @@ void TorrentsController::addAction()
void TorrentsController::addTrackersAction() void TorrentsController::addTrackersAction()
{ {
requireParams({u"hash"_s, u"urls"_s}); requireParams({u"hash"_s, u"urls"_s});
const QList<BitTorrent::TrackerEntry> trackers = BitTorrent::parseTrackerEntries(params()[u"urls"_s]);
const QStringList idStrings = params()[u"hash"_s].split(u'|');
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_s]); applyToTorrents(idStrings, [&trackers](BitTorrent::Torrent *const torrent) { torrent->addTrackers(trackers); });
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
const QList<BitTorrent::TrackerEntry> entries = BitTorrent::parseTrackerEntries(params()[u"urls"_s]);
torrent->addTrackers(entries);
setResult(QString());
} }
void TorrentsController::editTrackerAction() void TorrentsController::editTrackerAction()
@ -1187,7 +1181,10 @@ void TorrentsController::removeTrackersAction()
{ {
requireParams({u"hash"_s, u"urls"_s}); requireParams({u"hash"_s, u"urls"_s});
const QString hashParam = params()[u"hash"_s]; QString hash = params()[u"hash"_s];
if (hash == u"*"_s)
hash = u"all"_s;
const QStringList idStrings = hash.split(u'|', Qt::SkipEmptyParts);
const QStringList urlsParam = params()[u"urls"_s].split(u'|', Qt::SkipEmptyParts); const QStringList urlsParam = params()[u"urls"_s].split(u'|', Qt::SkipEmptyParts);
QStringList urls; QStringList urls;
@ -1195,28 +1192,7 @@ void TorrentsController::removeTrackersAction()
for (const QString &urlStr : urlsParam) for (const QString &urlStr : urlsParam)
urls << QUrl::fromPercentEncoding(urlStr.toLatin1()); urls << QUrl::fromPercentEncoding(urlStr.toLatin1());
QList<BitTorrent::Torrent *> torrents; applyToTorrents(idStrings, [&urls](BitTorrent::Torrent *const torrent) { torrent->removeTrackers(urls); });
if (hashParam == u"*"_s)
{
// remove trackers from all torrents
torrents = BitTorrent::Session::instance()->torrents();
}
else
{
// remove trackers from specified torrent
const auto id = BitTorrent::TorrentID::fromString(hashParam);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
torrents.append(torrent);
}
for (BitTorrent::Torrent *const torrent : asConst(torrents))
torrent->removeTrackers(urls);
setResult(QString());
} }
void TorrentsController::addPeersAction() void TorrentsController::addPeersAction()

View file

@ -180,6 +180,11 @@ window.qBittorrent.PropTrackers ??= (() => {
const addTrackerFN = () => { const addTrackerFN = () => {
if (current_hash.length === 0) if (current_hash.length === 0)
return; return;
const selectedTorrents = torrentsTable.selectedRowsIds();
if (selectedTorrents.length !== 0)
current_hash = selectedTorrents.map(encodeURIComponent).join("|");
new MochaUI.Window({ new MochaUI.Window({
id: "trackersPage", id: "trackersPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
@ -229,6 +234,10 @@ window.qBittorrent.PropTrackers ??= (() => {
if (current_hash.length === 0) if (current_hash.length === 0)
return; return;
const selectedTorrents = torrentsTable.selectedRowsIds();
if (selectedTorrents.length !== 0)
current_hash = selectedTorrents.map(encodeURIComponent).join("|");
fetch("api/v2/torrents/removeTrackers", { fetch("api/v2/torrents/removeTrackers", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({