web/server-info: remove turnstile in more cases

This commit is contained in:
wukko 2024-11-23 19:14:14 +06:00
parent 601597eb15
commit d4044e3350
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -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;
}