From dcf7b4e794f8eda6915d4a58e5e84a56d91724b2 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 22 Mar 2026 10:29:37 +0100 Subject: [PATCH] Properly use https server url when redirect to --- front/src/primitives/utils/hover.ts | 1 + front/src/providers/account-provider.tsx | 1 + front/src/providers/settings.ts | 1 + front/src/ui/login/server-url.tsx | 33 ++++++++++++++++-------- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/front/src/primitives/utils/hover.ts b/front/src/primitives/utils/hover.ts index 469826e4..2dd49b83 100644 --- a/front/src/primitives/utils/hover.ts +++ b/front/src/primitives/utils/hover.ts @@ -7,6 +7,7 @@ let hoverTimeout: NodeJS.Timeout | number; export const useMobileHover = () => { if (Platform.OS !== "web") return; + // biome-ignore lint/correctness/useHookAtTopLevel: const condition useEffect(() => { const enableHover = () => { if (preventHover) return; diff --git a/front/src/providers/account-provider.tsx b/front/src/providers/account-provider.tsx index 4e540851..4d120677 100644 --- a/front/src/providers/account-provider.tsx +++ b/front/src/providers/account-provider.tsx @@ -31,6 +31,7 @@ export const AccountProvider = ({ children }: { children: ReactNode }) => { const router = useRouter(); if (Platform.OS !== "web") { + // biome-ignore lint/correctness/useHookAtTopLevel: static useEffect(() => { if (!ret.apiUrl) { setTimeout(() => { diff --git a/front/src/providers/settings.ts b/front/src/providers/settings.ts index da004b72..2395a22b 100644 --- a/front/src/providers/settings.ts +++ b/front/src/providers/settings.ts @@ -71,6 +71,7 @@ export const readValue = (key: string, parser: T) => { export const useLocalSetting = (setting: string, def: T) => { if (Platform.OS === "web" && typeof window === "undefined") return [def as T, null!] as const; + // biome-ignore lint/correctness/useHookAtTopLevel: ssr const [val, setter] = useMMKVString(`settings.${setting}`, storage); return [(val ?? def) as T, setter] as const; }; diff --git a/front/src/ui/login/server-url.tsx b/front/src/ui/login/server-url.tsx index 52881f8c..f9bff7c5 100644 --- a/front/src/ui/login/server-url.tsx +++ b/front/src/ui/login/server-url.tsx @@ -1,8 +1,9 @@ +import { useQuery } from "@tanstack/react-query"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Platform, View } from "react-native"; +import { RetryableError } from "~/models/retryable-error"; import { Button, H1, Input, Link, P } from "~/primitives"; -import { type QueryIdentifier, useFetch } from "~/query"; export const cleanApiUrl = (apiUrl: string) => { if (Platform.OS === "web") return undefined; @@ -13,9 +14,24 @@ export const cleanApiUrl = (apiUrl: string) => { export const ServerUrlPage = () => { const [_apiUrl, setApiUrl] = useState(""); const apiUrl = cleanApiUrl(_apiUrl); - const { data, error } = useFetch({ - ...ServerUrlPage.query, - options: { apiUrl, authToken: null, returnError: true }, + const { data, error } = useQuery({ + queryKey: [apiUrl, "api", "health"], + queryFn: async (ctx) => { + try { + const apiUrl = "http://kyoo.sdg.moe"; + const resp = await fetch(`${apiUrl}/api/health`, { + method: "GET", + signal: ctx.signal, + }); + console.log(resp.url); + return resp.url.replace("/api/health", ""); + } catch (e) { + console.log("server select fetch error", e); + throw new RetryableError({ + key: "offline", + }); + } + }, }); const { t } = useTranslation(); @@ -43,14 +59,14 @@ export const ServerUrlPage = () => {