mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-04 21:18:31 +01:00
Type a loose address (media.example.com, https://…, host:port) and the app finds the working, canonical URL. - utils/serverUrl: generic candidate generator (https-first, port/path preserved, no Jellyfin-specific ports), parallel-probe resolver, numeric semver compare, and a Jellyseerr probe (/api/v1/status, min 2.0.0). - useServerUrlResolver: idle -> resolving -> ok | error state machine with cancellation. - ServerUrlField: shared input that auto-resolves on blur, inline status chip (tap to re-test) + resolved URL, persists the canonical URL. - Jellyseerr settings adopt the field and log in with the resolved URL. Probe contract makes Streamystats/Jellyfin/Merlin a drop-in follow-up.
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import axios from "axios";
|
|
import { isVersionBelow } from "../semver";
|
|
import type { ServerProbe } from "../types";
|
|
|
|
/** Jellyseerr/Overseerr minimum supported version. */
|
|
const MIN_VERSION = "2.0.0";
|
|
|
|
/**
|
|
* Probe for a Jellyseerr server. `/api/v1/status` is jellyseerr/overseerr
|
|
* specific and unauthenticated, so it both proves reachability and confirms
|
|
* we hit the right service.
|
|
*/
|
|
export const jellyseerrProbe: ServerProbe = async (url, signal) => {
|
|
try {
|
|
const { status, data } = await axios.get(`${url}/api/v1/status`, {
|
|
signal,
|
|
timeout: 8000, // backstop; the resolver aborts via signal first
|
|
});
|
|
|
|
if (status < 200 || status >= 300) return { status: "unreachable" };
|
|
|
|
const version: string | undefined =
|
|
typeof data?.version === "string" ? data.version : undefined;
|
|
|
|
// A JSON body carrying version/commitTag identifies a real jellyseerr.
|
|
if (
|
|
!version &&
|
|
!(data && typeof data === "object" && "commitTag" in data)
|
|
) {
|
|
return { status: "wrong-service" };
|
|
}
|
|
|
|
if (version && isVersionBelow(version, MIN_VERSION)) {
|
|
return { status: "version-too-low", version };
|
|
}
|
|
|
|
return { status: "ok", meta: { version } };
|
|
} catch {
|
|
return { status: "unreachable" };
|
|
}
|
|
};
|