mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-05 11:24:15 +00:00
Include trackers in /sync/maindata API endpoint
This commit is contained in:
parent
8110912e4e
commit
84a40c1665
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "base/bittorrent/infohash.h"
|
#include "base/bittorrent/infohash.h"
|
||||||
#include "base/bittorrent/torrenthandle.h"
|
#include "base/bittorrent/torrenthandle.h"
|
||||||
|
#include "base/bittorrent/trackerentry.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -110,6 +111,7 @@ QVariantMap serialize(const BitTorrent::TorrentHandle &torrent)
|
|||||||
{KEY_TORRENT_ADDED_ON, torrent.addedTime().toSecsSinceEpoch()},
|
{KEY_TORRENT_ADDED_ON, torrent.addedTime().toSecsSinceEpoch()},
|
||||||
{KEY_TORRENT_COMPLETION_ON, torrent.completedTime().toSecsSinceEpoch()},
|
{KEY_TORRENT_COMPLETION_ON, torrent.completedTime().toSecsSinceEpoch()},
|
||||||
{KEY_TORRENT_TRACKER, torrent.currentTracker()},
|
{KEY_TORRENT_TRACKER, torrent.currentTracker()},
|
||||||
|
{KEY_TORRENT_TRACKERS_COUNT, torrent.trackers().size()},
|
||||||
{KEY_TORRENT_DL_LIMIT, torrent.downloadLimit()},
|
{KEY_TORRENT_DL_LIMIT, torrent.downloadLimit()},
|
||||||
{KEY_TORRENT_UP_LIMIT, torrent.uploadLimit()},
|
{KEY_TORRENT_UP_LIMIT, torrent.uploadLimit()},
|
||||||
{KEY_TORRENT_AMOUNT_DOWNLOADED, torrent.totalDownload()},
|
{KEY_TORRENT_AMOUNT_DOWNLOADED, torrent.totalDownload()},
|
||||||
|
@ -61,6 +61,7 @@ const char KEY_TORRENT_SAVE_PATH[] = "save_path";
|
|||||||
const char KEY_TORRENT_ADDED_ON[] = "added_on";
|
const char KEY_TORRENT_ADDED_ON[] = "added_on";
|
||||||
const char KEY_TORRENT_COMPLETION_ON[] = "completion_on";
|
const char KEY_TORRENT_COMPLETION_ON[] = "completion_on";
|
||||||
const char KEY_TORRENT_TRACKER[] = "tracker";
|
const char KEY_TORRENT_TRACKER[] = "tracker";
|
||||||
|
const char KEY_TORRENT_TRACKERS_COUNT[] = "trackers_count";
|
||||||
const char KEY_TORRENT_DL_LIMIT[] = "dl_limit";
|
const char KEY_TORRENT_DL_LIMIT[] = "dl_limit";
|
||||||
const char KEY_TORRENT_UP_LIMIT[] = "up_limit";
|
const char KEY_TORRENT_UP_LIMIT[] = "up_limit";
|
||||||
const char KEY_TORRENT_AMOUNT_DOWNLOADED[] = "downloaded";
|
const char KEY_TORRENT_AMOUNT_DOWNLOADED[] = "downloaded";
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "base/bittorrent/peerinfo.h"
|
#include "base/bittorrent/peerinfo.h"
|
||||||
#include "base/bittorrent/session.h"
|
#include "base/bittorrent/session.h"
|
||||||
#include "base/bittorrent/torrenthandle.h"
|
#include "base/bittorrent/torrenthandle.h"
|
||||||
|
#include "base/bittorrent/trackerentry.h"
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/net/geoipmanager.h"
|
#include "base/net/geoipmanager.h"
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
@ -247,6 +248,22 @@ namespace
|
|||||||
syncData[i.key()] = map;
|
syncData[i.key()] = map;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case QVariant::StringList:
|
||||||
|
if (!prevData.contains(i.key())) {
|
||||||
|
// new list item found - append it to syncData
|
||||||
|
syncData[i.key()] = i.value();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QVariantList list;
|
||||||
|
QVariantList removedList;
|
||||||
|
processList(prevData[i.key()].toList(), i.value().toList(), list, removedList);
|
||||||
|
// existing list item found - remove it from prevData
|
||||||
|
prevData.remove(i.key());
|
||||||
|
if (!list.isEmpty() || !removedList.isEmpty())
|
||||||
|
// changed list item found - append entire list to syncData
|
||||||
|
syncData[i.key()] = i.value();
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Q_ASSERT(0);
|
Q_ASSERT(0);
|
||||||
}
|
}
|
||||||
@ -354,6 +371,8 @@ SyncController::~SyncController()
|
|||||||
// - "torrents_removed": a list of hashes of removed torrents
|
// - "torrents_removed": a list of hashes of removed torrents
|
||||||
// - "categories": map of categories info
|
// - "categories": map of categories info
|
||||||
// - "categories_removed": list of removed categories
|
// - "categories_removed": list of removed categories
|
||||||
|
// - "trackers": dictionary contains information about trackers
|
||||||
|
// - "trackers_removed": a list of removed trackers
|
||||||
// - "server_state": map contains information about the state of the server
|
// - "server_state": map contains information about the state of the server
|
||||||
// The keys of the 'torrents' dictionary are hashes of torrents.
|
// The keys of the 'torrents' dictionary are hashes of torrents.
|
||||||
// Each value of the 'torrents' dictionary contains map. The map can contain following keys:
|
// Each value of the 'torrents' dictionary contains map. The map can contain following keys:
|
||||||
@ -414,6 +433,7 @@ void SyncController::maindataAction()
|
|||||||
QVariantMap lastAcceptedResponse = sessionManager()->session()->getData(QLatin1String("syncMainDataLastAcceptedResponse")).toMap();
|
QVariantMap lastAcceptedResponse = sessionManager()->session()->getData(QLatin1String("syncMainDataLastAcceptedResponse")).toMap();
|
||||||
|
|
||||||
QVariantHash torrents;
|
QVariantHash torrents;
|
||||||
|
QHash<QString, QStringList> trackers;
|
||||||
for (const BitTorrent::TorrentHandle *torrent : asConst(session->torrents())) {
|
for (const BitTorrent::TorrentHandle *torrent : asConst(session->torrents())) {
|
||||||
const BitTorrent::InfoHash torrentHash = torrent->hash();
|
const BitTorrent::InfoHash torrentHash = torrent->hash();
|
||||||
|
|
||||||
@ -439,6 +459,10 @@ void SyncController::maindataAction()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers())) {
|
||||||
|
trackers[tracker.url()] << torrentHash;
|
||||||
|
}
|
||||||
|
|
||||||
torrents[torrentHash] = map;
|
torrents[torrentHash] = map;
|
||||||
}
|
}
|
||||||
data["torrents"] = torrents;
|
data["torrents"] = torrents;
|
||||||
@ -459,6 +483,12 @@ void SyncController::maindataAction()
|
|||||||
tags << tag;
|
tags << tag;
|
||||||
data["tags"] = tags;
|
data["tags"] = tags;
|
||||||
|
|
||||||
|
QVariantHash trackersHash;
|
||||||
|
for (auto i = trackers.constBegin(); i != trackers.constEnd(); ++i) {
|
||||||
|
trackersHash[i.key()] = i.value();
|
||||||
|
}
|
||||||
|
data["trackers"] = trackersHash;
|
||||||
|
|
||||||
QVariantMap serverState = getTransferInfo();
|
QVariantMap serverState = getTransferInfo();
|
||||||
serverState[KEY_TRANSFER_FREESPACEONDISK] = getFreeDiskSpace();
|
serverState[KEY_TRANSFER_FREESPACEONDISK] = getFreeDiskSpace();
|
||||||
serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled();
|
serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user