WebUI/WebAPI: Support downloading torrent via search plugin

This adds support for downloading a torrent via a search plugin's `download_torrent` function. This primarily affects torrents that use a private tracker requiring a login.

Closes #18334.
PR #23163.
This commit is contained in:
Thomas (Tom) Piccirello
2025-09-05 05:24:15 -07:00
committed by GitHub
parent becfd19e34
commit 4fa433a728
8 changed files with 125 additions and 35 deletions

View File

@@ -49,6 +49,13 @@
const windowId = searchParams.get("windowId");
window.qBittorrent.AddTorrent.setWindowId(windowId);
const downloader = searchParams.get("downloader");
if (downloader?.length > 0) {
const downloaderInput = document.getElementById("downloader");
downloaderInput.value = downloader;
downloaderInput.disabled = false;
}
document.getElementById("uploadForm").addEventListener("submit", (event) => {
submitted = true;
window.qBittorrent.AddTorrent.submitForm();
@@ -81,7 +88,7 @@
window.qBittorrent.TorrentContent.init("addTorrentFilesTableDiv", window.qBittorrent.DynamicTable.AddTorrentFilesTable);
if (fetchMetadata)
window.qBittorrent.AddTorrent.loadMetadata(source);
window.qBittorrent.AddTorrent.loadMetadata(source, downloader);
});
</script>
@@ -144,6 +151,7 @@
<form action="api/v2/torrents/add" enctype="multipart/form-data" method="post" id="uploadForm" style="text-align: center; padding: 10px 12px;" target="upload_frame" autocorrect="off" autocapitalize="none">
<input type="hidden" id="urls" name="urls">
<input type="hidden" id="filePriorities" name="filePriorities">
<input type="hidden" id="downloader" name="downloader" disabled>
<div class="container">
<div class="column">
<fieldset class="settings" style="text-align: left;">

View File

@@ -42,6 +42,7 @@ window.qBittorrent.AddTorrent ??= (() => {
let defaultTempPathEnabled = false;
let windowId = "";
let source = "";
let downloader = "";
const localPreferences = new window.qBittorrent.LocalPreferences.LocalPreferences();
@@ -214,14 +215,17 @@ window.qBittorrent.AddTorrent ??= (() => {
};
let loadMetadataTimer = -1;
const loadMetadata = (sourceUrl = undefined) => {
const loadMetadata = (sourceUrl = undefined, downloaderName = undefined) => {
if (sourceUrl !== undefined)
source = sourceUrl;
if (downloaderName !== undefined)
downloader = downloaderName;
fetch("api/v2/torrents/fetchMetadata", {
method: "POST",
body: new URLSearchParams({
source: source
source: source,
downloader: downloader
})
})
.then(async (response) => {

View File

@@ -130,7 +130,7 @@ window.qBittorrent.Client ??= (() => {
return showingLogViewer;
};
const createAddTorrentWindow = (title, source, metadata = undefined) => {
const createAddTorrentWindow = (title, source, metadata = undefined, downloader = undefined) => {
const isFirefox = navigator.userAgent.includes("Firefox");
const isSafari = navigator.userAgent.includes("AppleWebKit") && !navigator.userAgent.includes("Chrome");
let height = 855;
@@ -147,7 +147,8 @@ window.qBittorrent.Client ??= (() => {
v: "${CACHEID}",
source: source,
fetch: metadata === undefined,
windowId: id
windowId: id,
downloader: downloader ?? ""
});
new MochaUI.Window({

View File

@@ -561,8 +561,8 @@ window.qBittorrent.Search ??= (() => {
const downloadSearchTorrent = () => {
for (const rowID of searchResultsTable.selectedRowsIds()) {
const { fileName, fileUrl } = searchResultsTable.getRow(rowID).full_data;
qBittorrent.Client.createAddTorrentWindow(fileName, fileUrl);
const { engineName, fileName, fileUrl } = searchResultsTable.getRow(rowID).full_data;
qBittorrent.Client.createAddTorrentWindow(fileName, fileUrl, undefined, engineName);
}
};