import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { api, type ArrApp, type CurrentUser } from "../api/client"; import ReadNowButton from "../components/ReadNowButton"; import EmptyState from "../components/EmptyState"; import TimeAgo from "../components/TimeAgo"; import { BlockSkeleton } from "../components/Skeleton"; import { ErrorNotice } from "../components/Notice"; import { formatBytes } from "./settings/StorageSettings"; import { readableError } from "../utils/errors"; import PageIntro from "../components/PageIntro"; import FigureHistory from "../components/FigureHistory"; import { t } from "../i18n"; const KIND_NAMES: Record = { sonarr: "Sonarr", radarr: "Radarr", prowlarr: "Prowlarr", lidarr: "Lidarr", readarr: "Readarr" }; const QUEUE_SHOWN = 25; function Badge({ a }: { a: ArrApp }) { if (!a.enabled) return Off; if (!a.state) return {t("Not read yet")}; if (!a.fresh) return Can’t be read; if (a.problems.some((x) => x.severity === "critical")) return {t("Needs a look")}; if (a.problems.length > 0) return {t("Needs a look")}; return {t("In order")}; } function Tile({ label, value, sub, warn }: { label: string; value: string; sub?: string | null; warn?: boolean }) { return (
{label}
{value}
{sub &&
{sub}
}
); } function Card({ a, canRead, onRead }: { a: ArrApp; canRead: boolean; onRead: () => void }) { const s = a.state; const stuck = new Set(s?.stuck ?? []); const queue = s?.queue ?? null; const items = queue ? [...queue.items].sort((x, y) => Number(stuck.has(y.id)) - Number(stuck.has(x.id)) || Date.parse(x.added ?? "") - Date.parse(y.added ?? "")) : []; const findings = (s?.health ?? []).filter((h) => h.type === "warning" || h.type === "error"); const notices = (s?.health ?? []).filter((h) => h.type === "notice"); return (

{a.name} {KIND_NAMES[a.kind]}{s?.version ? ` ${s.version}` : ""}

{a.status ? <>read : "not read yet"} {canRead && a.enabled && }
{a.status && !a.status.ok &&
The last attempt to read it failed: {a.status.error ?? "no answer"}.
} {a.problems.length > 0 && (
    {a.problems.map((x) => (
  • {x.message}
  • ))}
)} {s && ( <>
{a.kind !== "prowlarr" && ( <> 0 ? `${stuck.size} stuck` : "nothing stuck") : "could not be read"} warn={stuck.size > 0} /> )} {a.kind === "prowlarr" && ( <> i.enabled).length} switched on` : "could not be read"} /> i.disabledTill && Date.parse(i.disabledTill) > Date.now()).length) : "—"} sub="switched off after failures" warn={!!s.indexers?.some((i) => i.disabledTill && Date.parse(i.disabledTill) > Date.now())} /> )} 0 ? `and ${notices.length} notice${notices.length === 1 ? "" : "s"}` : "warnings and errors"} warn={findings.length > 0} /> 0 ? `${formatBytes(Math.min(...s.disks.map((d) => d.free)))} free on the fullest` : "none reported") : "could not be read"} />
{(findings.length > 0 || notices.length > 0) && ( <>

What {KIND_NAMES[a.kind]} says

    {[...findings, ...notices].map((h, i) => (
  • {h.type} {h.message}
  • ))}
)} {s.disks && s.disks.length > 0 && (

Disks

{s.disks.map((d) => { const free = d.total > 0 ? d.free / d.total : 1; return (
{d.path} {formatBytes(d.free)} free of {formatBytes(d.total)} ({Math.floor(free * 100)}%)
); })}
)} {queue && queue.total > 0 && ( <>

Download queue

{items.slice(0, QUEUE_SHOWN).map((i) => { const done = i.size && i.size > 0 && i.sizeLeft !== null ? Math.round(((i.size - i.sizeLeft) / i.size) * 100) : null; const isStuck = stuck.has(i.id); return ( ); })}
{t("Title")} State Progress In the queue Client
{i.title} {i.messages.map((m) => (
{m}
))}
{isStuck ? stuck : i.tracked === "warning" || i.tracked === "error" ? {i.tracked} : {i.status}} {i.state && i.state !== "downloading" &&
{i.state}
}
{done === null ? ( — ) : ( <>
{done}%{i.size ? ` of ${formatBytes(i.size)}` : ""}
)}
{i.client ?? "—"} {i.indexer &&
{i.indexer}
}
{queue.total > QUEUE_SHOWN &&
{queue.total - QUEUE_SHOWN} more are in the queue (the stuck ones are listed first).
} )} {s.indexers && s.indexers.length > 0 && ( <>

Indexers

    {s.indexers.map((i) => { const off = i.disabledTill !== null && Date.parse(i.disabledTill) > Date.now(); return (
  • {i.name} {i.protocol && {i.protocol}}{" "} {!i.enabled ? off : off ? failing, tried again : working}
  • ); })}
)} )}
); } /** Sonarr, Radarr and Prowlarr: what each says is wrong, the downloads that are stuck, the disks they fill and the indexers that have failed. */ export default function Media({ user }: { user: CurrentUser }) { const [data, setData] = useState(null); const [error, setError] = useState(null); const load = () => api.arr .list() .then((r) => { setData(r.apps); setError(null); }) .catch((err) => setError(readableError(err))); useEffect(() => { void load(); const t = setInterval(load, 60_000); return () => clearInterval(t); }, []); const canRead = user.role === "admin" || user.role === "operator"; return ( <>

{t("Media managers")}

Sonarr, Radarr, Prowlarr, Lidarr and Readarr, read every few minutes (see {t("Integrations")}) — nothing is searched, grabbed or changed. What an application says is wrong with itself, downloads stuck for two hours and{" "} a disk nearly full are alerts — see {t("Alerts")}. {!data && !error && } {data && data.length === 0 && (
)} {data?.map((a) => void load()} />)} ); }