feat(settings): unify Streamystats + Marlin URL inputs via the resolver

- jellyfinProbe (/System/Info/Public, ProductName check) + reachabilityProbe (services with no health route).

- ServerUrlStatusText: compact resolver status for ListItem-row layouts.

- Streamystats + Marlin: resolve the URL on blur (https-first, http fallback) and store the canonical URL; inline status feedback.
This commit is contained in:
Gauvain
2026-06-04 20:44:39 +02:00
parent 0f29457ff8
commit b54b0c670b
6 changed files with 133 additions and 0 deletions

View File

@@ -11,12 +11,15 @@ import {
} from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { toast } from "sonner-native";
import { ServerUrlStatusText } from "@/components/common/ServerUrlStatusText";
import { Text } from "@/components/common/Text";
import { ListGroup } from "@/components/list/ListGroup";
import { ListItem } from "@/components/list/ListItem";
import DisabledSetting from "@/components/settings/DisabledSetting";
import { useNetworkAwareQueryClient } from "@/hooks/useNetworkAwareQueryClient";
import { useServerUrlResolver } from "@/hooks/useServerUrlResolver";
import { useSettings } from "@/utils/atoms/settings";
import { reachabilityProbe } from "@/utils/serverUrl/probes/reachability";
export default function MarlinSearchPage() {
const navigation = useNavigation();
@@ -29,6 +32,7 @@ export default function MarlinSearchPage() {
const queryClient = useNetworkAwareQueryClient();
const [value, setValue] = useState<string>(settings?.marlinServerUrl || "");
const urlResolver = useServerUrlResolver(reachabilityProbe);
const onSave = (val: string) => {
updateSettings({
@@ -127,8 +131,17 @@ export default function MarlinSearchPage() {
autoCapitalize='none'
textContentType='URL'
onChangeText={(text) => setValue(text)}
onBlur={() => {
const candidate = value.trim();
if (candidate) {
urlResolver.resolve(candidate).then((r) => {
if (r.ok) setValue(r.url);
});
}
}}
/>
</View>
<ServerUrlStatusText state={urlResolver} className='mt-1' />
</DisabledSetting>
<Text className='px-4 text-xs text-neutral-500 mt-1'>
{t("home.settings.plugins.marlin_search.marlin_search_hint")}{" "}

View File

@@ -11,11 +11,14 @@ import {
} from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { toast } from "sonner-native";
import { ServerUrlStatusText } from "@/components/common/ServerUrlStatusText";
import { Text } from "@/components/common/Text";
import { ListGroup } from "@/components/list/ListGroup";
import { ListItem } from "@/components/list/ListItem";
import { useNetworkAwareQueryClient } from "@/hooks/useNetworkAwareQueryClient";
import { useServerUrlResolver } from "@/hooks/useServerUrlResolver";
import { useSettings } from "@/utils/atoms/settings";
import { reachabilityProbe } from "@/utils/serverUrl/probes/reachability";
export default function StreamystatsPage() {
const { t } = useTranslation();
@@ -32,6 +35,7 @@ export default function StreamystatsPage() {
// Local state for all editable fields
const [url, setUrl] = useState<string>(settings?.streamyStatsServerUrl || "");
const urlResolver = useServerUrlResolver(reachabilityProbe);
const [useForSearch, setUseForSearch] = useState<boolean>(
settings?.searchEngine === "Streamystats",
);
@@ -152,9 +156,20 @@ export default function StreamystatsPage() {
autoCapitalize='none'
textContentType='URL'
onChangeText={setUrl}
onBlur={() => {
const candidate = url.trim();
if (candidate) {
urlResolver.resolve(candidate).then((r) => {
if (r.ok) setUrl(r.url);
});
}
}}
/>
</ListItem>
</ListGroup>
<View className='px-4 mt-1'>
<ServerUrlStatusText state={urlResolver} />
</View>
<Text className='px-4 text-xs text-neutral-500 mt-1'>
{t("home.settings.plugins.streamystats.streamystats_search_hint")}{" "}

View File

@@ -0,0 +1,56 @@
import { useTranslation } from "react-i18next";
import { ActivityIndicator, View } from "react-native";
import type { ServerUrlResolverState } from "@/hooks/useServerUrlResolver";
import { Text } from "./Text";
/**
* Compact status line for the server-URL resolver, for screens whose layout
* (e.g. ListItem rows) doesn't fit the full `ServerUrlField`. Renders nothing
* while idle.
*/
export function ServerUrlStatusText({
state,
minVersion,
className = "",
}: {
state: ServerUrlResolverState;
minVersion?: string;
className?: string;
}) {
const { t } = useTranslation();
if (state.status === "idle") return null;
if (state.status === "resolving") {
return (
<View className={`flex-row items-center ${className}`}>
<ActivityIndicator size='small' color='#9ca3af' />
<Text className='text-xs text-neutral-400 ml-2'>
{t("server_url.resolving")}
</Text>
</View>
);
}
if (state.status === "ok") {
return (
<Text className={`text-xs text-green-500 ${className}`}>
{t("server_url.resolved", { url: state.resolvedUrl })}
</Text>
);
}
const message =
state.reason === "version-too-low"
? t("server_url.version_too_low", {
version: state.version ?? "?",
min: minVersion ?? "",
})
: state.reason === "wrong-service"
? t("server_url.wrong_service")
: state.reason === "invalid"
? t("server_url.invalid_url")
: t("server_url.unreachable");
return <Text className={`text-xs text-red-500 ${className}`}>{message}</Text>;
}

View File

@@ -3,7 +3,9 @@ export {
type ParsedServerInput,
parseServerInput,
} from "./candidates";
export { jellyfinProbe } from "./probes/jellyfin";
export { jellyseerrProbe } from "./probes/jellyseerr";
export { reachabilityProbe } from "./probes/reachability";
export {
type ResolveFailureReason,
type ResolveOptions,

View File

@@ -0,0 +1,24 @@
import axios from "axios";
import type { ServerProbe } from "../types";
/** Public, unauthenticated Jellyfin endpoint; `ProductName` confirms the service. */
const PRODUCT_NAME = "Jellyfin Server";
export const jellyfinProbe: ServerProbe = async (url, signal) => {
try {
const { status, data } = await axios.get(`${url}/System/Info/Public`, {
signal,
timeout: 8000, // backstop; the resolver aborts via signal first
});
if (status < 200 || status >= 300) return { status: "unreachable" };
if (data?.ProductName !== PRODUCT_NAME) return { status: "wrong-service" };
return {
status: "ok",
meta: { version: data?.Version, serverName: data?.ServerName },
};
} catch {
return { status: "unreachable" };
}
};

View File

@@ -0,0 +1,23 @@
import axios from "axios";
import type { ServerProbe } from "../types";
/**
* Minimal probe for services without a known/unauthenticated health endpoint
* (e.g. Marlin Search, Streamystats). Any HTTP response — even 4xx — proves the
* host is up and speaking HTTP at this protocol/port, which is enough to pick
* https vs http. It cannot detect a "wrong service".
*/
export const reachabilityProbe: ServerProbe = async (url, signal) => {
try {
await axios.get(url, {
signal,
timeout: 8000,
validateStatus: () => true, // any status = the server answered
});
return { status: "ok" };
} catch (error) {
// A delivered response that still threw counts as reachable.
if ((error as { response?: unknown })?.response) return { status: "ok" };
return { status: "unreachable" };
}
};