diff --git a/src/webui/btjson.cpp b/src/webui/btjson.cpp index 73867d5ea..cd4bceede 100644 --- a/src/webui/btjson.cpp +++ b/src/webui/btjson.cpp @@ -110,6 +110,9 @@ static const char KEY_TRACKER_STATUS[] = "status"; static const char KEY_TRACKER_MSG[] = "msg"; static const char KEY_TRACKER_PEERS[] = "num_peers"; +// Web seed keys +static const char KEY_WEBSEED_URL[] = "url"; + // Torrent keys (Properties) static const char KEY_PROP_SAVE_PATH[] = "save_path"; static const char KEY_PROP_CREATION_DATE[] = "creation_date"; @@ -377,6 +380,31 @@ QByteArray btjson::getTrackersForTorrent(const QString& hash) return json::toJson(tracker_list); } +/** + * Returns the web seeds for a torrent in JSON format. + * + * The return value is a JSON-formatted list of dictionaries. + * The dictionary keys are: + * - "url": Web seed URL + */ +QByteArray btjson::getWebSeedsForTorrent(const QString& hash) +{ + CACHED_VARIABLE_FOR_HASH(QVariantList, webSeedList, CACHE_DURATION_MS, hash); + BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); + if (!torrent) { + qWarning() << Q_FUNC_INFO << "Invalid torrent " << qPrintable(hash); + return QByteArray(); + } + + foreach (const QUrl &webseed, torrent->urlSeeds()) { + QVariantMap webSeedDict; + webSeedDict[KEY_WEBSEED_URL] = webseed.toString(); + webSeedList.append(webSeedDict); + } + + return json::toJson(webSeedList); +} + /** * Returns the properties for a torrent in JSON format. * diff --git a/src/webui/btjson.h b/src/webui/btjson.h index e919c6531..246d1eb86 100644 --- a/src/webui/btjson.h +++ b/src/webui/btjson.h @@ -47,6 +47,7 @@ public: QString sortedColumn = "name", bool reverse = false, int limit = 0, int offset = 0); static QByteArray getSyncMainData(int acceptedResponseId, QVariantMap &lastData, QVariantMap &lastAcceptedData); static QByteArray getTrackersForTorrent(const QString& hash); + static QByteArray getWebSeedsForTorrent(const QString& hash); static QByteArray getPropertiesForTorrent(const QString& hash); static QByteArray getFilesForTorrent(const QString& hash); static QByteArray getTransferInfo(); diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 0748fd0ed..89c553135 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -76,6 +76,7 @@ QMap > WebApplication::initialize ADD_ACTION(query, transferInfo); ADD_ACTION(query, propertiesGeneral); ADD_ACTION(query, propertiesTrackers); + ADD_ACTION(query, propertiesWebSeeds); ADD_ACTION(query, propertiesFiles); ADD_ACTION(sync, maindata); ADD_ACTION(command, shutdown); @@ -249,6 +250,12 @@ void WebApplication::action_query_propertiesTrackers() print(btjson::getTrackersForTorrent(args_.front()), Http::CONTENT_TYPE_JS); } +void WebApplication::action_query_propertiesWebSeeds() +{ + CHECK_URI(1); + print(btjson::getWebSeedsForTorrent(args_.front()), Http::CONTENT_TYPE_JS); +} + void WebApplication::action_query_propertiesFiles() { CHECK_URI(1); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index fad03f724..e4bef1ab1 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -52,6 +52,7 @@ private: void action_query_transferInfo(); void action_query_propertiesGeneral(); void action_query_propertiesTrackers(); + void action_query_propertiesWebSeeds(); void action_query_propertiesFiles(); void action_sync_maindata(); void action_command_shutdown(); diff --git a/src/webui/webui.qrc b/src/webui/webui.qrc index db5f1c413..c77d04bdc 100644 --- a/src/webui/webui.qrc +++ b/src/webui/webui.qrc @@ -33,6 +33,7 @@ www/public/properties_content.html www/public/scripts/prop-general.js www/public/scripts/prop-trackers.js + www/public/scripts/prop-webseeds.js www/public/scripts/prop-files.js www/public/transferlist.html www/public/upload.html diff --git a/src/webui/www/public/css/style.css b/src/webui/www/public/css/style.css index 7d3f87f27..25f1fbb0c 100644 --- a/src/webui/www/public/css/style.css +++ b/src/webui/www/public/css/style.css @@ -362,7 +362,7 @@ ul.filterList li:hover a { line-height: 20px; } -#trackersTable { +#trackersTable, #webseedsTable { line-height: 25px; } diff --git a/src/webui/www/public/properties.html b/src/webui/www/public/properties.html index 2ffd2c784..a9c04ecf0 100644 --- a/src/webui/www/public/properties.html +++ b/src/webui/www/public/properties.html @@ -2,6 +2,7 @@
diff --git a/src/webui/www/public/properties_content.html b/src/webui/www/public/properties_content.html index 13c24fce6..435b000de 100644 --- a/src/webui/www/public/properties_content.html +++ b/src/webui/www/public/properties_content.html @@ -38,6 +38,19 @@ + +