web/PickerItem: make sure the item url is valid

This commit is contained in:
wukko 2025-02-11 15:29:23 +06:00
parent 366279a3bc
commit f76d40bec4
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -14,18 +14,28 @@
export let number: number;
let imageLoaded = false;
const isTunnel = new URL(item.url).pathname === "/tunnel";
let validUrl = false;
try {
new URL(item.url);
validUrl = true;
} catch {}
const isTunnel = validUrl && new URL(item.url).pathname === "/tunnel";
$: itemType = item.type ?? "photo";
</script>
<button
class="picker-item"
on:click={() =>
on:click={() => {
if (validUrl) {
downloadFile({
url: item.url,
urlType: isTunnel ? "tunnel" : "redirect",
})}
});
}
}}
>
<div class="picker-type">
{#if itemType === "video"}