Skip to content

Commit

Permalink
Support managing web seeds from WebUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Piccirello committed Aug 4, 2024
1 parent d69730b commit 75be788
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 1 deletion.
58 changes: 58 additions & 0 deletions src/webui/www/private/addwebseeds.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="${LANG}">

<head>
<meta charset="UTF-8">
<title>QBT_TR(Add web seeds)QBT_TR[CONTEXT=HttpServer]</title>
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
<script src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
<script src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
<script>
"use strict";

window.addEventListener("DOMContentLoaded", () => {
new Keyboard({
defaultEventType: "keydown",
events: {
"Escape": function(event) {
window.parent.qBittorrent.Client.closeWindows();
event.preventDefault();
},
"Esc": function(event) {
window.parent.qBittorrent.Client.closeWindows();
event.preventDefault();
}
}
}).activate();

$("urls").focus();
$("addWebseedsButton").addEvent("click", (e) => {
e.stopPropagation();
const hash = new URI().getData("hash");
new Request({
url: "api/v2/torrents/addWebseeds",
method: "post",
data: {
hash: hash,
urls: $("urls").value.split("\n").map(w => encodeURIComponent(w.trim())).filter(w => (w.length > 0)).join("|")
},
onComplete: function() {
window.parent.qBittorrent.Client.closeWindows();
}
}).send();
});
});
</script>
</head>

<body>
<div style="text-align: center;">
<br>
<label for="urls">QBT_TR(List of web seeds to add (one per line):)QBT_TR[CONTEXT=HttpServer]</label>
<textarea name="list" id="urls" rows="10" cols="1"></textarea>
<br>
<input type="button" value="QBT_TR(Add)QBT_TR[CONTEXT=HttpServer]" id="addWebseedsButton">
</div>
</body>

</html>
68 changes: 68 additions & 0 deletions src/webui/www/private/editwebseed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="${LANG}">

<head>
<meta charset="UTF-8">
<title>QBT_TR(Edit web seed)QBT_TR[CONTEXT=HttpServer]</title>
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
<script src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
<script src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
<script>
"use strict";

window.addEventListener("DOMContentLoaded", () => {
new Keyboard({
defaultEventType: "keydown",
events: {
"Enter": function(event) {
$("editWebseedButton").click();
event.preventDefault();
},
"Escape": function(event) {
window.parent.qBittorrent.Client.closeWindows();
event.preventDefault();
},
"Esc": function(event) {
window.parent.qBittorrent.Client.closeWindows();
event.preventDefault();
}
}
}).activate();

const origUrl = new URI().getData("url");
$("url").value = decodeURIComponent(origUrl);
$("url").focus();

$("editWebseedButton").addEvent("click", (e) => {
e.stopPropagation();
const hash = new URI().getData("hash");
new Request({
url: "api/v2/torrents/editWebseed",
method: "post",
data: {
hash: hash,
origUrl: origUrl,
newUrl: encodeURIComponent($("url").value.trim()),
},
onComplete: function() {
window.parent.qBittorrent.Client.closeWindows();
}
}).send();
});
});
</script>
</head>

<body>
<div style="text-align: center;">
<br>
<label for="url">QBT_TR(Web seed URL:)QBT_TR[CONTEXT=PropertiesWidget]</label>
<div style="text-align: center; padding-top: 10px;">
<input type="text" id="url" style="width: 90%;">
</div>
<br>
<input type="button" value="QBT_TR(Edit)QBT_TR[CONTEXT=HttpServer]" id="editWebseedButton">
</div>
</body>

</html>
6 changes: 6 additions & 0 deletions src/webui/www/private/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ <h1 class="applicationTitle">qBittorrent Web User Interface <span class="version
<li><a href="#copyPeer" id="CopyPeerInfo"><img src="images/edit-copy.svg" alt="QBT_TR(Copy IP:port)QBT_TR[CONTEXT=PeerListWidget]"> QBT_TR(Copy IP:port)QBT_TR[CONTEXT=PeerListWidget]</a></li>
<li class="separator"><a href="#banPeer"><img src="images/peers-remove.svg" alt="QBT_TR(Ban peer permanently)QBT_TR[CONTEXT=PeerListWidget]"> QBT_TR(Ban peer permanently)QBT_TR[CONTEXT=PeerListWidget]</a></li>
</ul>
<ul id="torrentWebseedsMenu" class="contextMenu">
<li><a href="#AddWebseeds"><img src="images/list-add.svg" alt="QBT_TR(Add web seeds...)QBT_TR[CONTEXT=HttpServer]"> QBT_TR(Add web seeds...)QBT_TR[CONTEXT=HttpServer]</a></li>
<li><a href="#RemoveWebseed"><img src="images/list-remove.svg" alt="QBT_TR(Remove web seed)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Remove web seed)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
<li class="separator"><a href="#CopyWebseedUrl" id="CopyWebseedUrl"><img src="images/edit-copy.svg" alt="QBT_TR(Copy web seed URL)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Copy web seed URL)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
<li><a href="#EditWebseed"><img src="images/edit-rename.svg" alt="QBT_TR(Edit web seed URL...)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Edit web seed URL...)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
</ul>
<ul id="torrentFilesMenu" class="contextMenu">
<li><a href="#Rename"><img src="images/edit-rename.svg" alt="QBT_TR(Rename...)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Rename...)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
<li class="separator">
Expand Down
118 changes: 117 additions & 1 deletion src/webui/www/private/scripts/prop-webseeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,123 @@ window.qBittorrent.PropWebseeds ??= (() => {
loadWebSeedsData();
};

torrentWebseedsTable.setup("torrentWebseedsTableDiv", "torrentWebseedsTableFixedHeaderDiv");
const torrentWebseedsContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
targets: "#torrentWebseedsTableDiv",
menu: "torrentWebseedsMenu",
actions: {
AddWebseeds: function(element, ref) {
addWebseedFN();
},
EditWebseed: function(element, ref) {
// only allow editing of one row
element.firstChild.click();
editWebseedFN(element);
},
RemoveWebseed: function(element, ref) {
removeWebseedFN(element);
}
},
offsets: {
x: -15,
y: 2
},
onShow: function() {
const selectedWebseeds = torrentWebseedsTable.selectedRowsIds();

if (selectedWebseeds.length === 0) {
this.hideItem("EditWebseed");
this.hideItem("RemoveWebseed");
this.hideItem("CopyWebseedUrl");
}
else {
if (selectedWebseeds.length === 1)
this.showItem("EditWebseed");
else
this.hideItem("EditWebseed");

this.showItem("RemoveWebseed");
this.showItem("CopyWebseedUrl");
}
}
});

const addWebseedFN = function() {
if (current_hash.length === 0)
return;

new MochaUI.Window({
id: "webseedsPage",
title: "QBT_TR(Add web seeds)QBT_TR[CONTEXT=HttpServer]",
loadMethod: "iframe",
contentURL: "addwebseeds.html?hash=" + current_hash,
scrollbars: true,
resizable: false,
maximizable: false,
closable: true,
paddingVertical: 0,
paddingHorizontal: 0,
width: 500,
height: 250,
onCloseComplete: function() {
updateData();
}
});
};

const editWebseedFN = function(element) {
if (current_hash.length === 0)
return;

const selectedWebseeds = torrentWebseedsTable.selectedRowsIds();
if (selectedWebseeds.length > 1)
return;

const webseedUrl = selectedWebseeds[0];

new MochaUI.Window({
id: "webseedsPage",
title: "QBT_TR(Web seed editing)QBT_TR[CONTEXT=PropertiesWidget]",
loadMethod: "iframe",
contentURL: "editwebseed.html?hash=" + current_hash + "&url=" + encodeURIComponent(webseedUrl),
scrollbars: true,
resizable: false,
maximizable: false,
closable: true,
paddingVertical: 0,
paddingHorizontal: 0,
width: 500,
height: 150,
onCloseComplete: function() {
updateData();
}
});
};

const removeWebseedFN = function(element) {
if (current_hash.length === 0)
return;

const selectedWebseeds = torrentWebseedsTable.selectedRowsIds();
new Request({
url: "api/v2/torrents/removeWebseeds",
method: "post",
data: {
hash: current_hash,
urls: selectedWebseeds.map(webseed => encodeURIComponent(webseed)).join("|")
},
onSuccess: function() {
updateData();
}
}).send();
};

new ClipboardJS("#CopyWebseedUrl", {
text: function(trigger) {
return torrentWebseedsTable.selectedRowsIds().join("\n");
}
});

torrentWebseedsTable.setup("torrentWebseedsTableDiv", "torrentWebseedsTableFixedHeaderDiv", torrentWebseedsContextMenu);

return exports();
})();
Expand Down
2 changes: 2 additions & 0 deletions src/webui/www/webui.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<qresource prefix="/www">
<file>private/addpeers.html</file>
<file>private/addtrackers.html</file>
<file>private/addwebseeds.html</file>
<file>private/confirmdeletion.html</file>
<file>private/confirmfeeddeletion.html</file>
<file>private/confirmruleclear.html</file>
Expand All @@ -18,6 +19,7 @@
<file>private/download.html</file>
<file>private/downloadlimit.html</file>
<file>private/edittracker.html</file>
<file>private/editwebseed.html</file>
<file>private/images/3-state-checkbox.gif</file>
<file>private/images/application-exit.svg</file>
<file>private/images/application-rss.svg</file>
Expand Down

0 comments on commit 75be788

Please sign in to comment.