mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 13:23:34 -07:00
WebUI: Support managing category download path
This commit is contained in:
parent
c481c6c732
commit
d2155c716a
3 changed files with 113 additions and 21 deletions
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>QBT_TR(New Category)QBT_TR[CONTEXT=TransferListWidget]</title>
|
<title>QBT_TR(New Category)QBT_TR[CONTEXT=Category]</title>
|
||||||
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
|
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
|
||||||
<script defer src="scripts/localpreferences.js?v=${CACHEID}"></script>
|
<script defer src="scripts/localpreferences.js?v=${CACHEID}"></script>
|
||||||
<script defer src="scripts/color-scheme.js?v=${CACHEID}"></script>
|
<script defer src="scripts/color-scheme.js?v=${CACHEID}"></script>
|
||||||
|
@ -26,27 +26,78 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const defaultDownloadPath = () => {
|
||||||
|
const category = document.getElementById("categoryName").value.trim();
|
||||||
|
return `${pref.temp_path}/${category}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const setDownloadPath = (option) => {
|
||||||
|
const downloadPath = document.getElementById("downloadPath");
|
||||||
|
const defaultPath = defaultDownloadPath();
|
||||||
|
switch (option) {
|
||||||
|
case "default":
|
||||||
|
downloadPath.disabled = true;
|
||||||
|
downloadPath.value = pref.temp_path_enabled ? defaultPath : "";
|
||||||
|
downloadPath.placeholder = "";
|
||||||
|
break;
|
||||||
|
case "yes":
|
||||||
|
downloadPath.disabled = false;
|
||||||
|
if ((categoryData !== undefined) && (categoryData.downloadPath !== false) && (categoryData.downloadPath !== null))
|
||||||
|
downloadPath.value = categoryData.downloadPath;
|
||||||
|
else
|
||||||
|
downloadPath.value = "";
|
||||||
|
downloadPath.placeholder = defaultPath;
|
||||||
|
break;
|
||||||
|
case "no":
|
||||||
|
downloadPath.disabled = true;
|
||||||
|
downloadPath.value = "";
|
||||||
|
downloadPath.placeholder = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(window.location.search);
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
const uriAction = window.qBittorrent.Misc.safeTrim(searchParams.get("action"));
|
const uriAction = window.qBittorrent.Misc.safeTrim(searchParams.get("action"));
|
||||||
const uriHashes = window.qBittorrent.Misc.safeTrim(searchParams.get("hashes"));
|
const uriHashes = window.qBittorrent.Misc.safeTrim(searchParams.get("hashes"));
|
||||||
const uriCategoryName = window.qBittorrent.Misc.safeTrim(searchParams.get("categoryName"));
|
const uriCategoryName = window.qBittorrent.Misc.safeTrim(searchParams.get("categoryName"));
|
||||||
const uriSavePath = window.qBittorrent.Misc.safeTrim(searchParams.get("savePath"));
|
|
||||||
|
|
||||||
|
const pref = window.parent.qBittorrent.Cache.preferences.get();
|
||||||
|
const categoryData = window.parent.qBittorrent.Client.categoryMap.get(uriCategoryName);
|
||||||
|
|
||||||
|
const useDownloadPathElem = document.getElementById("useDownloadPath");
|
||||||
|
const categoryNameElem = document.getElementById("categoryName");
|
||||||
|
const savePathElem = document.getElementById("savePath");
|
||||||
if (uriAction === "edit") {
|
if (uriAction === "edit") {
|
||||||
if (!uriCategoryName)
|
if (!uriCategoryName)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
document.getElementById("categoryName").disabled = true;
|
categoryNameElem.disabled = true;
|
||||||
document.getElementById("categoryName").value = window.qBittorrent.Misc.escapeHtml(uriCategoryName);
|
categoryNameElem.value = uriCategoryName;
|
||||||
document.getElementById("savePath").value = window.qBittorrent.Misc.escapeHtml(uriSavePath);
|
savePathElem.value = categoryData.savePath;
|
||||||
document.getElementById("savePath").focus();
|
savePathElem.placeholder = `${pref.save_path}/${uriCategoryName}`;
|
||||||
|
savePathElem.focus();
|
||||||
|
|
||||||
|
switch (categoryData.downloadPath) {
|
||||||
|
case false:
|
||||||
|
useDownloadPathElem.selectedIndex = 2;
|
||||||
|
setDownloadPath("no");
|
||||||
|
break;
|
||||||
|
case null:
|
||||||
|
useDownloadPathElem.selectedIndex = 0;
|
||||||
|
setDownloadPath("default");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
useDownloadPathElem.selectedIndex = 1;
|
||||||
|
setDownloadPath("yes");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (uriAction === "createSubcategory") {
|
else if (uriAction === "createSubcategory") {
|
||||||
document.getElementById("categoryName").value = window.qBittorrent.Misc.escapeHtml(uriCategoryName);
|
categoryNameElem.value = uriCategoryName;
|
||||||
document.getElementById("categoryName").focus();
|
categoryNameElem.focus();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
document.getElementById("categoryName").focus();
|
categoryNameElem.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("categoryNameButton").addEventListener("click", (e) => {
|
document.getElementById("categoryNameButton").addEventListener("click", (e) => {
|
||||||
|
@ -66,6 +117,16 @@
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const dlPathParams = {};
|
||||||
|
const useDownloadPath = document.getElementById("useDownloadPath");
|
||||||
|
if (useDownloadPath.value === "no") {
|
||||||
|
dlPathParams.downloadPathEnabled = false;
|
||||||
|
}
|
||||||
|
else if (useDownloadPath.value === "yes") {
|
||||||
|
dlPathParams.downloadPathEnabled = true;
|
||||||
|
dlPathParams.downloadPath = document.getElementById("downloadPath").value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
switch (uriAction) {
|
switch (uriAction) {
|
||||||
case "set":
|
case "set":
|
||||||
if ((uriHashes === "") || !verifyCategoryName(categoryName))
|
if ((uriHashes === "") || !verifyCategoryName(categoryName))
|
||||||
|
@ -74,6 +135,7 @@
|
||||||
fetch("api/v2/torrents/createCategory", {
|
fetch("api/v2/torrents/createCategory", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
|
...dlPathParams,
|
||||||
category: categoryName,
|
category: categoryName,
|
||||||
savePath: savePath
|
savePath: savePath
|
||||||
})
|
})
|
||||||
|
@ -110,6 +172,7 @@
|
||||||
fetch("api/v2/torrents/createCategory", {
|
fetch("api/v2/torrents/createCategory", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
|
...body,
|
||||||
category: categoryName,
|
category: categoryName,
|
||||||
savePath: savePath
|
savePath: savePath
|
||||||
})
|
})
|
||||||
|
@ -129,6 +192,7 @@
|
||||||
fetch("api/v2/torrents/editCategory", {
|
fetch("api/v2/torrents/editCategory", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
|
...body,
|
||||||
category: uriCategoryName, // category name can't be changed
|
category: uriCategoryName, // category name can't be changed
|
||||||
savePath: savePath
|
savePath: savePath
|
||||||
})
|
})
|
||||||
|
@ -146,6 +210,10 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useDownloadPathElem.addEventListener("change", (e) => {
|
||||||
|
setDownloadPath(e.target.value);
|
||||||
|
});
|
||||||
|
|
||||||
window.qBittorrent.pathAutofill.attachPathAutofill();
|
window.qBittorrent.pathAutofill.attachPathAutofill();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -153,10 +221,32 @@
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div style="padding: 10px 10px 0px 10px;">
|
<div style="padding: 10px 10px 0px 10px;">
|
||||||
<label for="categoryName" style="font-weight: bold;">QBT_TR(Category:)QBT_TR[CONTEXT=TransferListWidget]</label>
|
<div style="display: flex; align-items: center;">
|
||||||
<input type="text" id="categoryName" style="width: 99%;">
|
<label for="categoryName">QBT_TR(Category:)QBT_TR[CONTEXT=Category]</label>
|
||||||
<label for="savePath" style="font-weight: bold;">QBT_TR(Save path:)QBT_TR[CONTEXT=TransferListWidget]</label>
|
<input type="text" id="categoryName" style="flex-grow: 1; margin-left: 10px;">
|
||||||
<input type="text" id="savePath" class="pathDirectory" style="width: 99%;">
|
</div>
|
||||||
|
<div style="display: flex; align-items: center;">
|
||||||
|
<label for="savePath">QBT_TR(Save path:)QBT_TR[CONTEXT=Category]</label>
|
||||||
|
<input type="text" id="savePath" class="pathDirectory" style="flex-grow: 1; margin-left: 10px;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<fieldset class="settings" style="text-align: left;">
|
||||||
|
<legend>QBT_TR(Save path for incomplete torrents:)QBT_TR[CONTEXT=Category]</legend>
|
||||||
|
|
||||||
|
<div style="display: flex; align-items: center;">
|
||||||
|
<label for="useDownloadPath">QBT_TR(Use another path for incomplete torrents:)QBT_TR[CONTEXT=Category]</label>
|
||||||
|
<select id="useDownloadPath">
|
||||||
|
<option selected value="default">QBT_TR(Default)QBT_TR[CONTEXT=Category]</option>
|
||||||
|
<option value="yes">QBT_TR(Yes)QBT_TR[CONTEXT=Category]</option>
|
||||||
|
<option value="no">QBT_TR(No)QBT_TR[CONTEXT=Category]</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; align-items: center;">
|
||||||
|
<label for="downloadPath">QBT_TR(Path:)QBT_TR[CONTEXT=Category]</label>
|
||||||
|
<input type="text" id="downloadPath" class="pathDirectory" style="flex-grow: 1; margin-left: 10px;">
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<div style="text-align: center; padding-top: 10px;">
|
<div style="text-align: center; padding-top: 10px;">
|
||||||
<input type="button" value="QBT_TR(OK)QBT_TR[CONTEXT=Category]" id="categoryNameButton">
|
<input type="button" value="QBT_TR(OK)QBT_TR[CONTEXT=Category]" id="categoryNameButton">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -832,12 +832,15 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
||||||
if (categoryData === undefined) {
|
if (categoryData === undefined) {
|
||||||
window.qBittorrent.Client.categoryMap.set(responseName, {
|
window.qBittorrent.Client.categoryMap.set(responseName, {
|
||||||
savePath: responseData.savePath,
|
savePath: responseData.savePath,
|
||||||
|
downloadPath: responseData.download_path ?? null,
|
||||||
torrents: new Set()
|
torrents: new Set()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// only the save path can change for existing categories
|
if (responseData.savePath !== undefined)
|
||||||
categoryData.savePath = responseData.savePath;
|
categoryData.savePath = responseData.savePath;
|
||||||
|
if (responseData.download_path !== undefined)
|
||||||
|
categoryData.downloadPath = responseData.download_path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateCategories = true;
|
updateCategories = true;
|
||||||
|
|
|
@ -882,7 +882,7 @@ const initializeWindows = () => {
|
||||||
paddingVertical: 0,
|
paddingVertical: 0,
|
||||||
paddingHorizontal: 0,
|
paddingHorizontal: 0,
|
||||||
width: window.qBittorrent.Dialog.limitWidthToViewport(400),
|
width: window.qBittorrent.Dialog.limitWidthToViewport(400),
|
||||||
height: 150
|
height: 200
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -923,7 +923,7 @@ const initializeWindows = () => {
|
||||||
paddingVertical: 0,
|
paddingVertical: 0,
|
||||||
paddingHorizontal: 0,
|
paddingHorizontal: 0,
|
||||||
width: window.qBittorrent.Dialog.limitWidthToViewport(400),
|
width: window.qBittorrent.Dialog.limitWidthToViewport(400),
|
||||||
height: 150
|
height: 200
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -945,7 +945,7 @@ const initializeWindows = () => {
|
||||||
paddingVertical: 0,
|
paddingVertical: 0,
|
||||||
paddingHorizontal: 0,
|
paddingHorizontal: 0,
|
||||||
width: window.qBittorrent.Dialog.limitWidthToViewport(400),
|
width: window.qBittorrent.Dialog.limitWidthToViewport(400),
|
||||||
height: 150
|
height: 200
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -953,8 +953,7 @@ const initializeWindows = () => {
|
||||||
const contentURL = new URL("newcategory.html", window.location);
|
const contentURL = new URL("newcategory.html", window.location);
|
||||||
contentURL.search = new URLSearchParams({
|
contentURL.search = new URLSearchParams({
|
||||||
action: "edit",
|
action: "edit",
|
||||||
categoryName: category,
|
categoryName: category
|
||||||
savePath: categoryMap.get(category).savePath
|
|
||||||
});
|
});
|
||||||
new MochaUI.Window({
|
new MochaUI.Window({
|
||||||
id: "editCategoryPage",
|
id: "editCategoryPage",
|
||||||
|
@ -968,7 +967,7 @@ const initializeWindows = () => {
|
||||||
paddingVertical: 0,
|
paddingVertical: 0,
|
||||||
paddingHorizontal: 0,
|
paddingHorizontal: 0,
|
||||||
width: window.qBittorrent.Dialog.limitWidthToViewport(400),
|
width: window.qBittorrent.Dialog.limitWidthToViewport(400),
|
||||||
height: 150
|
height: 200
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue