web/DownloadButton: check server info before main request

This commit is contained in:
wukko 2024-09-20 18:28:35 +06:00
parent 92008d3012
commit 819c7a4fa0
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -6,7 +6,7 @@
import { createDialog } from "$lib/dialogs"; import { createDialog } from "$lib/dialogs";
import { downloadFile } from "$lib/download"; import { downloadFile } from "$lib/download";
import { cachedInfo } from "$lib/api/server-info"; import { cachedInfo, getServerInfo } from "$lib/api/server-info";
import { turnstileLoaded } from "$lib/state/turnstile"; import { turnstileLoaded } from "$lib/state/turnstile";
import type { DialogInfo } from "$lib/types/dialog"; import type { DialogInfo } from "$lib/types/dialog";
@ -66,6 +66,17 @@
export const download = async (link: string) => { export const download = async (link: string) => {
changeDownloadButton("think"); changeDownloadButton("think");
await getServerInfo();
if (!$cachedInfo) {
changeDownloadButton("error");
return createDialog({
...defaultErrorPopup,
bodyText: $t("error.api.unreachable"),
});
}
if ($cachedInfo?.info?.cobalt?.turnstileSitekey && !$turnstileLoaded) { if ($cachedInfo?.info?.cobalt?.turnstileSitekey && !$turnstileLoaded) {
changeDownloadButton("error"); changeDownloadButton("error");