Skip to content

Commit

Permalink
WebUI: migrate to fetch API
Browse files Browse the repository at this point in the history
And away from mootools.

PR #22037.
  • Loading branch information
Chocobo1 authored Dec 22, 2024
1 parent 9709672 commit a841fe9
Show file tree
Hide file tree
Showing 34 changed files with 884 additions and 807 deletions.
27 changes: 14 additions & 13 deletions src/webui/www/private/addpeers.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@
if (peers.length === 0)
return;

new Request({
url: "api/v2/torrents/addPeers",
method: "post",
data: {
hashes: hash,
peers: peers.join("|")
},
onFailure: () => {
alert("QBT_TR(Unable to add peers. Please ensure you are adhering to the IP:port format.)QBT_TR[CONTEXT=HttpServer]");
},
onSuccess: () => {
fetch("api/v2/torrents/addPeers", {
method: "POST",
body: new URLSearchParams({
"hashes": hash,
"peers": peers.join("|")
})
})
.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]");
return;
}

window.parent.qBittorrent.Client.closeFrameWindow(window);
}
}).send();
});
});
});
</script>
Expand Down
23 changes: 12 additions & 11 deletions src/webui/www/private/addtrackers.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@
e.preventDefault();
e.stopPropagation();

const hash = new URI().getData("hash");
new Request({
url: "api/v2/torrents/addTrackers",
method: "post",
data: {
hash: hash,
urls: $("trackersUrls").value
},
onComplete: () => {
fetch("api/v2/torrents/addTrackers", {
method: "POST",
body: new URLSearchParams({
"hash": new URI().getData("hash"),
"urls": $("trackersUrls").value
})
})
.then((response) => {
if (!response.ok)
return;

window.parent.qBittorrent.Client.closeFrameWindow(window);
}
}).send();
});
});
});
</script>
Expand Down
24 changes: 13 additions & 11 deletions src/webui/www/private/addwebseeds.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@
$("urls").focus();
$("addWebSeedsButton").addEventListener("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: () => {

fetch("api/v2/torrents/addWebSeeds", {
method: "POST",
body: new URLSearchParams({
"hash": new URI().getData("hash"),
"urls": $("urls").value.split("\n").map(w => encodeURIComponent(w.trim())).filter(w => (w.length > 0)).join("|")
})
})
.then((response) => {
if (!response.ok)
return;

window.parent.qBittorrent.Client.closeFrameWindow(window);
}
}).send();
});
});
});
</script>
Expand Down
20 changes: 11 additions & 9 deletions src/webui/www/private/confirmfeeddeletion.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@

let completionCount = 0;
paths.forEach((path) => {
new Request({
url: "api/v2/rss/removeItem",
method: "post",
data: {
path: decodeURIComponent(path)
},
onComplete: (response) => {
fetch("api/v2/rss/removeItem", {
method: "POST",
body: new URLSearchParams({
"path": decodeURIComponent(path)
})
})
.then((response) => {
if (!response.ok)
return;

++completionCount;
if (completionCount === paths.length) {
window.parent.qBittorrent.Rss.updateRssFeedList();
window.parent.qBittorrent.Client.closeFrameWindow(window);
}
}
}).send();
});
});
});
});
Expand Down
20 changes: 11 additions & 9 deletions src/webui/www/private/confirmruledeletion.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@

let completionCount = 0;
rules.forEach((rule) => {
new Request({
url: "api/v2/rss/removeRule",
method: "post",
data: {
ruleName: decodeURIComponent(rule)
},
onComplete: (response) => {
fetch("api/v2/rss/removeRule", {
method: "POST",
body: new URLSearchParams({
"ruleName": decodeURIComponent(rule)
})
})
.then((response) => {
if (!response.ok)
return;

++completionCount;
if (completionCount === rules.length) {
window.parent.qBittorrent.RssDownloader.updateRulesList();
window.parent.qBittorrent.Client.closeFrameWindow(window);
}
}
}).send();
});
});
});
});
Expand Down
24 changes: 13 additions & 11 deletions src/webui/www/private/confirmtrackerdeletion.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@
});
$("confirmBtn").addEventListener("click", (e) => {
e.stopPropagation();
const cmd = "api/v2/torrents/removeTrackers";
new Request({
url: cmd,
method: "post",
data: {
hash: "*",
urls: urls,
},
onComplete: () => {

fetch("api/v2/torrents/removeTrackers", {
method: "POST",
body: new URLSearchParams({
"hash": "*",
"urls": urls
})
})
.then((response) => {
if (!response.ok)
return;

window.parent.qBittorrent.Client.closeFrameWindow(window);
}
}).send();
});
});
});
</script>
Expand Down
42 changes: 23 additions & 19 deletions src/webui/www/private/downloadlimit.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,34 @@
const setDlLimit = () => {
const limit = Number($("dllimitUpdatevalue").value) * 1024;
if (hashes[0] === "global") {
new Request({
url: "api/v2/transfer/setDownloadLimit",
method: "post",
data: {
"limit": limit
},
onComplete: () => {
fetch("api/v2/transfer/setDownloadLimit", {
method: "POST",
body: new URLSearchParams({
"limit": limit
})
})
.then(async (response) => {
if (!response.ok)
return;

window.parent.updateMainData();
window.parent.qBittorrent.Client.closeFrameWindow(window);
}
}).send();
});
}
else {
new Request({
url: "api/v2/torrents/setDownloadLimit",
method: "post",
data: {
"hashes": hashes.join("|"),
"limit": limit
},
onComplete: () => {
fetch("api/v2/torrents/setDownloadLimit", {
method: "POST",
body: new URLSearchParams({
"hashes": hashes.join("|"),
"limit": limit
})
})
.then(async (response) => {
if (!response.ok)
return;

window.parent.qBittorrent.Client.closeFrameWindow(window);
}
}).send();
});
}
};

Expand Down
34 changes: 17 additions & 17 deletions src/webui/www/private/editfeedurl.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@

$("submitButton").disabled = true;

new Request({
url: "api/v2/rss/setFeedURL",
method: "post",
data: {
path: new URI().getData("path"),
url: newUrl
},
onSuccess: (response) => {
fetch("api/v2/rss/setFeedURL", {
method: "POST",
body: new URLSearchParams({
"path": new URI().getData("path"),
"url": newUrl
})
})
.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.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>
Expand Down
25 changes: 13 additions & 12 deletions src/webui/www/private/edittracker.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@
e.preventDefault();
e.stopPropagation();

const hash = new URI().getData("hash");
new Request({
url: "api/v2/torrents/editTracker",
method: "post",
data: {
hash: hash,
origUrl: currentUrl,
newUrl: $("trackerUrl").value
},
onComplete: () => {
fetch("api/v2/torrents/editTracker", {
method: "POST",
body: new URLSearchParams({
"hash": new URI().getData("hash"),
"origUrl": currentUrl,
"newUrl": $("trackerUrl").value
})
})
.then((response) => {
if (!response.ok)
return;

window.parent.qBittorrent.Client.closeFrameWindow(window);
}
}).send();
});
});
});
</script>
Expand Down
26 changes: 14 additions & 12 deletions src/webui/www/private/editwebseed.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@

$("editWebSeedButton").addEventListener("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: () => {

fetch("api/v2/torrents/editWebSeed", {
method: "POST",
body: new URLSearchParams({
"hash": new URI().getData("hash"),
"origUrl": origUrl,
"newUrl": encodeURIComponent($("url").value.trim())
})
})
.then((response) => {
if (!response.ok)
return;

window.parent.qBittorrent.Client.closeFrameWindow(window);
}
}).send();
});
});
});
</script>
Expand Down
Loading

0 comments on commit a841fe9

Please sign in to comment.