mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 05:43:32 -07:00
WebUI: Support using separate download path
Signed-off-by: Thomas Piccirello <thomas@piccirello.com>
This commit is contained in:
parent
bd674f0328
commit
789f92ff84
2 changed files with 104 additions and 43 deletions
|
@ -140,7 +140,7 @@
|
||||||
<label for="autoTMM">QBT_TR(Torrent Management Mode:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
|
<label for="autoTMM">QBT_TR(Torrent Management Mode:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
|
||||||
</td>
|
</td>
|
||||||
<td class="fullWidth">
|
<td class="fullWidth">
|
||||||
<select id="autoTMM" name="autoTMM" onchange="qBittorrent.AddTorrent.changeTMM(this)">
|
<select id="autoTMM" name="autoTMM" onchange="qBittorrent.AddTorrent.changeTMM()">
|
||||||
<option selected value="false">QBT_TR(Manual)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
|
<option selected value="false">QBT_TR(Manual)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
|
||||||
<option value="true">QBT_TR(Automatic)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
|
<option value="true">QBT_TR(Automatic)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
|
||||||
</select>
|
</select>
|
||||||
|
@ -156,6 +156,17 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<fieldset class="settings">
|
||||||
|
<legend>
|
||||||
|
<input type="checkbox" id="useDownloadPath">
|
||||||
|
<input type="hidden" id="useDownloadPathHidden" name="useDownloadPath">
|
||||||
|
<label for="useDownloadPath">QBT_TR(Use another path for incomplete torrent)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
|
||||||
|
</legend>
|
||||||
|
<div class="formRow" style="display: flex; align-items: center;">
|
||||||
|
<label for="downloadPath">QBT_TR(Save path:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
|
||||||
|
<input type="text" id="downloadPath" name="downloadPath" class="pathDirectory" disabled style="flex-grow: 1; margin-left: 5px; margin-right: 5px;">
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset class="settings" style="text-align: left;">
|
<fieldset class="settings" style="text-align: left;">
|
||||||
<legend>QBT_TR(Torrent settings)QBT_TR[CONTEXT=AddNewTorrentDialog]</legend>
|
<legend>QBT_TR(Torrent settings)QBT_TR[CONTEXT=AddNewTorrentDialog]</legend>
|
||||||
|
|
|
@ -37,51 +37,39 @@ window.qBittorrent.AddTorrent ??= (() => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
let categories = {};
|
|
||||||
let defaultSavePath = "";
|
let defaultSavePath = "";
|
||||||
|
let defaultTempPath = "";
|
||||||
|
let defaultTempPathEnabled = false;
|
||||||
let windowId = "";
|
let windowId = "";
|
||||||
let source = "";
|
let source = "";
|
||||||
|
|
||||||
const getCategories = () => {
|
const getCategories = () => {
|
||||||
fetch("api/v2/torrents/categories", {
|
for (const name of window.parent.qBittorrent.Client.categoryMap.keys()) {
|
||||||
method: "GET",
|
|
||||||
cache: "no-store"
|
|
||||||
})
|
|
||||||
.then(async (response) => {
|
|
||||||
if (!response.ok)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
categories = data;
|
|
||||||
for (const i in data) {
|
|
||||||
if (!Object.hasOwn(data, i))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const category = data[i];
|
|
||||||
const option = document.createElement("option");
|
const option = document.createElement("option");
|
||||||
option.value = category.name;
|
option.value = name;
|
||||||
option.textContent = category.name;
|
option.textContent = name;
|
||||||
document.getElementById("categorySelect").appendChild(option);
|
document.getElementById("categorySelect").appendChild(option);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getPreferences = () => {
|
const getPreferences = () => {
|
||||||
const pref = window.parent.qBittorrent.Cache.preferences.get();
|
const pref = window.parent.qBittorrent.Cache.preferences.get();
|
||||||
|
|
||||||
defaultSavePath = pref.save_path;
|
defaultSavePath = pref.save_path;
|
||||||
document.getElementById("savepath").value = defaultSavePath;
|
defaultTempPath = pref.temp_path;
|
||||||
|
defaultTempPathEnabled = pref.temp_path_enabled;
|
||||||
document.getElementById("startTorrent").checked = !pref.add_stopped_enabled;
|
document.getElementById("startTorrent").checked = !pref.add_stopped_enabled;
|
||||||
document.getElementById("addToTopOfQueue").checked = pref.add_to_top_of_queue;
|
document.getElementById("addToTopOfQueue").checked = pref.add_to_top_of_queue;
|
||||||
|
|
||||||
|
const autoTMM = document.getElementById("autoTMM");
|
||||||
if (pref.auto_tmm_enabled) {
|
if (pref.auto_tmm_enabled) {
|
||||||
document.getElementById("autoTMM").selectedIndex = 1;
|
autoTMM.selectedIndex = 1;
|
||||||
document.getElementById("savepath").disabled = true;
|
document.getElementById("savepath").disabled = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
document.getElementById("autoTMM").selectedIndex = 0;
|
autoTMM.selectedIndex = 0;
|
||||||
}
|
}
|
||||||
|
changeTMM();
|
||||||
|
|
||||||
if (pref.torrent_stop_condition === "MetadataReceived")
|
if (pref.torrent_stop_condition === "MetadataReceived")
|
||||||
document.getElementById("stopCondition").selectedIndex = 1;
|
document.getElementById("stopCondition").selectedIndex = 1;
|
||||||
|
@ -98,43 +86,97 @@ window.qBittorrent.AddTorrent ??= (() => {
|
||||||
document.getElementById("contentLayout").selectedIndex = 0;
|
document.getElementById("contentLayout").selectedIndex = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const categorySavePath = (categoryName) => {
|
||||||
|
const category = window.parent.qBittorrent.Client.categoryMap.get(categoryName);
|
||||||
|
return (category === undefined) ? defaultSavePath : (category.savePath || `${defaultSavePath}/${categoryName}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const categoryDownloadPath = (categoryName) => {
|
||||||
|
const category = window.parent.qBittorrent.Client.categoryMap.get(categoryName);
|
||||||
|
if (category === undefined)
|
||||||
|
return defaultTempPath;
|
||||||
|
if (category.downloadPath === false)
|
||||||
|
return "";
|
||||||
|
return category.downloadPath || `${defaultTempPath}/${categoryName}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const categoryDownloadPathEnabled = (categoryName) => {
|
||||||
|
const category = window.parent.qBittorrent.Client.categoryMap.get(categoryName);
|
||||||
|
if ((category === undefined) || (category.downloadPath === null))
|
||||||
|
return defaultTempPathEnabled;
|
||||||
|
return category.downloadPath !== false;
|
||||||
|
};
|
||||||
|
|
||||||
const changeCategorySelect = (item) => {
|
const changeCategorySelect = (item) => {
|
||||||
if (item.value === "\\other") {
|
const categoryName = item.value;
|
||||||
|
if (categoryName === "\\other") {
|
||||||
item.nextElementSibling.hidden = false;
|
item.nextElementSibling.hidden = false;
|
||||||
item.nextElementSibling.value = "";
|
item.nextElementSibling.value = "";
|
||||||
item.nextElementSibling.select();
|
item.nextElementSibling.select();
|
||||||
|
|
||||||
if (document.getElementById("autoTMM").selectedIndex === 1)
|
if (isAutoTMMEnabled()) {
|
||||||
document.getElementById("savepath").value = defaultSavePath;
|
document.getElementById("savepath").value = defaultSavePath;
|
||||||
|
|
||||||
|
const downloadPathEnabled = categoryDownloadPathEnabled(categoryName);
|
||||||
|
document.getElementById("useDownloadPath").checked = downloadPathEnabled;
|
||||||
|
changeUseDownloadPath(downloadPathEnabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
item.nextElementSibling.hidden = true;
|
item.nextElementSibling.hidden = true;
|
||||||
const text = item.options[item.selectedIndex].textContent;
|
const text = item.options[item.selectedIndex].textContent;
|
||||||
item.nextElementSibling.value = text;
|
item.nextElementSibling.value = text;
|
||||||
|
|
||||||
if (document.getElementById("autoTMM").selectedIndex === 1) {
|
if (isAutoTMMEnabled()) {
|
||||||
const categoryName = item.value;
|
document.getElementById("savepath").value = categorySavePath(categoryName);
|
||||||
const category = categories[categoryName];
|
|
||||||
let savePath = defaultSavePath;
|
const downloadPathEnabled = categoryDownloadPathEnabled(categoryName);
|
||||||
if (category !== undefined)
|
document.getElementById("useDownloadPath").checked = downloadPathEnabled;
|
||||||
savePath = (category["savePath"] !== "") ? category["savePath"] : `${defaultSavePath}/${categoryName}`;
|
changeUseDownloadPath(downloadPathEnabled);
|
||||||
document.getElementById("savepath").value = savePath;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeTMM = (item) => {
|
const isAutoTMMEnabled = () => {
|
||||||
if (item.selectedIndex === 1) {
|
return document.getElementById("autoTMM").selectedIndex === 1;
|
||||||
document.getElementById("savepath").disabled = true;
|
};
|
||||||
|
|
||||||
|
const changeTMM = () => {
|
||||||
|
const autoTMMEnabled = isAutoTMMEnabled();
|
||||||
|
const savepath = document.getElementById("savepath");
|
||||||
|
const useDownloadPath = document.getElementById("useDownloadPath");
|
||||||
|
|
||||||
|
if (autoTMMEnabled) {
|
||||||
const categorySelect = document.getElementById("categorySelect");
|
const categorySelect = document.getElementById("categorySelect");
|
||||||
const categoryName = categorySelect.options[categorySelect.selectedIndex].value;
|
const categoryName = categorySelect.options[categorySelect.selectedIndex].value;
|
||||||
const category = categories[categoryName];
|
savepath.value = categorySavePath(categoryName);
|
||||||
document.getElementById("savepath").value = (category === undefined) ? "" : category["savePath"];
|
useDownloadPath.checked = categoryDownloadPathEnabled(categoryName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
document.getElementById("savepath").disabled = false;
|
savepath.value = defaultSavePath;
|
||||||
document.getElementById("savepath").value = defaultSavePath;
|
useDownloadPath.checked = defaultTempPathEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
savepath.disabled = autoTMMEnabled;
|
||||||
|
useDownloadPath.disabled = autoTMMEnabled;
|
||||||
|
|
||||||
|
// only submit this value when using manual tmm
|
||||||
|
document.getElementById("useDownloadPathHidden").disabled = autoTMMEnabled;
|
||||||
|
|
||||||
|
changeUseDownloadPath(useDownloadPath.checked);
|
||||||
|
};
|
||||||
|
|
||||||
|
const changeUseDownloadPath = (enabled) => {
|
||||||
|
const downloadPath = document.getElementById("downloadPath");
|
||||||
|
if (isAutoTMMEnabled()) {
|
||||||
|
const categorySelect = document.getElementById("categorySelect");
|
||||||
|
const categoryName = categorySelect.options[categorySelect.selectedIndex].value;
|
||||||
|
downloadPath.value = enabled ? categoryDownloadPath(categoryName) : "";
|
||||||
|
downloadPath.disabled = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
downloadPath.value = enabled ? defaultTempPath : "";
|
||||||
|
downloadPath.disabled = !enabled;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -227,7 +269,11 @@ window.qBittorrent.AddTorrent ??= (() => {
|
||||||
.sort((el1, el2) => Number(el1.dataset.fileId) - Number(el2.dataset.fileId))
|
.sort((el1, el2) => Number(el1.dataset.fileId) - Number(el2.dataset.fileId))
|
||||||
.map((el) => Number(el.value));
|
.map((el) => Number(el.value));
|
||||||
|
|
||||||
|
if (!isAutoTMMEnabled())
|
||||||
|
document.getElementById("useDownloadPathHidden").value = document.getElementById("useDownloadPath").checked;
|
||||||
|
|
||||||
document.getElementById("loadingSpinner").style.display = "block";
|
document.getElementById("loadingSpinner").style.display = "block";
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("load", async (event) => {
|
window.addEventListener("load", async (event) => {
|
||||||
|
@ -239,6 +285,10 @@ window.qBittorrent.AddTorrent ??= (() => {
|
||||||
getCategories();
|
getCategories();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener("DOMContentLoaded", (event) => {
|
||||||
|
document.getElementById("useDownloadPath").addEventListener("change", (e) => changeUseDownloadPath(e.target.checked));
|
||||||
|
});
|
||||||
|
|
||||||
return exports();
|
return exports();
|
||||||
})();
|
})();
|
||||||
Object.freeze(window.qBittorrent.AddTorrent);
|
Object.freeze(window.qBittorrent.AddTorrent);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue