mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-13 18:17:08 -07:00
Add ability to add and ban a peer from the Web UI
This commit is contained in:
parent
f121e67aba
commit
0fa28f233f
8 changed files with 197 additions and 1 deletions
|
@ -40,6 +40,7 @@
|
|||
#include <QUrl>
|
||||
|
||||
#include "base/bittorrent/downloadpriority.h"
|
||||
#include "base/bittorrent/peeraddress.h"
|
||||
#include "base/bittorrent/peerinfo.h"
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/bittorrent/torrenthandle.h"
|
||||
|
@ -682,6 +683,42 @@ void TorrentsController::removeTrackersAction()
|
|||
torrent->forceReannounce();
|
||||
}
|
||||
|
||||
void TorrentsController::addPeersAction()
|
||||
{
|
||||
checkParams({"hashes", "peers"});
|
||||
|
||||
const QStringList hashes = params()["hashes"].split('|');
|
||||
const QStringList peers = params()["peers"].split('|');
|
||||
|
||||
QVector<BitTorrent::PeerAddress> peerList;
|
||||
peerList.reserve(peers.size());
|
||||
for (const QString &peer : peers) {
|
||||
const BitTorrent::PeerAddress addr = BitTorrent::PeerAddress::parse(peer.trimmed());
|
||||
if (!addr.ip.isNull())
|
||||
peerList.append(addr);
|
||||
}
|
||||
|
||||
if (peerList.isEmpty())
|
||||
throw APIError(APIErrorType::BadParams, "No valid peers were specified");
|
||||
|
||||
QJsonObject results;
|
||||
|
||||
applyToTorrents(hashes, [peers, peerList, &results](BitTorrent::TorrentHandle *const torrent)
|
||||
{
|
||||
const int peersAdded = std::count_if(peerList.cbegin(), peerList.cend(), [torrent](const BitTorrent::PeerAddress &peer)
|
||||
{
|
||||
return torrent->connectPeer(peer);
|
||||
});
|
||||
|
||||
results[torrent->hash()] = QJsonObject {
|
||||
{"added", peersAdded},
|
||||
{"failed", (peers.size() - peersAdded)}
|
||||
};
|
||||
});
|
||||
|
||||
setResult(results);
|
||||
}
|
||||
|
||||
void TorrentsController::pauseAction()
|
||||
{
|
||||
checkParams({"hashes"});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue