Skip to content

armgit / VERT

Public Imported from GitHub
0

The next-generation file converter. Open source, fully local* and free forever.

feat: abort controller on vertd

not-nullptr1615cf3acf81
diff --git a/src/lib/sections/settings/Vertd.svelte b/src/lib/sections/settings/Vertd.svelte
index 185269e..9e2f054 100644
--- a/src/lib/sections/settings/Vertd.svelte
+++ b/src/lib/sections/settings/Vertd.svelte
@@ -8,25 +8,30 @@
import clsx from "clsx";
let vertdCommit = $state<string | null>(null);
+ let abortController: AbortController | null = null;
+
const { settings }: { settings: Settings } = $props();
$effect(() => {
if (settings.settings.vertdURL) {
+ if (abortController) abortController.abort();
+ abortController = new AbortController();
+ const { signal } = abortController;
+
vertdCommit = "loading";
- fetch(`${settings.settings.vertdURL}/api/version`)
+ fetch(`${settings.settings.vertdURL}/api/version`, { signal })
.then((res) => {
- if (res.ok) {
- res.json().then((data) => {
- vertdCommit = data.data;
- });
- } else {
- vertdCommit = null;
- }
+ if (!res.ok) throw new Error("bad response");
+ return res.json();
+ })
+ .then((data) => {
+ vertdCommit = data.data;
})
- .catch(() => {
- vertdCommit = null;
+ .catch((err) => {
+ if (err.name !== "AbortError") vertdCommit = null;
});
} else {
+ if (abortController) abortController.abort();
vertdCommit = null;
}
});