2022-10-18 22:39:32 -04:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt and libtorrent.
|
|
|
|
* Copyright (C) 2009 Christophe Dumez <chris@qbittorrent.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*/
|
|
|
|
|
2024-10-03 08:37:11 -04:00
|
|
|
"use strict";
|
2022-10-18 22:39:32 -04:00
|
|
|
|
2024-10-03 08:37:11 -04:00
|
|
|
window.qBittorrent ??= {};
|
|
|
|
window.qBittorrent.PropTrackers ??= (() => {
|
|
|
|
const exports = () => {
|
2022-10-18 22:39:32 -04:00
|
|
|
return {
|
|
|
|
updateData: updateData
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
let current_hash = "";
|
|
|
|
|
|
|
|
const torrentTrackersTable = new window.qBittorrent.DynamicTable.TorrentTrackersTable();
|
2024-10-03 08:37:11 -04:00
|
|
|
let loadTrackersDataTimer = -1;
|
2022-10-18 22:39:32 -04:00
|
|
|
|
|
|
|
const loadTrackersData = function() {
|
2024-10-03 08:37:11 -04:00
|
|
|
if ($("propTrackers").hasClass("invisible")
|
|
|
|
|| $("propertiesPanel_collapseToggle").hasClass("panel-expand")) {
|
2022-10-18 22:39:32 -04:00
|
|
|
// Tab changed, don't do anything
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const new_hash = torrentsTable.getCurrentTorrentID();
|
|
|
|
if (new_hash === "") {
|
|
|
|
torrentTrackersTable.clear();
|
|
|
|
clearTimeout(loadTrackersDataTimer);
|
|
|
|
loadTrackersDataTimer = loadTrackersData.delay(10000);
|
|
|
|
return;
|
|
|
|
}
|
2024-10-03 08:37:11 -04:00
|
|
|
if (new_hash !== current_hash) {
|
2022-10-18 22:39:32 -04:00
|
|
|
torrentTrackersTable.clear();
|
|
|
|
current_hash = new_hash;
|
|
|
|
}
|
2024-10-03 08:37:11 -04:00
|
|
|
const url = new URI("api/v2/torrents/trackers?hash=" + current_hash);
|
2022-10-18 22:39:32 -04:00
|
|
|
new Request.JSON({
|
|
|
|
url: url,
|
2024-10-03 08:37:11 -04:00
|
|
|
method: "get",
|
2022-10-18 22:39:32 -04:00
|
|
|
noCache: true,
|
|
|
|
onComplete: function() {
|
|
|
|
clearTimeout(loadTrackersDataTimer);
|
|
|
|
loadTrackersDataTimer = loadTrackersData.delay(10000);
|
|
|
|
},
|
|
|
|
onSuccess: function(trackers) {
|
|
|
|
const selectedTrackers = torrentTrackersTable.selectedRowsIds();
|
|
|
|
torrentTrackersTable.clear();
|
|
|
|
|
|
|
|
if (trackers) {
|
2024-10-03 08:37:11 -04:00
|
|
|
trackers.each((tracker) => {
|
2022-10-18 22:39:32 -04:00
|
|
|
let status;
|
|
|
|
switch (tracker.status) {
|
|
|
|
case 0:
|
2022-11-30 13:49:48 -05:00
|
|
|
status = "Disabled";
|
2022-10-18 22:39:32 -04:00
|
|
|
break;
|
|
|
|
case 1:
|
2022-11-30 13:49:48 -05:00
|
|
|
status = "Not contacted yet";
|
2022-10-18 22:39:32 -04:00
|
|
|
break;
|
|
|
|
case 2:
|
2022-11-30 13:49:48 -05:00
|
|
|
status = "Working";
|
2022-10-18 22:39:32 -04:00
|
|
|
break;
|
|
|
|
case 3:
|
2022-11-30 13:49:48 -05:00
|
|
|
status = "Updating...";
|
2022-10-18 22:39:32 -04:00
|
|
|
break;
|
|
|
|
case 4:
|
2022-11-30 13:49:48 -05:00
|
|
|
status = "Not working";
|
2022-10-18 22:39:32 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const row = {
|
|
|
|
rowId: tracker.url,
|
|
|
|
tier: (tracker.tier >= 0) ? tracker.tier : "",
|
|
|
|
url: tracker.url,
|
|
|
|
status: status,
|
2024-10-03 08:37:11 -04:00
|
|
|
peers: (tracker.num_peers >= 0) ? tracker.num_peers : "N/A",
|
2022-11-30 13:49:48 -05:00
|
|
|
seeds: (tracker.num_seeds >= 0) ? tracker.num_seeds : "N/A",
|
|
|
|
leeches: (tracker.num_leeches >= 0) ? tracker.num_leeches : "N/A",
|
|
|
|
downloaded: (tracker.num_downloaded >= 0) ? tracker.num_downloaded : "N/A",
|
2022-10-18 22:39:32 -04:00
|
|
|
message: tracker.msg
|
|
|
|
};
|
|
|
|
|
|
|
|
torrentTrackersTable.updateRowData(row);
|
|
|
|
});
|
|
|
|
|
|
|
|
torrentTrackersTable.updateTable(false);
|
|
|
|
|
|
|
|
if (selectedTrackers.length > 0)
|
|
|
|
torrentTrackersTable.reselectRows(selectedTrackers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
};
|
|
|
|
|
|
|
|
const updateData = function() {
|
|
|
|
clearTimeout(loadTrackersDataTimer);
|
2024-10-03 08:37:11 -04:00
|
|
|
loadTrackersDataTimer = -1;
|
2022-10-18 22:39:32 -04:00
|
|
|
loadTrackersData();
|
|
|
|
};
|
|
|
|
|
|
|
|
const torrentTrackersContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
|
2024-10-03 08:37:11 -04:00
|
|
|
targets: "#torrentTrackersTableDiv",
|
|
|
|
menu: "torrentTrackersMenu",
|
2022-10-18 22:39:32 -04:00
|
|
|
actions: {
|
|
|
|
AddTracker: function(element, ref) {
|
|
|
|
addTrackerFN();
|
|
|
|
},
|
|
|
|
EditTracker: function(element, ref) {
|
|
|
|
// only allow editing of one row
|
|
|
|
element.firstChild.click();
|
|
|
|
editTrackerFN(element);
|
|
|
|
},
|
|
|
|
RemoveTracker: function(element, ref) {
|
|
|
|
removeTrackerFN(element);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
offsets: {
|
|
|
|
x: -15,
|
|
|
|
y: 2
|
|
|
|
},
|
|
|
|
onShow: function() {
|
|
|
|
const selectedTrackers = torrentTrackersTable.selectedRowsIds();
|
2024-10-03 08:37:11 -04:00
|
|
|
const containsStaticTracker = selectedTrackers.some((tracker) => {
|
2022-10-18 22:39:32 -04:00
|
|
|
return (tracker.indexOf("** [") === 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (containsStaticTracker || (selectedTrackers.length === 0)) {
|
2024-10-03 08:37:11 -04:00
|
|
|
this.hideItem("EditTracker");
|
|
|
|
this.hideItem("RemoveTracker");
|
|
|
|
this.hideItem("CopyTrackerUrl");
|
2022-10-18 22:39:32 -04:00
|
|
|
}
|
|
|
|
else {
|
2024-10-03 08:37:11 -04:00
|
|
|
this.showItem("EditTracker");
|
|
|
|
this.showItem("RemoveTracker");
|
|
|
|
this.showItem("CopyTrackerUrl");
|
2022-10-18 22:39:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const addTrackerFN = function() {
|
|
|
|
if (current_hash.length === 0)
|
|
|
|
return;
|
|
|
|
new MochaUI.Window({
|
2024-10-03 08:37:11 -04:00
|
|
|
id: "trackersPage",
|
|
|
|
icon: "images/qbittorrent-tray.svg",
|
2022-11-30 13:49:48 -05:00
|
|
|
title: "Add trackers",
|
2024-10-03 08:37:11 -04:00
|
|
|
loadMethod: "iframe",
|
|
|
|
contentURL: "addtrackers.html?hash=" + current_hash,
|
2022-10-18 22:39:32 -04:00
|
|
|
scrollbars: true,
|
|
|
|
resizable: false,
|
|
|
|
maximizable: false,
|
|
|
|
closable: true,
|
|
|
|
paddingVertical: 0,
|
|
|
|
paddingHorizontal: 0,
|
|
|
|
width: 500,
|
|
|
|
height: 250,
|
|
|
|
onCloseComplete: function() {
|
|
|
|
updateData();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const editTrackerFN = function(element) {
|
|
|
|
if (current_hash.length === 0)
|
|
|
|
return;
|
|
|
|
|
2024-10-03 08:37:11 -04:00
|
|
|
const trackerUrl = encodeURIComponent(element.childNodes[1].textContent);
|
2022-10-18 22:39:32 -04:00
|
|
|
new MochaUI.Window({
|
2024-10-03 08:37:11 -04:00
|
|
|
id: "trackersPage",
|
|
|
|
icon: "images/qbittorrent-tray.svg",
|
2022-11-30 13:49:48 -05:00
|
|
|
title: "Tracker editing",
|
2024-10-03 08:37:11 -04:00
|
|
|
loadMethod: "iframe",
|
|
|
|
contentURL: "edittracker.html?hash=" + current_hash + "&url=" + trackerUrl,
|
2022-10-18 22:39:32 -04:00
|
|
|
scrollbars: true,
|
|
|
|
resizable: false,
|
|
|
|
maximizable: false,
|
|
|
|
closable: true,
|
|
|
|
paddingVertical: 0,
|
|
|
|
paddingHorizontal: 0,
|
|
|
|
width: 500,
|
|
|
|
height: 150,
|
|
|
|
onCloseComplete: function() {
|
|
|
|
updateData();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const removeTrackerFN = function(element) {
|
|
|
|
if (current_hash.length === 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const selectedTrackers = torrentTrackersTable.selectedRowsIds();
|
|
|
|
new Request({
|
2024-10-03 08:37:11 -04:00
|
|
|
url: "api/v2/torrents/removeTrackers",
|
|
|
|
method: "post",
|
2022-10-18 22:39:32 -04:00
|
|
|
data: {
|
|
|
|
hash: current_hash,
|
2024-10-03 08:37:11 -04:00
|
|
|
urls: selectedTrackers.map(encodeURIComponent).join("|")
|
2022-10-18 22:39:32 -04:00
|
|
|
},
|
|
|
|
onSuccess: function() {
|
|
|
|
updateData();
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
};
|
|
|
|
|
2024-10-03 08:37:11 -04:00
|
|
|
new ClipboardJS("#CopyTrackerUrl", {
|
2022-10-18 22:39:32 -04:00
|
|
|
text: function(trigger) {
|
|
|
|
return torrentTrackersTable.selectedRowsIds().join("\n");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-10-03 08:37:11 -04:00
|
|
|
torrentTrackersTable.setup("torrentTrackersTableDiv", "torrentTrackersTableFixedHeaderDiv", torrentTrackersContextMenu);
|
2022-10-18 22:39:32 -04:00
|
|
|
|
|
|
|
return exports();
|
|
|
|
})();
|
|
|
|
Object.freeze(window.qBittorrent.PropTrackers);
|