mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-05 05:28:37 +01:00
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:
24
utils/serverUrl/probes/jellyfin.ts
Normal file
24
utils/serverUrl/probes/jellyfin.ts
Normal 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" };
|
||||
}
|
||||
};
|
||||
23
utils/serverUrl/probes/reachability.ts
Normal file
23
utils/serverUrl/probes/reachability.ts
Normal 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" };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user