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
parent 9709672b34
commit a841fe9320
34 changed files with 888 additions and 811 deletions

View File

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