A small translation system (the English text is its own key, so anything without a Swedish entry stays English) and a Language switch in the user menu, saved on the account (users.language) and following the browser when no choice has been made. Swedish covers the menu, shared parts (search, tables, dialogs, relative times), the sign-in page and the everyday pages: Dashboard, Alerts, Servers, Updates, Maintenance, My work, Coming up, To do, Integrations and the display settings. Server-written messages stay English for now. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
242 lines
12 KiB
TypeScript
242 lines
12 KiB
TypeScript
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<ArrApp["kind"], string> = { sonarr: "Sonarr", radarr: "Radarr", prowlarr: "Prowlarr", lidarr: "Lidarr", readarr: "Readarr" };
|
|
const QUEUE_SHOWN = 25;
|
|
|
|
function Badge({ a }: { a: ArrApp }) {
|
|
if (!a.enabled) return <span className="badge bg-secondary-lt text-secondary">Off</span>;
|
|
if (!a.state) return <span className="badge bg-secondary-lt text-secondary">{t("Not read yet")}</span>;
|
|
if (!a.fresh) return <span className="badge bg-yellow-lt text-yellow">Can’t be read</span>;
|
|
if (a.problems.some((x) => x.severity === "critical")) return <span className="badge bg-red-lt text-red">{t("Needs a look")}</span>;
|
|
if (a.problems.length > 0) return <span className="badge bg-yellow-lt text-yellow">{t("Needs a look")}</span>;
|
|
return <span className="badge bg-green-lt text-green">{t("In order")}</span>;
|
|
}
|
|
|
|
function Tile({ label, value, sub, warn }: { label: string; value: string; sub?: string | null; warn?: boolean }) {
|
|
return (
|
|
<div className="col-6 col-lg-3">
|
|
<div className="card card-sm h-100">
|
|
<div className="card-body">
|
|
<div className="text-secondary small">{label}</div>
|
|
<div className={`h2 mb-0 ${warn ? "text-yellow" : ""}`}>{value}</div>
|
|
{sub && <div className="text-secondary small">{sub}</div>}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
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 (
|
|
<div className="card mb-3">
|
|
<div className="card-header">
|
|
<h3 className="card-title">
|
|
{a.name} <span className="text-secondary fw-normal">{KIND_NAMES[a.kind]}{s?.version ? ` ${s.version}` : ""}</span> <Badge a={a} />
|
|
</h3>
|
|
<div className="card-actions d-flex align-items-center gap-2 text-secondary small">
|
|
{a.status ? <>read <TimeAgo value={a.status.at} /></> : "not read yet"}
|
|
{canRead && a.enabled && <ReadNowButton integrationId={a.id} name={a.name} onDone={onRead} />}
|
|
</div>
|
|
</div>
|
|
<div className="card-body">
|
|
{a.status && !a.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {a.status.error ?? "no answer"}.</div>}
|
|
{a.problems.length > 0 && (
|
|
<ul className="mb-3">
|
|
{a.problems.map((x) => (
|
|
<li key={x.key} className={x.severity === "critical" ? "text-red" : ""}>
|
|
{x.message}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
{s && (
|
|
<>
|
|
<div className="row g-3 mb-3">
|
|
{a.kind !== "prowlarr" && (
|
|
<>
|
|
<Tile label="Download queue" value={queue ? String(queue.total) : "—"} sub={queue ? (stuck.size > 0 ? `${stuck.size} stuck` : "nothing stuck") : "could not be read"} warn={stuck.size > 0} />
|
|
<Tile label="Wanted, no file yet" value={s.missing === null ? "—" : String(s.missing)} sub="monitored items" />
|
|
</>
|
|
)}
|
|
{a.kind === "prowlarr" && (
|
|
<>
|
|
<Tile label="Indexers" value={s.indexers ? String(s.indexers.length) : "—"} sub={s.indexers ? `${s.indexers.filter((i) => i.enabled).length} switched on` : "could not be read"} />
|
|
<Tile label={t("Failing")} value={s.indexers ? String(s.indexers.filter((i) => 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())} />
|
|
</>
|
|
)}
|
|
<Tile label="Its own findings" value={String(findings.length)} sub={notices.length > 0 ? `and ${notices.length} notice${notices.length === 1 ? "" : "s"}` : "warnings and errors"} warn={findings.length > 0} />
|
|
<Tile label="Disks" value={s.disks ? String(s.disks.length) : "—"} sub={s.disks ? (s.disks.length > 0 ? `${formatBytes(Math.min(...s.disks.map((d) => d.free)))} free on the fullest` : "none reported") : "could not be read"} />
|
|
</div>
|
|
{(findings.length > 0 || notices.length > 0) && (
|
|
<>
|
|
<h4>What {KIND_NAMES[a.kind]} says</h4>
|
|
<ul>
|
|
{[...findings, ...notices].map((h, i) => (
|
|
<li key={`${h.source}-${i}`}>
|
|
<span className={`badge ${h.type === "error" ? "bg-red-lt text-red" : h.type === "warning" ? "bg-yellow-lt text-yellow" : "bg-blue-lt text-blue"}`}>{h.type}</span> {h.message}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</>
|
|
)}
|
|
{s.disks && s.disks.length > 0 && (
|
|
<div className="mb-3">
|
|
<h4>Disks</h4>
|
|
{s.disks.map((d) => {
|
|
const free = d.total > 0 ? d.free / d.total : 1;
|
|
return (
|
|
<div key={d.path} className="mb-1" style={{ maxWidth: 520 }}>
|
|
<div className="progress progress-sm">
|
|
<div className={`progress-bar ${free < 0.05 ? "bg-red" : free < 0.1 ? "bg-yellow" : "bg-green"}`} style={{ width: `${Math.min(100, (1 - free) * 100)}%` }} />
|
|
</div>
|
|
<div className="small text-secondary">
|
|
<code>{d.path}</code> {formatBytes(d.free)} free of {formatBytes(d.total)} ({Math.floor(free * 100)}%)
|
|
</div>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
)}
|
|
{queue && queue.total > 0 && (
|
|
<>
|
|
<h4>Download queue</h4>
|
|
<div className="table-responsive">
|
|
<table className="table table-vcenter card-table">
|
|
<thead>
|
|
<tr>
|
|
<th>{t("Title")}</th>
|
|
<th>State</th>
|
|
<th>Progress</th>
|
|
<th>In the queue</th>
|
|
<th>Client</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{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 (
|
|
<tr key={i.id}>
|
|
<td className="text-break">
|
|
{i.title}
|
|
{i.messages.map((m) => (
|
|
<div key={m} className={`small ${isStuck ? "text-red" : "text-yellow"}`}>
|
|
{m}
|
|
</div>
|
|
))}
|
|
</td>
|
|
<td>
|
|
{isStuck ? <span className="badge bg-red-lt text-red">stuck</span> : i.tracked === "warning" || i.tracked === "error" ? <span className="badge bg-yellow-lt text-yellow">{i.tracked}</span> : <span className="badge bg-secondary-lt text-secondary">{i.status}</span>}
|
|
{i.state && i.state !== "downloading" && <div className="small text-secondary">{i.state}</div>}
|
|
</td>
|
|
<td style={{ minWidth: 120 }}>
|
|
{done === null ? (
|
|
<span className="text-secondary">—</span>
|
|
) : (
|
|
<>
|
|
<div className="progress progress-sm">
|
|
<div className="progress-bar" style={{ width: `${done}%` }} />
|
|
</div>
|
|
<div className="small text-secondary">
|
|
{done}%{i.size ? ` of ${formatBytes(i.size)}` : ""}
|
|
</div>
|
|
</>
|
|
)}
|
|
</td>
|
|
<td className="text-secondary">
|
|
<TimeAgo value={i.added} />
|
|
</td>
|
|
<td className="text-secondary text-break">
|
|
{i.client ?? "—"}
|
|
{i.indexer && <div className="small">{i.indexer}</div>}
|
|
</td>
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{queue.total > QUEUE_SHOWN && <div className="text-secondary small">{queue.total - QUEUE_SHOWN} more are in the queue (the stuck ones are listed first).</div>}
|
|
</>
|
|
)}
|
|
{s.indexers && s.indexers.length > 0 && (
|
|
<>
|
|
<h4 className="mt-3">Indexers</h4>
|
|
<ul className="mb-0">
|
|
{s.indexers.map((i) => {
|
|
const off = i.disabledTill !== null && Date.parse(i.disabledTill) > Date.now();
|
|
return (
|
|
<li key={i.id}>
|
|
<strong>{i.name}</strong> {i.protocol && <span className="text-secondary small">{i.protocol}</span>}{" "}
|
|
{!i.enabled ? <span className="badge bg-secondary-lt text-secondary">off</span> : off ? <span className="badge bg-red-lt text-red">failing, tried again <TimeAgo value={i.disabledTill} /></span> : <span className="badge bg-green-lt text-green">working</span>}
|
|
</li>
|
|
);
|
|
})}
|
|
</ul>
|
|
</>
|
|
)}
|
|
</>
|
|
)}
|
|
<FigureHistory integrationId={a.id} name={a.name} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/** 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<ArrApp[] | null>(null);
|
|
const [error, setError] = useState<string | null>(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 (
|
|
<>
|
|
<h2 className="page-title">{t("Media managers")}</h2>
|
|
<PageIntro>
|
|
Sonarr, Radarr, Prowlarr, Lidarr and Readarr, read every few minutes (see <Link to="/integrations">{t("Integrations")}</Link>) — nothing is searched, grabbed or changed. <strong>What an application says is wrong with itself</strong>, <strong>downloads stuck for two hours</strong> and{" "}
|
|
<strong>a disk nearly full</strong> are alerts — see <Link to="/alerts">{t("Alerts")}</Link>.
|
|
</PageIntro>
|
|
<ErrorNotice error={error} />
|
|
{!data && !error && <BlockSkeleton lines={4} />}
|
|
{data && data.length === 0 && (
|
|
<div className="card">
|
|
<div className="card-body">
|
|
<EmptyState title="No media manager connected" hint="Add one under Integrations with its address and API key (Settings → General → Security → API Key in the application)." />
|
|
</div>
|
|
</div>
|
|
)}
|
|
{data?.map((a) => <Card key={a.id} a={a} canRead={canRead} onRead={() => void load()} />)}
|
|
</>
|
|
);
|
|
}
|