WebUI: migrate to fetch API

This is the final part of it.

PR #22072.
This commit is contained in:
Chocobo1
2024-12-29 15:44:28 +08:00
committed by GitHub
parent e740a42366
commit 9c0475ebfa
15 changed files with 626 additions and 551 deletions

View File

@@ -58,18 +58,23 @@ window.qBittorrent.PropWebseeds ??= (() => {
torrentWebseedsTable.clear();
current_hash = new_hash;
}
new Request.JSON({
url: new URI("api/v2/torrents/webseeds").setData("hash", current_hash),
method: "get",
noCache: true,
onComplete: () => {
clearTimeout(loadWebSeedsDataTimer);
loadWebSeedsDataTimer = loadWebSeedsData.delay(10000);
},
onSuccess: (webseeds) => {
const url = new URL("api/v2/torrents/webseeds", window.location);
url.search = new URLSearchParams({
hash: current_hash
});
fetch(url, {
method: "GET",
cache: "no-store"
})
.then(async (response) => {
if (!response.ok)
return;
const selectedWebseeds = torrentWebseedsTable.selectedRowsIds();
torrentWebseedsTable.clear();
const webseeds = await response.json();
if (webseeds) {
// Update WebSeeds data
webseeds.each((webseed) => {
@@ -84,8 +89,11 @@ window.qBittorrent.PropWebseeds ??= (() => {
if (selectedWebseeds.length > 0)
torrentWebseedsTable.reselectRows(selectedWebseeds);
}
}).send();
})
.finally(() => {
clearTimeout(loadWebSeedsDataTimer);
loadWebSeedsDataTimer = loadWebSeedsData.delay(10000);
});
};
const updateData = () => {
@@ -190,18 +198,19 @@ window.qBittorrent.PropWebseeds ??= (() => {
if (current_hash.length === 0)
return;
const selectedWebseeds = torrentWebseedsTable.selectedRowsIds();
new Request({
url: "api/v2/torrents/removeWebSeeds",
method: "post",
data: {
hash: current_hash,
urls: selectedWebseeds.map(webseed => encodeURIComponent(webseed)).join("|")
},
onSuccess: () => {
fetch("api/v2/torrents/removeWebSeeds", {
method: "POST",
body: new URLSearchParams({
hash: current_hash,
urls: torrentWebseedsTable.selectedRowsIds().map(webseed => encodeURIComponent(webseed)).join("|")
})
})
.then((response) => {
if (!response.ok)
return;
updateData();
}
}).send();
});
};
const clear = () => {