feat: abort controller on vertd

This commit is contained in:
not-nullptr 2025-02-09 02:56:29 +00:00
parent e2766f0121
commit 1615cf3acf
1 changed files with 15 additions and 10 deletions

View File

@ -8,25 +8,30 @@
import clsx from "clsx"; import clsx from "clsx";
let vertdCommit = $state<string | null>(null); let vertdCommit = $state<string | null>(null);
let abortController: AbortController | null = null;
const { settings }: { settings: Settings } = $props(); const { settings }: { settings: Settings } = $props();
$effect(() => { $effect(() => {
if (settings.settings.vertdURL) { if (settings.settings.vertdURL) {
if (abortController) abortController.abort();
abortController = new AbortController();
const { signal } = abortController;
vertdCommit = "loading"; vertdCommit = "loading";
fetch(`${settings.settings.vertdURL}/api/version`) fetch(`${settings.settings.vertdURL}/api/version`, { signal })
.then((res) => { .then((res) => {
if (res.ok) { if (!res.ok) throw new Error("bad response");
res.json().then((data) => { return res.json();
vertdCommit = data.data;
});
} else {
vertdCommit = null;
}
}) })
.catch(() => { .then((data) => {
vertdCommit = null; vertdCommit = data.data;
})
.catch((err) => {
if (err.name !== "AbortError") vertdCommit = null;
}); });
} else { } else {
if (abortController) abortController.abort();
vertdCommit = null; vertdCommit = null;
} }
}); });