Skip to content

best way to save what you love

web/server-info: remove turnstile in more cases

wukkod4044e335026
diff --git a/web/src/lib/api/server-info.ts b/web/src/lib/api/server-info.ts
index 0f36ceff..c0ceee31 100644
--- a/web/src/lib/api/server-info.ts
+++ b/web/src/lib/api/server-info.ts
@@ -2,6 +2,7 @@ import { browser } from "$app/environment";
import { get, writable } from "svelte/store";
import { currentApiURL } from "$lib/api/api-url";
+import { turnstileCreated, turnstileEnabled, turnstileSolved } from "$lib/state/turnstile";
import type { CobaltServerInfoResponse, CobaltErrorResponse, CobaltServerInfo } from "$lib/types/api";
@@ -34,10 +35,18 @@ const request = async () => {
return response;
}
+// reload the page if turnstile is now disabled, but was previously loaded and not solved
+const reloadIfTurnstileDisabled = () => {
+ if (browser && !get(turnstileEnabled) && get(turnstileCreated) && !get(turnstileSolved)) {
+ window.location.reload();
+ }
+}
+
export const getServerInfo = async () => {
const cache = get(cachedInfo);
if (cache && cache.origin === currentApiURL()) {
+ reloadIfTurnstileDisabled();
return true
}
@@ -54,10 +63,12 @@ export const getServerInfo = async () => {
});
// reload the page if turnstile sitekey changed
- if (cache && cache?.info?.cobalt?.turnstileSitekey !== freshInfo?.cobalt?.turnstileSitekey) {
- if (browser) window.location.reload();
+ if (browser && get(turnstileEnabled) && cache && cache?.info?.cobalt?.turnstileSitekey !== freshInfo?.cobalt?.turnstileSitekey) {
+ window.location.reload();
}
+ reloadIfTurnstileDisabled();
+
return true;
}