mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-28 02:26:10 +00:00
web/server-info: remove turnstile in more cases
This commit is contained in:
parent
601597eb15
commit
d4044e3350
|
@ -2,6 +2,7 @@ import { browser } from "$app/environment";
|
||||||
|
|
||||||
import { get, writable } from "svelte/store";
|
import { get, writable } from "svelte/store";
|
||||||
import { currentApiURL } from "$lib/api/api-url";
|
import { currentApiURL } from "$lib/api/api-url";
|
||||||
|
import { turnstileCreated, turnstileEnabled, turnstileSolved } from "$lib/state/turnstile";
|
||||||
|
|
||||||
import type { CobaltServerInfoResponse, CobaltErrorResponse, CobaltServerInfo } from "$lib/types/api";
|
import type { CobaltServerInfoResponse, CobaltErrorResponse, CobaltServerInfo } from "$lib/types/api";
|
||||||
|
|
||||||
|
@ -34,10 +35,18 @@ const request = async () => {
|
||||||
return response;
|
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 () => {
|
export const getServerInfo = async () => {
|
||||||
const cache = get(cachedInfo);
|
const cache = get(cachedInfo);
|
||||||
|
|
||||||
if (cache && cache.origin === currentApiURL()) {
|
if (cache && cache.origin === currentApiURL()) {
|
||||||
|
reloadIfTurnstileDisabled();
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,10 +63,12 @@ export const getServerInfo = async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// reload the page if turnstile sitekey changed
|
// reload the page if turnstile sitekey changed
|
||||||
if (cache && cache?.info?.cobalt?.turnstileSitekey !== freshInfo?.cobalt?.turnstileSitekey) {
|
if (browser && get(turnstileEnabled) && cache && cache?.info?.cobalt?.turnstileSitekey !== freshInfo?.cobalt?.turnstileSitekey) {
|
||||||
if (browser) window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reloadIfTurnstileDisabled();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue