Skip to content

Commit

Permalink
WebUI: use native API for accessing query string
Browse files Browse the repository at this point in the history
PR #22141.
  • Loading branch information
Chocobo1 authored Jan 12, 2025
1 parent 11991e6 commit c622d50
Show file tree
Hide file tree
Showing 28 changed files with 294 additions and 205 deletions.
4 changes: 2 additions & 2 deletions src/webui/www/private/addpeers.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
}
});

const hash = new URI().getData("hash");
if (!hash)
const hash = new URLSearchParams(window.location.search).get("hash");
if (hash === null)
return;

$("peers").focus();
Expand Down
2 changes: 1 addition & 1 deletion src/webui/www/private/addtrackers.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
fetch("api/v2/torrents/addTrackers", {
method: "POST",
body: new URLSearchParams({
hash: new URI().getData("hash"),
hash: new URLSearchParams(window.location.search).get("hash"),
urls: $("trackersUrls").value
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/webui/www/private/addwebseeds.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
fetch("api/v2/torrents/addWebSeeds", {
method: "POST",
body: new URLSearchParams({
hash: new URI().getData("hash"),
hash: new URLSearchParams(window.location.search).get("hash"),
urls: $("urls").value.split("\n").map(w => encodeURIComponent(w.trim())).filter(w => (w.length > 0)).join("|")
})
})
Expand Down
6 changes: 3 additions & 3 deletions src/webui/www/private/confirmfeeddeletion.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"use strict";

window.addEventListener("DOMContentLoaded", () => {
const paths = new URI().getData("paths").split("|");
$("cancelBtn").focus();
$("cancelBtn").addEventListener("click", (e) => {
e.preventDefault();
Expand All @@ -25,7 +24,8 @@
e.stopPropagation();

let completionCount = 0;
paths.forEach((path) => {
const paths = new URLSearchParams(window.location.search).get("paths").split("|");
for (const path of paths) {
fetch("api/v2/rss/removeItem", {
method: "POST",
body: new URLSearchParams({
Expand All @@ -42,7 +42,7 @@
window.parent.qBittorrent.Client.closeFrameWindow(window);
}
});
});
}
});
});
</script>
Expand Down
7 changes: 3 additions & 4 deletions src/webui/www/private/confirmruleclear.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
"use strict";

window.addEventListener("DOMContentLoaded", () => {
const rules = new URI().getData("rules").split("|");

$("cancelBtn").focus();
$("cancelBtn").addEventListener("click", (e) => {
e.preventDefault();
Expand All @@ -26,15 +24,16 @@
e.stopPropagation();

let completionCount = 0;
rules.forEach((rule) => {
const rules = new URLSearchParams(window.location.search).get("rules").split("|");
for (const rule of rules) {
window.parent.qBittorrent.RssDownloader.modifyRuleState(decodeURIComponent(rule), "previouslyMatchedEpisodes", [], () => {
++completionCount;
if (completionCount === rules.length) {
window.parent.qBittorrent.RssDownloader.updateRulesList();
window.parent.qBittorrent.Client.closeFrameWindow(window);
}
});
});
}
});
});
</script>
Expand Down
7 changes: 3 additions & 4 deletions src/webui/www/private/confirmruledeletion.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
"use strict";

window.addEventListener("DOMContentLoaded", () => {
const rules = new URI().getData("rules").split("|");

$("cancelBtn").focus();
$("cancelBtn").addEventListener("click", (e) => {
e.preventDefault();
Expand All @@ -26,7 +24,8 @@
e.stopPropagation();

let completionCount = 0;
rules.forEach((rule) => {
const rules = new URLSearchParams(window.location.search).get("rules").split("|");
for (const rule of rules) {
fetch("api/v2/rss/removeRule", {
method: "POST",
body: new URLSearchParams({
Expand All @@ -43,7 +42,7 @@
window.parent.qBittorrent.Client.closeFrameWindow(window);
}
});
});
}
});
});
</script>
Expand Down
9 changes: 5 additions & 4 deletions src/webui/www/private/confirmtrackerdeletion.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"use strict";

window.addEventListener("DOMContentLoaded", () => {
const host = new URI().getData("host");
const urls = new URI().getData("urls");
$("confirmDeleteTrackerText").textContent = "QBT_TR(Are you sure you want to remove tracker %1 from all torrents?)QBT_TR[CONTEXT=TrackersFilterWidget]".replace("%1", `"${host}"`);
const searchParams = new URLSearchParams(window.location.search);
const host = searchParams.get("host");

$("confirmDeleteTrackerText").textContent = "QBT_TR(Are you sure you want to remove tracker %1 from all torrents?)QBT_TR[CONTEXT=TrackersFilterWidget]".replace("%1", host);

$("cancelBtn").focus();
$("cancelBtn").addEventListener("click", (e) => {
Expand All @@ -29,7 +30,7 @@
method: "POST",
body: new URLSearchParams({
hash: "*",
urls: urls
urls: searchParams.get("urls")
})
})
.then((response) => {
Expand Down
11 changes: 4 additions & 7 deletions src/webui/www/private/download.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,10 @@ <h2><label for="urls">QBT_TR(Add torrent links)QBT_TR[CONTEXT=AddNewTorrentDialo
<script>
"use strict";

const encodedUrls = new URI().getData("urls");
if (encodedUrls) {
const urls = encodedUrls.split("|").map((url) => {
return decodeURIComponent(url);
});

if (urls.length)
const encodedUrls = new URLSearchParams(window.location.search).get("urls");
if (encodedUrls !== null) {
const urls = encodedUrls.split("|").map(decodeURIComponent);
if (urls.length > 0)
$("urls").value = urls.join("\n");
}

Expand Down
2 changes: 1 addition & 1 deletion src/webui/www/private/downloadlimit.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}
});

const hashes = new URI().getData("hashes").split("|");
const hashes = new URLSearchParams(window.location.search).get("hashes").split("|");
const setDlLimit = () => {
const limit = Number($("dllimitUpdatevalue").value) * 1024;
if (hashes[0] === "global") {
Expand Down
5 changes: 3 additions & 2 deletions src/webui/www/private/editfeedurl.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
}
});

const currentUrl = new URI().getData("url");
const searchParams = new URLSearchParams(window.location.search);
const currentUrl = searchParams.get("url");

$("url").value = currentUrl;
$("url").focus();
Expand All @@ -54,7 +55,7 @@
fetch("api/v2/rss/setFeedURL", {
method: "POST",
body: new URLSearchParams({
path: new URI().getData("path"),
path: searchParams.get("path"),
url: newUrl
})
})
Expand Down
7 changes: 4 additions & 3 deletions src/webui/www/private/edittracker.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
}
});

const currentUrl = new URI().getData("url");
if (!currentUrl)
const searchParams = new URLSearchParams(window.location.search);
const currentUrl = searchParams.get("url");
if (currentUrl === null)
return;

$("trackerUrl").value = currentUrl;
Expand All @@ -40,7 +41,7 @@
fetch("api/v2/torrents/editTracker", {
method: "POST",
body: new URLSearchParams({
hash: new URI().getData("hash"),
hash: searchParams.get("hash"),
origUrl: currentUrl,
newUrl: $("trackerUrl").value
})
Expand Down
5 changes: 3 additions & 2 deletions src/webui/www/private/editwebseed.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
}
});

const origUrl = new URI().getData("url");
const searchParams = new URLSearchParams(window.location.search);
const origUrl = searchParams.get("url");
$("url").value = decodeURIComponent(origUrl);
$("url").focus();

Expand All @@ -36,7 +37,7 @@
fetch("api/v2/torrents/editWebSeed", {
method: "POST",
body: new URLSearchParams({
hash: new URI().getData("hash"),
hash: searchParams.get("hash"),
origUrl: origUrl,
newUrl: encodeURIComponent($("url").value.trim())
})
Expand Down
9 changes: 5 additions & 4 deletions src/webui/www/private/newcategory.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
}
});

const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData("action"));
const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData("hashes"));
const uriCategoryName = window.qBittorrent.Misc.safeTrim(new URI().getData("categoryName"));
const uriSavePath = window.qBittorrent.Misc.safeTrim(new URI().getData("savePath"));
const searchParams = new URLSearchParams(window.location.search);
const uriAction = window.qBittorrent.Misc.safeTrim(searchParams.get("action"));
const uriHashes = window.qBittorrent.Misc.safeTrim(searchParams.get("hashes"));
const uriCategoryName = window.qBittorrent.Misc.safeTrim(searchParams.get("categoryName"));
const uriSavePath = window.qBittorrent.Misc.safeTrim(searchParams.get("savePath"));

if (uriAction === "edit") {
if (!uriCategoryName)
Expand Down
4 changes: 2 additions & 2 deletions src/webui/www/private/newfeed.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
});

$("feedURL").focus();
const path = new URI().getData("path");
$("submitButton").addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
Expand All @@ -42,11 +41,12 @@

$("submitButton").disabled = true;

const path = new URLSearchParams(window.location.search).get("path");
fetch("api/v2/rss/addFeed", {
method: "POST",
body: new URLSearchParams({
url: feedURL,
path: path ? (path + "\\" + feedURL) : ""
path: (((path !== null) && (path.length > 0)) ? `${path}\\${feedURL}` : "")
})
})
.then(async (response) => {
Expand Down
4 changes: 2 additions & 2 deletions src/webui/www/private/newfolder.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
});

$("folderName").focus();
const path = new URI().getData("path");
$("submitButton").addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
Expand All @@ -43,10 +42,11 @@

$("submitButton").disabled = true;

const path = new URLSearchParams(window.location.search).get("path");
fetch("api/v2/rss/addFolder", {
method: "POST",
body: new URLSearchParams({
path: path ? (path + "\\" + folderName) : folderName
path: (((path !== null) && (path.length > 0)) ? `${path}\\${folderName}` : folderName)
})
})
.then(async (response) => {
Expand Down
10 changes: 6 additions & 4 deletions src/webui/www/private/newtag.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
}
});

const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData("action"));
const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData("hashes"));
const searchParams = new URLSearchParams(window.location.search);
const uriAction = window.qBittorrent.Misc.safeTrim(searchParams.get("action"));

if (uriAction === "create")
$("legendText").textContent = "QBT_TR(Tag:)QBT_TR[CONTEXT=TagFilterWidget]";
Expand All @@ -52,8 +52,9 @@
};

switch (uriAction) {
case "set":
if (uriHashes === "")
case "set": {
const uriHashes = window.qBittorrent.Misc.safeTrim(searchParams.get("hashes"));
if ((uriHashes === null) || (uriHashes.length <= 0))
return;

fetch("api/v2/torrents/addTags", {
Expand All @@ -70,6 +71,7 @@
window.parent.qBittorrent.Client.closeFrameWindow(window);
});
break;
}

case "create":
if (!verifyTagName(tagName))
Expand Down
9 changes: 5 additions & 4 deletions src/webui/www/private/rename.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
}
});

const name = new URI().getData("name");
const searchParams = new URLSearchParams(window.location.search);
const name = searchParams.get("name");
// set text field to current value
if (name)
if (name !== null)
$("rename").value = name;

$("rename").focus();
Expand All @@ -42,8 +43,8 @@
if ((name === null) || (name === ""))
return;

const hash = new URI().getData("hash");
if (hash) {
const hash = searchParams.get("hash");
if (hash !== null) {
fetch("api/v2/torrents/rename", {
method: "POST",
body: new URLSearchParams({
Expand Down
2 changes: 1 addition & 1 deletion src/webui/www/private/rename_feed.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
});

const oldPath = new URI().getData("oldPath");
const oldPath = new URLSearchParams(window.location.search).get("oldPath");

$("rename").value = oldPath;
$("rename").focus();
Expand Down
7 changes: 4 additions & 3 deletions src/webui/www/private/rename_file.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
}
});

const hash = new URI().getData("hash");
const oldPath = new URI().getData("path");
const isFolder = ((new URI().getData("isFolder")) === "true");
const searchParams = new URLSearchParams(window.location.search);
const hash = searchParams.get("hash");
const oldPath = searchParams.get("path");
const isFolder = ((searchParams.get("isFolder")) === "true");

const oldName = window.qBittorrent.Filesystem.fileName(oldPath);
$("rename").value = oldName;
Expand Down
2 changes: 1 addition & 1 deletion src/webui/www/private/rename_rule.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
});

const oldName = new URI().getData("rule");
const oldName = new URLSearchParams(window.location.search).get("rule");

$("rename").value = oldName;
$("rename").focus();
Expand Down
9 changes: 6 additions & 3 deletions src/webui/www/private/scripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,7 @@ window.addEventListener("DOMContentLoaded", () => {
icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Upload local torrent)QBT_TR[CONTEXT=HttpServer]",
loadMethod: "iframe",
contentURL: new URI("upload.html").toString(),
contentURL: "upload.html",
addClass: "windowFrame", // fixes iframe scrolling on iOS Safari
scrollbars: true,
maximizable: false,
Expand Down Expand Up @@ -1693,13 +1693,16 @@ window.addEventListener("DOMContentLoaded", () => {
return;

const id = "downloadPage";
const contentURI = new URI("download.html").setData("urls", urls.map(encodeURIComponent).join("|"));
const contentURL = new URL("download.html", window.location);
contentURL.search = new URLSearchParams({
urls: urls.map(encodeURIComponent).join("|")
});
new MochaUI.Window({
id: id,
icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Download from URLs)QBT_TR[CONTEXT=downloadFromURL]",
loadMethod: "iframe",
contentURL: contentURI.toString(),
contentURL: contentURL.toString(),
addClass: "windowFrame", // fixes iframe scrolling on iOS Safari
scrollbars: true,
maximizable: false,
Expand Down
Loading

0 comments on commit c622d50

Please sign in to comment.