From d4044e335026722195c4f52f69ef7da93be1dfef Mon Sep 17 00:00:00 2001 From: wukko Date: Sat, 23 Nov 2024 19:14:14 +0600 Subject: [PATCH] web/server-info: remove turnstile in more cases --- web/src/lib/api/server-info.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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; }