WebUI: migrate to fetch API

And away from mootools.

PR #22037.
This commit is contained in:
Chocobo1 2024-12-22 17:51:19 +08:00 committed by GitHub
commit a841fe9320
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 888 additions and 811 deletions

View file

@ -36,20 +36,21 @@
if (peers.length === 0) if (peers.length === 0)
return; return;
new Request({ fetch("api/v2/torrents/addPeers", {
url: "api/v2/torrents/addPeers", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hashes": hash,
hashes: hash, "peers": peers.join("|")
peers: peers.join("|") })
}, })
onFailure: () => { .then((response) => {
if (!response.ok) {
alert("QBT_TR(Unable to add peers. Please ensure you are adhering to the IP:port format.)QBT_TR[CONTEXT=HttpServer]"); alert("QBT_TR(Unable to add peers. Please ensure you are adhering to the IP:port format.)QBT_TR[CONTEXT=HttpServer]");
}, return;
onSuccess: () => {
window.parent.qBittorrent.Client.closeFrameWindow(window);
} }
}).send();
window.parent.qBittorrent.Client.closeFrameWindow(window);
});
}); });
}); });
</script> </script>

View file

@ -27,18 +27,19 @@
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
const hash = new URI().getData("hash"); fetch("api/v2/torrents/addTrackers", {
new Request({ method: "POST",
url: "api/v2/torrents/addTrackers", body: new URLSearchParams({
method: "post", "hash": new URI().getData("hash"),
data: { "urls": $("trackersUrls").value
hash: hash, })
urls: $("trackersUrls").value })
}, .then((response) => {
onComplete: () => { if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
}); });
}); });
</script> </script>

View file

@ -25,18 +25,20 @@
$("urls").focus(); $("urls").focus();
$("addWebSeedsButton").addEventListener("click", (e) => { $("addWebSeedsButton").addEventListener("click", (e) => {
e.stopPropagation(); e.stopPropagation();
const hash = new URI().getData("hash");
new Request({ fetch("api/v2/torrents/addWebSeeds", {
url: "api/v2/torrents/addWebSeeds", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hash": new URI().getData("hash"),
hash: hash, "urls": $("urls").value.split("\n").map(w => encodeURIComponent(w.trim())).filter(w => (w.length > 0)).join("|")
urls: $("urls").value.split("\n").map(w => encodeURIComponent(w.trim())).filter(w => (w.length > 0)).join("|") })
}, })
onComplete: () => { .then((response) => {
if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
}); });
}); });
</script> </script>

View file

@ -26,20 +26,22 @@
let completionCount = 0; let completionCount = 0;
paths.forEach((path) => { paths.forEach((path) => {
new Request({ fetch("api/v2/rss/removeItem", {
url: "api/v2/rss/removeItem", method: "POST",
method: "post", body: new URLSearchParams({
data: { "path": decodeURIComponent(path)
path: decodeURIComponent(path) })
}, })
onComplete: (response) => { .then((response) => {
if (!response.ok)
return;
++completionCount; ++completionCount;
if (completionCount === paths.length) { if (completionCount === paths.length) {
window.parent.qBittorrent.Rss.updateRssFeedList(); window.parent.qBittorrent.Rss.updateRssFeedList();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} }
} });
}).send();
}); });
}); });
}); });

View file

@ -27,20 +27,22 @@
let completionCount = 0; let completionCount = 0;
rules.forEach((rule) => { rules.forEach((rule) => {
new Request({ fetch("api/v2/rss/removeRule", {
url: "api/v2/rss/removeRule", method: "POST",
method: "post", body: new URLSearchParams({
data: { "ruleName": decodeURIComponent(rule)
ruleName: decodeURIComponent(rule) })
}, })
onComplete: (response) => { .then((response) => {
if (!response.ok)
return;
++completionCount; ++completionCount;
if (completionCount === rules.length) { if (completionCount === rules.length) {
window.parent.qBittorrent.RssDownloader.updateRulesList(); window.parent.qBittorrent.RssDownloader.updateRulesList();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} }
} });
}).send();
}); });
}); });
}); });

View file

@ -24,18 +24,20 @@
}); });
$("confirmBtn").addEventListener("click", (e) => { $("confirmBtn").addEventListener("click", (e) => {
e.stopPropagation(); e.stopPropagation();
const cmd = "api/v2/torrents/removeTrackers";
new Request({ fetch("api/v2/torrents/removeTrackers", {
url: cmd, method: "POST",
method: "post", body: new URLSearchParams({
data: { "hash": "*",
hash: "*", "urls": urls
urls: urls, })
}, })
onComplete: () => { .then((response) => {
if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
}); });
}); });
</script> </script>

View file

@ -50,30 +50,34 @@
const setDlLimit = () => { const setDlLimit = () => {
const limit = Number($("dllimitUpdatevalue").value) * 1024; const limit = Number($("dllimitUpdatevalue").value) * 1024;
if (hashes[0] === "global") { if (hashes[0] === "global") {
new Request({ fetch("api/v2/transfer/setDownloadLimit", {
url: "api/v2/transfer/setDownloadLimit", method: "POST",
method: "post", body: new URLSearchParams({
data: {
"limit": limit "limit": limit
}, })
onComplete: () => { })
.then(async (response) => {
if (!response.ok)
return;
window.parent.updateMainData(); window.parent.updateMainData();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
} }
else { else {
new Request({ fetch("api/v2/torrents/setDownloadLimit", {
url: "api/v2/torrents/setDownloadLimit", method: "POST",
method: "post", body: new URLSearchParams({
data: {
"hashes": hashes.join("|"), "hashes": hashes.join("|"),
"limit": limit "limit": limit
}, })
onComplete: () => { })
.then(async (response) => {
if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
} }
}; };

View file

@ -51,25 +51,25 @@
$("submitButton").disabled = true; $("submitButton").disabled = true;
new Request({ fetch("api/v2/rss/setFeedURL", {
url: "api/v2/rss/setFeedURL", method: "POST",
method: "post", body: new URLSearchParams({
data: { "path": new URI().getData("path"),
path: new URI().getData("path"), "url": newUrl
url: newUrl })
}, })
onSuccess: (response) => { .then(async (response) => {
if (!response.ok) {
alert((response.status === 409)
? await response.text()
: "QBT_TR(Unable to update URL)QBT_TR[CONTEXT=RSSWidget]");
$("submitButton").disabled = false;
return;
}
window.parent.qBittorrent.Rss.updateRssFeedList(); window.parent.qBittorrent.Rss.updateRssFeedList();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
}, });
onFailure: (response) => {
if (response.status === 409)
alert(response.responseText);
else
alert("QBT_TR(Unable to update URL)QBT_TR[CONTEXT=RSSWidget]");
$("submitButton").disabled = false;
}
}).send();
}); });
}); });
</script> </script>

View file

@ -37,19 +37,20 @@
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
const hash = new URI().getData("hash"); fetch("api/v2/torrents/editTracker", {
new Request({ method: "POST",
url: "api/v2/torrents/editTracker", body: new URLSearchParams({
method: "post", "hash": new URI().getData("hash"),
data: { "origUrl": currentUrl,
hash: hash, "newUrl": $("trackerUrl").value
origUrl: currentUrl, })
newUrl: $("trackerUrl").value })
}, .then((response) => {
onComplete: () => { if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
}); });
}); });
</script> </script>

View file

@ -32,19 +32,21 @@
$("editWebSeedButton").addEventListener("click", (e) => { $("editWebSeedButton").addEventListener("click", (e) => {
e.stopPropagation(); e.stopPropagation();
const hash = new URI().getData("hash");
new Request({ fetch("api/v2/torrents/editWebSeed", {
url: "api/v2/torrents/editWebSeed", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hash": new URI().getData("hash"),
hash: hash, "origUrl": origUrl,
origUrl: origUrl, "newUrl": encodeURIComponent($("url").value.trim())
newUrl: encodeURIComponent($("url").value.trim()), })
}, })
onComplete: () => { .then((response) => {
if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
}); });
}); });
</script> </script>

View file

@ -72,72 +72,77 @@
if ((uriHashes === "") || !verifyCategoryName(categoryName)) if ((uriHashes === "") || !verifyCategoryName(categoryName))
return; return;
new Request({ fetch("api/v2/torrents/createCategory", {
url: "api/v2/torrents/createCategory", method: "POST",
method: "post", body: new URLSearchParams({
data: { "category": categoryName,
category: categoryName, "savePath": savePath
savePath: savePath })
}, })
onSuccess: () => { .then((response) => {
new Request({ if (!response.ok) {
url: "api/v2/torrents/setCategory", alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=Category] " + window.qBittorrent.Misc.escapeHtml(categoryName));
method: "post", return;
data: { }
hashes: uriHashes,
category: categoryName fetch("api/v2/torrents/setCategory", {
}, method: "POST",
onSuccess: () => { body: new URLSearchParams({
"hashes": uriHashes,
"category": categoryName
})
})
.then((response) => {
if (!response.ok) {
alert("QBT_TR(Unable to set category)QBT_TR[CONTEXT=Category]");
return;
}
window.parent.updateMainData(); window.parent.updateMainData();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
}, });
onFailure: () => { });
alert("QBT_TR(Unable to set category)QBT_TR[CONTEXT=Category]");
}
}).send();
},
onFailure: () => {
alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=Category] " + window.qBittorrent.Misc.escapeHtml(categoryName));
}
}).send();
break; break;
case "create": case "create":
case "createSubcategory": case "createSubcategory":
if (!verifyCategoryName(categoryName)) if (!verifyCategoryName(categoryName))
return; return;
fetch("api/v2/torrents/createCategory", {
new Request({ method: "POST",
url: "api/v2/torrents/createCategory", body: new URLSearchParams({
method: "post", "category": categoryName,
data: { "savePath": savePath
category: categoryName, })
savePath: savePath })
}, .then((response) => {
onSuccess: () => { if (!response.ok) {
window.parent.updateMainData();
window.parent.qBittorrent.Client.closeFrameWindow(window);
},
onFailure: () => {
alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=Category]"); alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=Category]");
return;
} }
}).send();
break;
case "edit":
new Request({
url: "api/v2/torrents/editCategory",
method: "post",
data: {
category: uriCategoryName, // category name can't be changed
savePath: savePath
},
onSuccess: () => {
window.parent.updateMainData(); window.parent.updateMainData();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
}, });
onFailure: () => { break;
case "edit":
fetch("api/v2/torrents/editCategory", {
method: "POST",
body: new URLSearchParams({
"category": uriCategoryName, // category name can't be changed
"savePath": savePath
})
})
.then((response) => {
if (!response.ok) {
alert("QBT_TR(Unable to edit category)QBT_TR[CONTEXT=Category]"); alert("QBT_TR(Unable to edit category)QBT_TR[CONTEXT=Category]");
return;
} }
}).send();
window.parent.updateMainData();
window.parent.qBittorrent.Client.closeFrameWindow(window);
});
break; break;
} }
}); });

View file

@ -42,23 +42,24 @@
$("submitButton").disabled = true; $("submitButton").disabled = true;
new Request({ fetch("api/v2/rss/addFeed", {
url: "api/v2/rss/addFeed", method: "POST",
method: "post", body: new URLSearchParams({
data: { "url": feedURL,
url: feedURL, "path": path ? (path + "\\" + feedURL) : ""
path: path ? (path + "\\" + feedURL) : "" })
}, })
onSuccess: (response) => { .then(async (response) => {
if (!response.ok) {
if (response.status === 409)
alert(await response.text());
$("submitButton").disabled = false;
return;
}
window.parent.qBittorrent.Rss.updateRssFeedList(); window.parent.qBittorrent.Rss.updateRssFeedList();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
}, });
onFailure: (response) => {
if (response.status === 409)
alert(response.responseText);
$("submitButton").disabled = false;
}
}).send();
}); });
}); });
</script> </script>

View file

@ -43,22 +43,23 @@
$("submitButton").disabled = true; $("submitButton").disabled = true;
new Request({ fetch("api/v2/rss/addFolder", {
url: "api/v2/rss/addFolder", method: "POST",
method: "post", body: new URLSearchParams({
data: { "path": path ? (path + "\\" + folderName) : folderName
path: path ? (path + "\\" + folderName) : folderName })
}, })
onSuccess: (response) => { .then(async (response) => {
if (!response.ok) {
if (response.status === 409)
alert(await response.text());
$("submitButton").disabled = false;
return;
}
window.parent.qBittorrent.Rss.updateRssFeedList(); window.parent.qBittorrent.Rss.updateRssFeedList();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
}, });
onFailure: (response) => {
if (response.status === 409)
alert(response.responseText);
$("submitButton").disabled = false;
}
}).send();
}); });
}); });

View file

@ -39,18 +39,21 @@
return; return;
} }
$("submitButton").disabled = true; $("submitButton").disabled = true;
new Request({
url: "api/v2/rss/setRule", fetch("api/v2/rss/setRule", {
method: "post", method: "POST",
data: { body: new URLSearchParams({
ruleName: name, "ruleName": name,
ruleDef: "{}" "ruleDef": "{}"
}, })
onSuccess: (response) => { })
.then((response) => {
if (!response.ok)
return;
window.parent.qBittorrent.RssDownloader.updateRulesList(); window.parent.qBittorrent.RssDownloader.updateRulesList();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
}); });
}); });
</script> </script>

View file

@ -56,33 +56,37 @@
if (uriHashes === "") if (uriHashes === "")
return; return;
new Request({ fetch("api/v2/torrents/addTags", {
url: "api/v2/torrents/addTags", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hashes": uriHashes,
hashes: uriHashes, "tags": tagName
tags: tagName, })
}, })
onComplete: () => { .then(async (response) => {
if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
break; break;
case "create": case "create":
if (!verifyTagName(tagName)) if (!verifyTagName(tagName))
return; return;
new Request({ fetch("api/v2/torrents/createTags", {
url: "api/v2/torrents/createTags", method: "POST",
method: "post", body: new URLSearchParams({
data: { "tags": tagName
tags: tagName, })
}, })
onComplete: () => { .then(async (response) => {
if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
break; break;
} }
}); });

View file

@ -44,17 +44,19 @@
const hash = new URI().getData("hash"); const hash = new URI().getData("hash");
if (hash) { if (hash) {
new Request({ fetch("api/v2/torrents/rename", {
url: "api/v2/torrents/rename", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hash": hash,
hash: hash, "name": name
name: name })
}, })
onComplete: () => { .then((response) => {
if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
} }
}); });
}); });

View file

@ -51,23 +51,24 @@
$("renameButton").disabled = true; $("renameButton").disabled = true;
new Request({ fetch("api/v2/rss/moveItem", {
url: "api/v2/rss/moveItem", method: "POST",
method: "post", body: new URLSearchParams({
data: { "itemPath": oldPath,
itemPath: oldPath, "destPath": newPath
destPath: newPath })
}, })
onSuccess: (response) => { .then(async (response) => {
if (!response.ok) {
if (response.status === 409)
alert(await response.text());
$("renameButton").disabled = false;
return;
}
window.parent.qBittorrent.Rss.updateRssFeedList(); window.parent.qBittorrent.Rss.updateRssFeedList();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
}, });
onFailure: (response) => {
if (response.status === 409)
alert(response.responseText);
$("renameButton").disabled = false;
}
}).send();
}); });
}); });
</script> </script>

View file

@ -60,22 +60,23 @@
const newPath = parentPath const newPath = parentPath
? parentPath + window.qBittorrent.Filesystem.PathSeparator + newName ? parentPath + window.qBittorrent.Filesystem.PathSeparator + newName
: newName; : newName;
new Request({ fetch((isFolder ? "api/v2/torrents/renameFolder" : "api/v2/torrents/renameFile"), {
url: isFolder ? "api/v2/torrents/renameFolder" : "api/v2/torrents/renameFile", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hash": hash,
hash: hash, "oldPath": oldPath,
oldPath: oldPath, "newPath": newPath
newPath: newPath })
}, })
onSuccess: () => { .then((response) => {
window.parent.qBittorrent.Client.closeFrameWindow(window); if (!response.ok) {
},
onFailure: () => {
alert("QBT_TR(Failed to update name)QBT_TR[CONTEXT=HttpServer]"); alert("QBT_TR(Failed to update name)QBT_TR[CONTEXT=HttpServer]");
$("renameButton").disabled = false; $("renameButton").disabled = false;
return;
} }
}).send();
window.parent.qBittorrent.Client.closeFrameWindow(window);
});
}); });
}); });
</script> </script>

View file

@ -379,17 +379,20 @@
}; };
const setupTable = (selectedRows) => { const setupTable = (selectedRows) => {
new Request.JSON({ fetch(new URI("api/v2/torrents/files").setData("hash", data.hash), {
url: new URI("api/v2/torrents/files?hash=" + data.hash), method: "GET",
noCache: true, cache: "no-store"
method: "get", })
onSuccess: (files) => { .then(async (response) => {
if (!response.ok)
return;
const files = await response.json();
if (files.length === 0) if (files.length === 0)
bulkRenameFilesTable.clear(); bulkRenameFilesTable.clear();
else else
handleTorrentFiles(files, selectedRows); handleTorrentFiles(files, selectedRows);
} });
}).send();
}; };
setupTable(data.selectedRows); setupTable(data.selectedRows);
})(); })();

View file

@ -50,18 +50,21 @@
} }
$("renameButton").disabled = true; $("renameButton").disabled = true;
new Request({
url: "api/v2/rss/renameRule", fetch("api/v2/rss/renameRule", {
method: "post", method: "POST",
data: { body: new URLSearchParams({
ruleName: oldName, "ruleName": oldName,
newRuleName: newName "newRuleName": newName
}, })
onSuccess: (response) => { })
.then((response) => {
if (!response.ok)
return;
window.parent.qBittorrent.RssDownloader.updateRulesList(); window.parent.qBittorrent.RssDownloader.updateRulesList();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
}); });
}); });
</script> </script>

View file

@ -62,8 +62,7 @@ window.qBittorrent.Cache ??= (() => {
if (!response.ok) if (!response.ok)
return; return;
const responseText = await response.text(); const responseJSON = await response.json();
const responseJSON = JSON.parse(responseText);
deepFreeze(responseJSON); deepFreeze(responseJSON);
this.#m_store = responseJSON; this.#m_store = responseJSON;
}); });

View file

@ -748,22 +748,17 @@ window.addEventListener("DOMContentLoaded", () => {
let syncMainDataTimeoutID = -1; let syncMainDataTimeoutID = -1;
let syncRequestInProgress = false; let syncRequestInProgress = false;
const syncMainData = () => { const syncMainData = () => {
const url = new URI("api/v2/sync/maindata"); syncRequestInProgress = true;
url.setData("rid", syncMainDataLastResponseId); fetch(new URI("api/v2/sync/maindata").setData("rid", syncMainDataLastResponseId), {
const request = new Request.JSON({ method: "GET",
url: url, cache: "no-store"
noCache: true, })
method: "get", .then(async (response) => {
onFailure: () => { if (response.ok) {
const errorDiv = $("error_div");
if (errorDiv)
errorDiv.textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]";
syncRequestInProgress = false;
syncData(2000);
},
onSuccess: (response) => {
$("error_div").textContent = ""; $("error_div").textContent = "";
if (response) {
const responseJSON = await response.json();
clearTimeout(torrentsFilterInputTimer); clearTimeout(torrentsFilterInputTimer);
torrentsFilterInputTimer = -1; torrentsFilterInputTimer = -1;
@ -773,8 +768,8 @@ window.addEventListener("DOMContentLoaded", () => {
let updateTags = false; let updateTags = false;
let updateTrackers = false; let updateTrackers = false;
let updateTorrents = false; let updateTorrents = false;
const full_update = (response["full_update"] === true); const fullUpdate = (responseJSON["fullUpdate"] === true);
if (full_update) { if (fullUpdate) {
torrentsTableSelectedRows = torrentsTable.selectedRowsIds(); torrentsTableSelectedRows = torrentsTable.selectedRowsIds();
updateStatuses = true; updateStatuses = true;
update_categories = true; update_categories = true;
@ -786,14 +781,14 @@ window.addEventListener("DOMContentLoaded", () => {
tagList.clear(); tagList.clear();
trackerList.clear(); trackerList.clear();
} }
if (response["rid"]) if (responseJSON["rid"])
syncMainDataLastResponseId = response["rid"]; syncMainDataLastResponseId = responseJSON["rid"];
if (response["categories"]) { if (responseJSON["categories"]) {
for (const key in response["categories"]) { for (const key in responseJSON["categories"]) {
if (!Object.hasOwn(response["categories"], key)) if (!Object.hasOwn(responseJSON["categories"], key))
continue; continue;
const responseCategory = response["categories"][key]; const responseCategory = responseJSON["categories"][key];
const categoryHash = window.qBittorrent.Misc.genHash(key); const categoryHash = window.qBittorrent.Misc.genHash(key);
const category = category_list.get(categoryHash); const category = category_list.get(categoryHash);
if (category !== undefined) { if (category !== undefined) {
@ -810,15 +805,15 @@ window.addEventListener("DOMContentLoaded", () => {
} }
update_categories = true; update_categories = true;
} }
if (response["categories_removed"]) { if (responseJSON["categories_removed"]) {
response["categories_removed"].each((category) => { responseJSON["categories_removed"].each((category) => {
const categoryHash = window.qBittorrent.Misc.genHash(category); const categoryHash = window.qBittorrent.Misc.genHash(category);
category_list.delete(categoryHash); category_list.delete(categoryHash);
}); });
update_categories = true; update_categories = true;
} }
if (response["tags"]) { if (responseJSON["tags"]) {
for (const tag of response["tags"]) { for (const tag of responseJSON["tags"]) {
const tagHash = window.qBittorrent.Misc.genHash(tag); const tagHash = window.qBittorrent.Misc.genHash(tag);
if (!tagList.has(tagHash)) { if (!tagList.has(tagHash)) {
tagList.set(tagHash, { tagList.set(tagHash, {
@ -829,15 +824,15 @@ window.addEventListener("DOMContentLoaded", () => {
} }
updateTags = true; updateTags = true;
} }
if (response["tags_removed"]) { if (responseJSON["tags_removed"]) {
for (let i = 0; i < response["tags_removed"].length; ++i) { for (let i = 0; i < responseJSON["tags_removed"].length; ++i) {
const tagHash = window.qBittorrent.Misc.genHash(response["tags_removed"][i]); const tagHash = window.qBittorrent.Misc.genHash(responseJSON["tags_removed"][i]);
tagList.delete(tagHash); tagList.delete(tagHash);
} }
updateTags = true; updateTags = true;
} }
if (response["trackers"]) { if (responseJSON["trackers"]) {
for (const [tracker, torrents] of Object.entries(response["trackers"])) { for (const [tracker, torrents] of Object.entries(responseJSON["trackers"])) {
const host = window.qBittorrent.Misc.getHost(tracker); const host = window.qBittorrent.Misc.getHost(tracker);
const hash = window.qBittorrent.Misc.genHash(host); const hash = window.qBittorrent.Misc.genHash(host);
@ -850,9 +845,9 @@ window.addEventListener("DOMContentLoaded", () => {
} }
updateTrackers = true; updateTrackers = true;
} }
if (response["trackers_removed"]) { if (responseJSON["trackers_removed"]) {
for (let i = 0; i < response["trackers_removed"].length; ++i) { for (let i = 0; i < responseJSON["trackers_removed"].length; ++i) {
const tracker = response["trackers_removed"][i]; const tracker = responseJSON["trackers_removed"][i];
const host = window.qBittorrent.Misc.getHost(tracker); const host = window.qBittorrent.Misc.getHost(tracker);
const hash = window.qBittorrent.Misc.genHash(host); const hash = window.qBittorrent.Misc.genHash(host);
const trackerListEntry = trackerList.get(hash); const trackerListEntry = trackerList.get(hash);
@ -870,29 +865,29 @@ window.addEventListener("DOMContentLoaded", () => {
} }
updateTrackers = true; updateTrackers = true;
} }
if (response["torrents"]) { if (responseJSON["torrents"]) {
for (const key in response["torrents"]) { for (const key in responseJSON["torrents"]) {
if (!Object.hasOwn(response["torrents"], key)) if (!Object.hasOwn(responseJSON["torrents"], key))
continue; continue;
response["torrents"][key]["hash"] = key; responseJSON["torrents"][key]["hash"] = key;
response["torrents"][key]["rowId"] = key; responseJSON["torrents"][key]["rowId"] = key;
if (response["torrents"][key]["state"]) { if (responseJSON["torrents"][key]["state"]) {
const state = response["torrents"][key]["state"]; const state = responseJSON["torrents"][key]["state"];
response["torrents"][key]["status"] = state; responseJSON["torrents"][key]["status"] = state;
response["torrents"][key]["_statusOrder"] = statusSortOrder[state]; responseJSON["torrents"][key]["_statusOrder"] = statusSortOrder[state];
updateStatuses = true; updateStatuses = true;
} }
torrentsTable.updateRowData(response["torrents"][key]); torrentsTable.updateRowData(responseJSON["torrents"][key]);
if (addTorrentToCategoryList(response["torrents"][key])) if (addTorrentToCategoryList(responseJSON["torrents"][key]))
update_categories = true; update_categories = true;
if (addTorrentToTagList(response["torrents"][key])) if (addTorrentToTagList(responseJSON["torrents"][key]))
updateTags = true; updateTags = true;
updateTorrents = true; updateTorrents = true;
} }
} }
if (response["torrents_removed"]) { if (responseJSON["torrents_removed"]) {
response["torrents_removed"].each((hash) => { responseJSON["torrents_removed"].each((hash) => {
torrentsTable.removeRow(hash); torrentsTable.removeRow(hash);
removeTorrentFromCategoryList(hash); removeTorrentFromCategoryList(hash);
update_categories = true; // Always to update All category update_categories = true; // Always to update All category
@ -905,10 +900,10 @@ window.addEventListener("DOMContentLoaded", () => {
// don't update the table unnecessarily // don't update the table unnecessarily
if (updateTorrents) if (updateTorrents)
torrentsTable.updateTable(full_update); torrentsTable.updateTable(fullUpdate);
if (response["server_state"]) { if (responseJSON["server_state"]) {
const tmp = response["server_state"]; const tmp = responseJSON["server_state"];
for (const k in tmp) { for (const k in tmp) {
if (!Object.hasOwn(tmp, k)) if (!Object.hasOwn(tmp, k))
continue; continue;
@ -931,16 +926,21 @@ window.addEventListener("DOMContentLoaded", () => {
if (updateTrackers) if (updateTrackers)
updateTrackerList(); updateTrackerList();
if (full_update) if (fullUpdate)
// re-select previously selected rows // re-select previously selected rows
torrentsTable.reselectRows(torrentsTableSelectedRows); torrentsTable.reselectRows(torrentsTableSelectedRows);
} }
syncRequestInProgress = false; syncRequestInProgress = false;
syncData(window.qBittorrent.Client.getSyncMainDataInterval()); syncData(window.qBittorrent.Client.getSyncMainDataInterval());
} },
(error) => {
const errorDiv = $("error_div");
if (errorDiv)
errorDiv.textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]";
syncRequestInProgress = false;
syncData(2000);
}); });
syncRequestInProgress = true;
request.send();
}; };
updateMainData = () => { updateMainData = () => {
@ -1101,18 +1101,19 @@ window.addEventListener("DOMContentLoaded", () => {
// Change icon immediately to give some feedback // Change icon immediately to give some feedback
updateAltSpeedIcon(!alternativeSpeedLimits); updateAltSpeedIcon(!alternativeSpeedLimits);
new Request({ fetch("api/v2/transfer/toggleSpeedLimitsMode", {
url: "api/v2/transfer/toggleSpeedLimitsMode", method: "POST"
method: "post", })
onComplete: () => { .then((response) => {
alternativeSpeedLimits = !alternativeSpeedLimits; if (!response.ok) {
updateMainData();
},
onFailure: () => {
// Restore icon in case of failure // Restore icon in case of failure
updateAltSpeedIcon(alternativeSpeedLimits); updateAltSpeedIcon(alternativeSpeedLimits);
return;
} }
}).send();
alternativeSpeedLimits = !alternativeSpeedLimits;
updateMainData();
});
}); });
$("DlInfos").addEventListener("click", () => { globalDownloadLimitFN(); }); $("DlInfos").addEventListener("click", () => { globalDownloadLimitFN(); });

View file

@ -36,12 +36,16 @@ window.qBittorrent.Download ??= (() => {
let defaultSavePath = ""; let defaultSavePath = "";
const getCategories = () => { const getCategories = () => {
new Request.JSON({ fetch("api/v2/torrents/categories", {
url: "api/v2/torrents/categories", method: "GET",
method: "get", cache: "no-store"
noCache: true, })
onSuccess: (data) => { .then(async (response) => {
if (data) { if (!response.ok)
return;
const data = await response.json();
categories = data; categories = data;
for (const i in data) { for (const i in data) {
if (!Object.hasOwn(data, i)) if (!Object.hasOwn(data, i))
@ -53,9 +57,7 @@ window.qBittorrent.Download ??= (() => {
option.textContent = category.name; option.textContent = category.name;
$("categorySelect").appendChild(option); $("categorySelect").appendChild(option);
} }
} });
}
}).send();
}; };
const getPreferences = () => { const getPreferences = () => {

View file

@ -308,18 +308,20 @@ window.qBittorrent.PropFiles ??= (() => {
clearTimeout(loadTorrentFilesDataTimer); clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesDataTimer = -1; loadTorrentFilesDataTimer = -1;
new Request({ fetch("api/v2/torrents/filePrio", {
url: "api/v2/torrents/filePrio", method: "POST",
method: "post", body: new URLSearchParams({
data: {
"hash": current_hash, "hash": current_hash,
"id": fileIds.join("|"), "id": fileIds.join("|"),
"priority": priority "priority": priority
}, })
onComplete: () => { })
.then((response) => {
if (!response.ok)
return;
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(1000); loadTorrentFilesDataTimer = loadTorrentFilesData.delay(1000);
} });
}).send();
const ignore = (priority === FilePriority.Ignored); const ignore = (priority === FilePriority.Ignored);
ids.forEach((_id) => { ids.forEach((_id) => {
@ -352,16 +354,16 @@ window.qBittorrent.PropFiles ??= (() => {
current_hash = new_hash; current_hash = new_hash;
loadedNewTorrent = true; loadedNewTorrent = true;
} }
const url = new URI("api/v2/torrents/files?hash=" + current_hash); fetch(new URI("api/v2/torrents/files").setData("hash", current_hash), {
new Request.JSON({ method: "GET",
url: url, cache: "no-store"
method: "get", })
noCache: true, .then(async (response) => {
onComplete: () => { if (!response.ok)
clearTimeout(loadTorrentFilesDataTimer); return;
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000);
}, const files = await response.json();
onSuccess: (files) => {
clearTimeout(torrentFilesFilterInputTimer); clearTimeout(torrentFilesFilterInputTimer);
torrentFilesFilterInputTimer = -1; torrentFilesFilterInputTimer = -1;
@ -373,8 +375,11 @@ window.qBittorrent.PropFiles ??= (() => {
if (loadedNewTorrent) if (loadedNewTorrent)
collapseAllNodes(); collapseAllNodes();
} }
} })
}).send(); .finally(() => {
clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000);
});
}; };
const updateData = () => { const updateData = () => {

View file

@ -87,18 +87,22 @@ window.qBittorrent.PropGeneral ??= (() => {
clearTimeout(loadTorrentDataTimer); clearTimeout(loadTorrentDataTimer);
return; return;
} }
const url = new URI("api/v2/torrents/properties?hash=" + current_id);
new Request.JSON({ fetch(new URI("api/v2/torrents/properties").setData("hash", current_id), {
url: url, method: "GET",
method: "get", cache: "no-store"
noCache: true, })
onFailure: () => { .then(async (response) => {
if (!response.ok) {
$("error_div").textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]"; $("error_div").textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]";
clearTimeout(loadTorrentDataTimer); clearTimeout(loadTorrentDataTimer);
loadTorrentDataTimer = loadTorrentData.delay(10000); loadTorrentDataTimer = loadTorrentData.delay(10000);
}, return;
onSuccess: (data) => { }
$("error_div").textContent = ""; $("error_div").textContent = "";
const data = await response.json();
if (data) { if (data) {
// Update Torrent data // Update Torrent data
@ -224,22 +228,23 @@ window.qBittorrent.PropGeneral ??= (() => {
} }
clearTimeout(loadTorrentDataTimer); clearTimeout(loadTorrentDataTimer);
loadTorrentDataTimer = loadTorrentData.delay(5000); loadTorrentDataTimer = loadTorrentData.delay(5000);
} });
}).send();
const piecesUrl = new URI("api/v2/torrents/pieceStates?hash=" + current_id); fetch(new URI("api/v2/torrents/pieceStates").setData("hash", current_id), {
new Request.JSON({ method: "GET",
url: piecesUrl, cache: "no-store"
method: "get", })
noCache: true, .then(async (response) => {
onFailure: () => { if (!response.ok) {
$("error_div").textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]"; $("error_div").textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]";
clearTimeout(loadTorrentDataTimer); clearTimeout(loadTorrentDataTimer);
loadTorrentDataTimer = loadTorrentData.delay(10000); loadTorrentDataTimer = loadTorrentData.delay(10000);
}, return;
onSuccess: (data) => { }
$("error_div").textContent = ""; $("error_div").textContent = "";
const data = await response.json();
if (data) if (data)
piecesBar.setPieces(data); piecesBar.setPieces(data);
else else
@ -247,8 +252,7 @@ window.qBittorrent.PropGeneral ??= (() => {
clearTimeout(loadTorrentDataTimer); clearTimeout(loadTorrentDataTimer);
loadTorrentDataTimer = loadTorrentData.delay(5000); loadTorrentDataTimer = loadTorrentData.delay(5000);
} });
}).send();
}; };
const updateData = () => { const updateData = () => {

View file

@ -56,44 +56,45 @@ window.qBittorrent.PropPeers ??= (() => {
clearTimeout(loadTorrentPeersTimer); clearTimeout(loadTorrentPeersTimer);
return; return;
} }
const url = new URI("api/v2/sync/torrentPeers"); const url = new URI("api/v2/sync/torrentPeers")
url.setData("rid", syncTorrentPeersLastResponseId); .setData("rid", syncTorrentPeersLastResponseId)
url.setData("hash", current_hash); .setData("hash", current_hash);
new Request.JSON({ fetch(url, {
url: url, method: "GET",
method: "get", cache: "no-store"
noCache: true, })
onComplete: () => { .then(async (response) => {
clearTimeout(loadTorrentPeersTimer); if (!response.ok)
loadTorrentPeersTimer = loadTorrentPeersData.delay(window.qBittorrent.Client.getSyncMainDataInterval()); return;
},
onSuccess: (response) => { const responseJSON = await response.json();
$("error_div").textContent = ""; $("error_div").textContent = "";
if (response) { if (responseJSON) {
const full_update = (response["full_update"] === true); const full_update = (responseJSON["full_update"] === true);
if (full_update) if (full_update)
torrentPeersTable.clear(); torrentPeersTable.clear();
if (response["rid"]) if (responseJSON["rid"])
syncTorrentPeersLastResponseId = response["rid"]; syncTorrentPeersLastResponseId = responseJSON["rid"];
if (response["peers"]) { if (responseJSON["peers"]) {
for (const key in response["peers"]) { for (const key in responseJSON["peers"]) {
if (!Object.hasOwn(response["peers"], key)) if (!Object.hasOwn(responseJSON["peers"], key))
continue; continue;
response["peers"][key]["rowId"] = key; responseJSON["peers"][key]["rowId"] = key;
torrentPeersTable.updateRowData(response["peers"][key]); torrentPeersTable.updateRowData(responseJSON["peers"][key]);
} }
} }
if (response["peers_removed"]) { if (responseJSON["peers_removed"]) {
response["peers_removed"].each((hash) => { responseJSON["peers_removed"].each((hash) => {
torrentPeersTable.removeRow(hash); torrentPeersTable.removeRow(hash);
}); });
} }
torrentPeersTable.updateTable(full_update); torrentPeersTable.updateTable(full_update);
if (response["show_flags"]) { if (responseJSON["show_flags"]) {
if (show_flags !== response["show_flags"]) { if (show_flags !== responseJSON["show_flags"]) {
show_flags = response["show_flags"]; show_flags = responseJSON["show_flags"];
torrentPeersTable.columns["country"].force_hide = !show_flags; torrentPeersTable.columns["country"].force_hide = !show_flags;
torrentPeersTable.updateColumn("country"); torrentPeersTable.updateColumn("country");
} }
@ -102,8 +103,12 @@ window.qBittorrent.PropPeers ??= (() => {
else { else {
torrentPeersTable.clear(); torrentPeersTable.clear();
} }
}
}).send(); })
.finally(() => {
clearTimeout(loadTorrentPeersTimer);
loadTorrentPeersTimer = loadTorrentPeersData.delay(window.qBittorrent.Client.getSyncMainDataInterval());
});
}; };
const updateData = () => { const updateData = () => {
@ -146,14 +151,13 @@ window.qBittorrent.PropPeers ??= (() => {
return; return;
if (confirm("QBT_TR(Are you sure you want to permanently ban the selected peers?)QBT_TR[CONTEXT=PeerListWidget]")) { if (confirm("QBT_TR(Are you sure you want to permanently ban the selected peers?)QBT_TR[CONTEXT=PeerListWidget]")) {
new Request({ fetch("api/v2/transfer/banPeers", {
url: "api/v2/transfer/banPeers", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hash": torrentsTable.getCurrentTorrentID(),
hash: torrentsTable.getCurrentTorrentID(), "peers": selectedPeers.join("|")
peers: selectedPeers.join("|") })
} });
}).send();
} }
} }
}, },

View file

@ -32,13 +32,17 @@ MochaUI.extend({
addUpLimitSlider: (hashes) => { addUpLimitSlider: (hashes) => {
if ($("uplimitSliderarea")) { if ($("uplimitSliderarea")) {
// Get global upload limit // Get global upload limit
fetch("api/v2/transfer/uploadLimit", {
method: "GET",
cache: "no-store"
})
.then(async (response) => {
if (!response.ok)
return;
const data = await response.text();
let maximum = 500; let maximum = 500;
new Request({
url: "api/v2/transfer/uploadLimit",
method: "get",
data: {},
onSuccess: (data) => {
if (data) {
const tmp = Number(data); const tmp = Number(data);
if (tmp > 0) { if (tmp > 0) {
maximum = tmp / 1024.0; maximum = tmp / 1024.0;
@ -49,7 +53,7 @@ MochaUI.extend({
else else
maximum = 1000; maximum = 1000;
} }
}
// Get torrents upload limit // Get torrents upload limit
// And create slider // And create slider
if (hashes[0] === "global") { if (hashes[0] === "global") {
@ -83,14 +87,18 @@ MochaUI.extend({
} }
} }
else { else {
new Request.JSON({ fetch("api/v2/torrents/uploadLimit", {
url: "api/v2/torrents/uploadLimit", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hashes": hashes.join("|")
hashes: hashes.join("|") })
}, })
onSuccess: (data) => { .then(async (response) => {
if (data) { if (!response.ok)
return;
const data = await response.json();
let up_limit = data[hashes[0]]; let up_limit = data[hashes[0]];
for (const key in data) { for (const key in data) {
if (up_limit !== data[key]) { if (up_limit !== data[key]) {
@ -124,25 +132,26 @@ MochaUI.extend({
$("uplimitUpdatevalue").value = (up_limit / 1024.0).round(); $("uplimitUpdatevalue").value = (up_limit / 1024.0).round();
$("upLimitUnit").style.visibility = "visible"; $("upLimitUnit").style.visibility = "visible";
} }
});
} }
} });
}).send();
}
}
}).send();
} }
}, },
addDlLimitSlider: (hashes) => { addDlLimitSlider: (hashes) => {
if ($("dllimitSliderarea")) { if ($("dllimitSliderarea")) {
// Get global upload limit // Get global upload limit
fetch("api/v2/transfer/downloadLimit", {
method: "GET",
cache: "no-store"
})
.then(async (response) => {
if (!response.ok)
return;
const data = await response.text();
let maximum = 500; let maximum = 500;
new Request({
url: "api/v2/transfer/downloadLimit",
method: "get",
data: {},
onSuccess: (data) => {
if (data) {
const tmp = Number(data); const tmp = Number(data);
if (tmp > 0) { if (tmp > 0) {
maximum = tmp / 1024.0; maximum = tmp / 1024.0;
@ -153,7 +162,7 @@ MochaUI.extend({
else else
maximum = 1000; maximum = 1000;
} }
}
// Get torrents download limit // Get torrents download limit
// And create slider // And create slider
if (hashes[0] === "global") { if (hashes[0] === "global") {
@ -187,14 +196,18 @@ MochaUI.extend({
} }
} }
else { else {
new Request.JSON({ fetch("api/v2/torrents/downloadLimit", {
url: "api/v2/torrents/downloadLimit", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hashes": hashes.join("|")
hashes: hashes.join("|") })
}, })
onSuccess: (data) => { .then(async (response) => {
if (data) { if (!response.ok)
return;
const data = await response.json();
let dl_limit = data[hashes[0]]; let dl_limit = data[hashes[0]];
for (const key in data) { for (const key in data) {
if (dl_limit !== data[key]) { if (dl_limit !== data[key]) {
@ -228,12 +241,9 @@ MochaUI.extend({
$("dllimitUpdatevalue").value = (dl_limit / 1024.0).round(); $("dllimitUpdatevalue").value = (dl_limit / 1024.0).round();
$("dlLimitUnit").style.visibility = "visible"; $("dlLimitUnit").style.visibility = "visible";
} }
});
} }
} });
}).send();
}
}
}).send();
} }
} }
}); });

View file

@ -45,21 +45,21 @@
return; return;
} }
const hashesList = new URI().getData("hashes"); fetch("api/v2/torrents/setLocation", {
new Request({ method: "POST",
url: "api/v2/torrents/setLocation", body: new URLSearchParams({
method: "post", "hashes": new URI().getData("hashes"),
data: { "location": location
hashes: hashesList, })
location: location })
}, .then(async (response) => {
onSuccess: () => { if (!response.ok) {
window.parent.qBittorrent.Client.closeFrameWindow(window); $("error_div").textContent = await response.text();
}, return;
onFailure: (xhr) => {
$("error_div").textContent = xhr.response;
} }
}).send();
window.parent.qBittorrent.Client.closeFrameWindow(window);
});
}); });
}); });
</script> </script>

View file

@ -100,19 +100,21 @@
return; return;
} }
new Request({ fetch("api/v2/torrents/setShareLimits", {
url: "api/v2/torrents/setShareLimits", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hashes": hashesList.join("|"),
hashes: hashesList.join("|"), "ratioLimit": ratioLimitValue,
ratioLimit: ratioLimitValue, "seedingTimeLimit": seedingTimeLimitValue,
seedingTimeLimit: seedingTimeLimitValue, "inactiveSeedingTimeLimit": inactiveSeedingTimeLimitValue
inactiveSeedingTimeLimit: inactiveSeedingTimeLimitValue })
}, })
onComplete: () => { .then(async (response) => {
if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
}); });
}); });

View file

@ -50,30 +50,34 @@
const setUpLimit = () => { const setUpLimit = () => {
const limit = Number($("uplimitUpdatevalue").value) * 1024; const limit = Number($("uplimitUpdatevalue").value) * 1024;
if (hashes[0] === "global") { if (hashes[0] === "global") {
new Request({ fetch("api/v2/transfer/setUploadLimit", {
url: "api/v2/transfer/setUploadLimit", method: "POST",
method: "post", body: new URLSearchParams({
data: {
"limit": limit "limit": limit
}, })
onComplete: () => { })
.then((response) => {
if (!response.ok)
return;
window.parent.updateMainData(); window.parent.updateMainData();
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
} }
else { else {
new Request({ fetch("api/v2/torrents/setUploadLimit", {
url: "api/v2/torrents/setUploadLimit", method: "POST",
method: "post", body: new URLSearchParams({
data: {
"hashes": hashes.join("|"), "hashes": hashes.join("|"),
"limit": limit "limit": limit
}, })
onComplete: () => { })
.then((response) => {
if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} });
}).send();
} }
}; };

View file

@ -26,21 +26,22 @@
cancelButton.addEventListener("click", (e) => { window.qBittorrent.Client.closeWindow(windowEl); }); cancelButton.addEventListener("click", (e) => { window.qBittorrent.Client.closeWindow(windowEl); });
confirmButton.addEventListener("click", (e) => { confirmButton.addEventListener("click", (e) => {
new Request({ fetch("api/v2/torrents/setAutoManagement", {
url: "api/v2/torrents/setAutoManagement", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hashes": hashes.join("|"),
hashes: hashes.join("|"), "enable": enable
enable: enable })
}, })
onSuccess: () => { .then((response) => {
if (!response.ok) {
alert("QBT_TR(Unable to set Auto Torrent Management for the selected torrents.)QBT_TR[CONTEXT=HttpServer]");
return;
}
updateMainData(); updateMainData();
window.qBittorrent.Client.closeWindow(windowEl); window.qBittorrent.Client.closeWindow(windowEl);
}, });
onFailure: () => {
alert("QBT_TR(Unable to set Auto Torrent Management for the selected torrents.)QBT_TR[CONTEXT=HttpServer]");
}
}).send();
}); });
// set tabindex so window element receives keydown events // set tabindex so window element receives keydown events

View file

@ -28,20 +28,21 @@
window.qBittorrent.Client.closeWindow(document.getElementById("confirmRecheckDialog")); window.qBittorrent.Client.closeWindow(document.getElementById("confirmRecheckDialog"));
}); });
confirmButton.addEventListener("click", (e) => { confirmButton.addEventListener("click", (e) => {
new Request({ fetch("api/v2/torrents/recheck", {
url: "api/v2/torrents/recheck", method: "POST",
method: "post", body: new URLSearchParams({
data: { "hashes": hashes.join("|")
hashes: hashes.join("|"), })
}, })
onSuccess: () => { .then((response) => {
if (!response.ok) {
alert("QBT_TR(Unable to recheck torrents.)QBT_TR[CONTEXT=HttpServer]");
return;
}
updateMainData(); updateMainData();
window.qBittorrent.Client.closeWindow(document.getElementById("confirmRecheckDialog")); window.qBittorrent.Client.closeWindow(document.getElementById("confirmRecheckDialog"));
}, });
onFailure: () => {
alert("QBT_TR(Unable to recheck torrents.)QBT_TR[CONTEXT=HttpServer]");
}
}).send();
}); });
// set tabindex so window element receives keydown events // set tabindex so window element receives keydown events

View file

@ -77,23 +77,24 @@
? torrentsTable.getFilteredTorrentsHashes(selectedStatus, selectedCategory, selectedTag, selectedTracker) ? torrentsTable.getFilteredTorrentsHashes(selectedStatus, selectedCategory, selectedTag, selectedTracker)
: torrentsTable.selectedRowsIds(); : torrentsTable.selectedRowsIds();
new Request({ fetch("api/v2/torrents/delete", {
url: "api/v2/torrents/delete", method: "POST",
method: "post", body: new URLSearchParams({
data: {
"hashes": hashes.join("|"), "hashes": hashes.join("|"),
"deleteFiles": deleteCB.checked "deleteFiles": deleteCB.checked
}, })
onSuccess: () => { })
.then((response) => {
if (!response.ok) {
alert("QBT_TR(Unable to delete torrents.)QBT_TR[CONTEXT=HttpServer]");
return;
}
torrentsTable.deselectAll(); torrentsTable.deselectAll();
updateMainData(); updateMainData();
updatePropertiesPanel(); updatePropertiesPanel();
window.qBittorrent.Client.closeWindow(document.getElementById("confirmDeletionPage")); window.qBittorrent.Client.closeWindow(document.getElementById("confirmDeletionPage"));
}, });
onFailure: () => {
alert("QBT_TR(Unable to delete torrents.)QBT_TR[CONTEXT=HttpServer]");
},
}).send();
}); });
})(); })();
</script> </script>

View file

@ -356,48 +356,51 @@
url.setData("last_known_id", tableInfo[curTab].last_id); url.setData("last_known_id", tableInfo[curTab].last_id);
tableInfo[curTab].progress = true; tableInfo[curTab].progress = true;
new Request.JSON({ fetch(url, {
url: url, method: "GET",
method: "get", cache: "no-store"
noCache: true, })
onFailure: (response) => { .then(async (response) => {
if (!response.ok) {
const errorDiv = $("error_div"); const errorDiv = $("error_div");
if (errorDiv) if (errorDiv)
errorDiv.textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]"; errorDiv.textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]";
tableInfo[curTab].progress = false; tableInfo[curTab].progress = false;
syncLogWithInterval(10000); syncLogWithInterval(10000);
}, return;
onSuccess: (response) => { }
$("error_div").textContent = ""; $("error_div").textContent = "";
if ($("logTabColumn").classList.contains("invisible")) if ($("logTabColumn").classList.contains("invisible"))
return; return;
if (response.length > 0) { const responseJSON = await response.json();
if (responseJSON.length > 0) {
clearTimeout(logFilterTimer); clearTimeout(logFilterTimer);
logFilterTimer = -1; logFilterTimer = -1;
for (let i = 0; i < response.length; ++i) { for (let i = 0; i < responseJSON.length; ++i) {
let row; let row;
if (curTab === "main") { if (curTab === "main") {
row = { row = {
rowId: response[i].id, rowId: responseJSON[i].id,
message: response[i].message, message: responseJSON[i].message,
timestamp: response[i].timestamp, timestamp: responseJSON[i].timestamp,
type: response[i].type, type: responseJSON[i].type,
}; };
} }
else { else {
row = { row = {
rowId: response[i].id, rowId: responseJSON[i].id,
ip: response[i].ip, ip: responseJSON[i].ip,
timestamp: response[i].timestamp, timestamp: responseJSON[i].timestamp,
blocked: response[i].blocked, blocked: responseJSON[i].blocked,
reason: response[i].reason, reason: responseJSON[i].reason,
}; };
} }
tableInfo[curTab].instance.updateRowData(row); tableInfo[curTab].instance.updateRowData(row);
tableInfo[curTab].last_id = Math.max(Number(response[i].id), tableInfo[curTab].last_id); tableInfo[curTab].last_id = Math.max(Number(responseJSON[i].id), tableInfo[curTab].last_id);
} }
tableInfo[curTab].instance.updateTable(); tableInfo[curTab].instance.updateTable();
@ -406,8 +409,7 @@
tableInfo[curTab].progress = false; tableInfo[curTab].progress = false;
syncLogWithInterval(getSyncLogDataInterval()); syncLogWithInterval(getSyncLogDataInterval());
} });
}).send();
}; };
new ClipboardJS(".copyLogDataToClipboard", { new ClipboardJS(".copyLogDataToClipboard", {