Browse Source

Merge pull request #8782 from mj-p/filterByHashes

Filter torrent info endpoint by hashes
adaptive-webui-19844
Vladimir Golovnev 7 years ago committed by GitHub
parent
commit
8906c47798
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/webui/api/torrentscontroller.cpp

4
src/webui/api/torrentscontroller.cpp

@ -150,6 +150,7 @@ namespace
// GET params: // GET params:
// - filter (string): all, downloading, seeding, completed, paused, resumed, active, inactive // - filter (string): all, downloading, seeding, completed, paused, resumed, active, inactive
// - category (string): torrent category for filtering by it (empty string means "uncategorized"; no "category" param presented means "any category") // - category (string): torrent category for filtering by it (empty string means "uncategorized"; no "category" param presented means "any category")
// - hashes (string): filter by hashes, can contain multiple hashes separated by |
// - sort (string): name of column for sorting by its value // - sort (string): name of column for sorting by its value
// - reverse (bool): enable reverse sorting // - reverse (bool): enable reverse sorting
// - limit (int): set limit number of torrents returned (if greater than 0, otherwise - unlimited) // - limit (int): set limit number of torrents returned (if greater than 0, otherwise - unlimited)
@ -162,9 +163,10 @@ void TorrentsController::infoAction()
const bool reverse {parseBool(params()["reverse"], false)}; const bool reverse {parseBool(params()["reverse"], false)};
int limit {params()["limit"].toInt()}; int limit {params()["limit"].toInt()};
int offset {params()["offset"].toInt()}; int offset {params()["offset"].toInt()};
const QStringSet hashSet {params()["hashes"].split('|', QString::SkipEmptyParts).toSet()};
QVariantList torrentList; QVariantList torrentList;
TorrentFilter torrentFilter(filter, TorrentFilter::AnyHash, category); TorrentFilter torrentFilter(filter, (hashSet.isEmpty() ? TorrentFilter::AnyHash : hashSet), category);
foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents()) { foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents()) {
if (torrentFilter.match(torrent)) if (torrentFilter.match(torrent))
torrentList.append(serialize(*torrent)); torrentList.append(serialize(*torrent));

Loading…
Cancel
Save