mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
web/DownloadButton: move server info cache checks to the api lib
This commit is contained in:
parent
5ba83f3d56
commit
dfaef913c4
2 changed files with 25 additions and 25 deletions
|
@ -6,9 +6,6 @@
|
||||||
import { createDialog } from "$lib/dialogs";
|
import { createDialog } from "$lib/dialogs";
|
||||||
import { downloadFile } from "$lib/download";
|
import { downloadFile } from "$lib/download";
|
||||||
|
|
||||||
import { cachedInfo, getServerInfo } from "$lib/api/server-info";
|
|
||||||
import { turnstileLoaded } from "$lib/state/turnstile";
|
|
||||||
|
|
||||||
import type { DialogInfo } from "$lib/types/dialog";
|
import type { DialogInfo } from "$lib/types/dialog";
|
||||||
|
|
||||||
export let url: string;
|
export let url: string;
|
||||||
|
@ -66,26 +63,6 @@
|
||||||
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) {
|
|
||||||
changeDownloadButton("error");
|
|
||||||
|
|
||||||
return createDialog({
|
|
||||||
...defaultErrorPopup,
|
|
||||||
bodyText: $t("error.captcha_ongoing"),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await API.request(link);
|
const response = await API.request(link);
|
||||||
|
|
||||||
if (!response) {
|
if (!response) {
|
||||||
|
|
|
@ -5,8 +5,9 @@ import lazySettingGetter from "$lib/settings/lazy-get";
|
||||||
|
|
||||||
import { getSession } from "$lib/api/session";
|
import { getSession } from "$lib/api/session";
|
||||||
import { currentApiURL } from "$lib/api/api-url";
|
import { currentApiURL } from "$lib/api/api-url";
|
||||||
import { cachedInfo } from "$lib/api/server-info";
|
import { turnstileLoaded } from "$lib/state/turnstile";
|
||||||
import { apiOverrideWarning } from "$lib/api/safety-warning";
|
import { apiOverrideWarning } from "$lib/api/safety-warning";
|
||||||
|
import { cachedInfo, getServerInfo } from "$lib/api/server-info";
|
||||||
|
|
||||||
import type { Optional } from "$lib/types/generic";
|
import type { Optional } from "$lib/types/generic";
|
||||||
import type { CobaltAPIResponse, CobaltErrorResponse } from "$lib/types/api";
|
import type { CobaltAPIResponse, CobaltErrorResponse } from "$lib/types/api";
|
||||||
|
@ -37,9 +38,31 @@ const request = async (url: string) => {
|
||||||
|
|
||||||
await apiOverrideWarning();
|
await apiOverrideWarning();
|
||||||
|
|
||||||
|
await getServerInfo();
|
||||||
|
|
||||||
|
const getCachedInfo = get(cachedInfo);
|
||||||
|
|
||||||
|
if (!getCachedInfo) {
|
||||||
|
return {
|
||||||
|
status: "error",
|
||||||
|
error: {
|
||||||
|
code: "error.api.unreachable"
|
||||||
|
}
|
||||||
|
} as CobaltErrorResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getCachedInfo?.info?.cobalt?.turnstileSitekey && !get(turnstileLoaded)) {
|
||||||
|
return {
|
||||||
|
status: "error",
|
||||||
|
error: {
|
||||||
|
code: "error.captcha_ongoing"
|
||||||
|
}
|
||||||
|
} as CobaltErrorResponse;
|
||||||
|
}
|
||||||
|
|
||||||
const api = currentApiURL();
|
const api = currentApiURL();
|
||||||
|
|
||||||
const session = get(cachedInfo)?.info?.cobalt?.turnstileSitekey
|
const session = getCachedInfo?.info?.cobalt?.turnstileSitekey
|
||||||
? await getSession() : undefined;
|
? await getSession() : undefined;
|
||||||
|
|
||||||
let extraHeaders = {}
|
let extraHeaders = {}
|
||||||
|
|
Loading…
Reference in a new issue