Add Read now to every integration
POST /api/integrations/:id/read-now reads one integration at once (operators and administrators; not again within 20 s): a kind with a stored reading is read and judged again, a kind read live is asked whether it answers. The three per-kind lists in the integrations routes (add, change, delete) are now one map in services/integrationSyncs.ts. Button on the Integrations cards and the Media managers, Download clients and Hetzner Robot pages. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
01acbaf831
commit
b29c0b7d04
13 files changed
+434
-128
No files matched your search
+3
-3
@@ -186,9 +186,9 @@ function Shelled({ user }: { user: CurrentUser }) {
|
||||
<Route path="/nextcloud" element={<Nextcloud />} />
|
||||
<Route path="/hetzner" element={<Hetzner />} />
|
||||
<Route path="/game-servers" element={<GameServers user={user} />} />
|
||||
<Route path="/media" element={<Media />} />
|
||||
<Route path="/downloads" element={<Downloads />} />
|
||||
<Route path="/hetzner-robot" element={<HetznerRobot />} />
|
||||
<Route path="/media" element={<Media user={user} />} />
|
||||
<Route path="/downloads" element={<Downloads user={user} />} />
|
||||
<Route path="/hetzner-robot" element={<HetznerRobot user={user} />} />
|
||||
<Route path="/versions" element={<Versions user={user} />} />
|
||||
<Route path="/adguard" element={<AdguardHome />} />
|
||||
<Route path="/technitium" element={<TechnitiumDns />} />
|
||||
|
||||
@@ -4242,6 +4242,8 @@ export const api = {
|
||||
config: Record<string, string | boolean>;
|
||||
}>(`/api/integrations/${id}/config`),
|
||||
inspect: (id: number) => request<IntegrationInspection>(`/api/integrations/${id}/inspect`, { method: "POST" }),
|
||||
/** Reads it now instead of at its next turn. A kind with a stored reading is read and judged again; a kind that is read live is asked whether it answers. */
|
||||
readNow: (id: number) => request<{ kind: "stored" | "live"; ok: boolean; error: string | null; at: string; latencyMs: number | null }>(`/api/integrations/${id}/read-now`, { method: "POST" }),
|
||||
testExisting: (id: number, config: Record<string, string | boolean>) =>
|
||||
request<{ ok: boolean; latencyMs?: number; error?: string }>(`/api/integrations/${id}/test`, {
|
||||
method: "POST",
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useState } from "react";
|
||||
import { IconRefresh } from "@tabler/icons-react";
|
||||
import { api } from "../api/client";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
|
||||
/**
|
||||
* "Read now": reads one integration at once instead of at its next turn, then says how it went and — if the page that holds the button has something to refresh — asks it to (`onDone`). For
|
||||
* operators and administrators; the button is for the page to show or not. The same integration cannot be read again within twenty seconds (some systems limit how often they may be asked), which
|
||||
* the server says and the toast repeats.
|
||||
*/
|
||||
export default function ReadNowButton({ integrationId, name, onDone, className = "btn btn-sm" }: { integrationId: number; name: string; onDone?: () => void; className?: string }) {
|
||||
const [busy, setBusy] = useState(false);
|
||||
async function readNow() {
|
||||
setBusy(true);
|
||||
try {
|
||||
const r = await api.integrations.readNow(integrationId);
|
||||
if (r.ok) toast.success(r.kind === "live" ? `${name} answers.` : `${name} was read.`);
|
||||
else toast.error(`${name} could not be read: ${r.error ?? "no answer"}`);
|
||||
} catch (err) {
|
||||
toast.error(`${name}: ${readableError(err)}`);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
onDone?.();
|
||||
}
|
||||
}
|
||||
return (
|
||||
<button type="button" className={className} onClick={() => void readNow()} disabled={busy} title="Read it now, instead of waiting for its next turn">
|
||||
<IconRefresh size={14} className="me-1" />
|
||||
{busy ? "Reading…" : "Read now"}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
+18
-13
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type DownloadClient, type DownloadItem, type DownloadState } from "../api/client";
|
||||
import { api, type CurrentUser, type DownloadClient, type DownloadItem, type DownloadState } from "../api/client";
|
||||
import ReadNowButton from "../components/ReadNowButton";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
@@ -120,7 +121,7 @@ function ItemsTable({ items, stuck }: { items: DownloadItem[]; stuck: Set<string
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ c }: { c: DownloadClient }) {
|
||||
function Card({ c, canRead, onRead }: { c: DownloadClient; canRead: boolean; onRead: () => void }) {
|
||||
const s = c.state;
|
||||
const stuck = new Set(s?.stuck ?? []);
|
||||
const failedRecent = new Set(s?.failedRecent ?? []);
|
||||
@@ -133,7 +134,10 @@ function Card({ c }: { c: DownloadClient }) {
|
||||
<h3 className="card-title">
|
||||
{c.name} <span className="text-secondary fw-normal">{KIND_NAMES[c.kind]}{s?.version ? ` ${s.version}` : ""}</span> <Badge c={c} />
|
||||
</h3>
|
||||
<div className="card-actions text-secondary small">{c.status ? <>read <TimeAgo value={c.status.at} /></> : "not read yet"}</div>
|
||||
<div className="card-actions d-flex align-items-center gap-2 text-secondary small">
|
||||
{c.status ? <>read <TimeAgo value={c.status.at} /></> : "not read yet"}
|
||||
{canRead && c.enabled && <ReadNowButton integrationId={c.id} name={c.name} onDone={onRead} />}
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{c.status && !c.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {c.status.error ?? "no answer"}.</div>}
|
||||
@@ -235,22 +239,23 @@ function Card({ c }: { c: DownloadClient }) {
|
||||
}
|
||||
|
||||
/** qBittorrent and SABnzbd: how fast they are going, what is in their queues and in what state, what is stuck or failed, and the room they have. */
|
||||
export default function Downloads() {
|
||||
export default function Downloads({ user }: { user: CurrentUser }) {
|
||||
const [data, setData] = useState<DownloadClient[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const load = () =>
|
||||
api.downloads
|
||||
.list()
|
||||
.then((r) => {
|
||||
setData(r.clients);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
api.downloads
|
||||
.list()
|
||||
.then((r) => {
|
||||
setData(r.clients);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
void load();
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
const canRead = user.role === "admin" || user.role === "operator";
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title">Download clients</h2>
|
||||
@@ -267,7 +272,7 @@ export default function Downloads() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((c) => <Card key={c.id} c={c} />)}
|
||||
{data?.map((c) => <Card key={c.id} c={c} canRead={canRead} onRead={() => void load()} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type RobotAccount } from "../api/client";
|
||||
import { api, type CurrentUser, type RobotAccount } from "../api/client";
|
||||
import ReadNowButton from "../components/ReadNowButton";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
@@ -47,7 +48,7 @@ function Until({ date, cancelled, days }: { date: string | null; cancelled: bool
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ a }: { a: RobotAccount }) {
|
||||
function Card({ a, canRead, onRead }: { a: RobotAccount; canRead: boolean; onRead: () => void }) {
|
||||
const s = a.state;
|
||||
const rescue = s?.servers.filter((v) => v.rescue === true).length ?? 0;
|
||||
const cancelled = (s?.servers.filter((v) => v.cancelled).length ?? 0) + (s?.storageBoxes?.filter((b) => b.cancelled).length ?? 0);
|
||||
@@ -57,7 +58,10 @@ function Card({ a }: { a: RobotAccount }) {
|
||||
<h3 className="card-title">
|
||||
{a.name} <Badge a={a} />
|
||||
</h3>
|
||||
<div className="card-actions text-secondary small">{a.status ? <>read <TimeAgo value={a.status.at} /></> : "not read yet"}</div>
|
||||
<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>}
|
||||
@@ -183,22 +187,23 @@ function Card({ a }: { a: RobotAccount }) {
|
||||
}
|
||||
|
||||
/** Hetzner Robot: the account's dedicated servers (rescue system, cancellation) and storage boxes. */
|
||||
export default function HetznerRobot() {
|
||||
export default function HetznerRobot({ user }: { user: CurrentUser }) {
|
||||
const [data, setData] = useState<RobotAccount[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const load = () =>
|
||||
api.hetznerRobot
|
||||
.list()
|
||||
.then((r) => {
|
||||
setData(r.accounts);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
api.hetznerRobot
|
||||
.list()
|
||||
.then((r) => {
|
||||
setData(r.accounts);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
void load();
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
const canRead = user.role === "admin" || user.role === "operator";
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title">Hetzner Robot</h2>
|
||||
@@ -215,7 +220,7 @@ export default function HetznerRobot() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} />)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} canRead={canRead} onRead={() => void load()} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { toast } from "../utils/toast";
|
||||
import UptimeRibbon from "../components/UptimeRibbon";
|
||||
import RunbookEntry from "../components/RunbookEntry";
|
||||
import IntegrationInspector from "../components/IntegrationInspector";
|
||||
import ReadNowButton from "../components/ReadNowButton";
|
||||
import { groupOfType, INSPECTABLE, TYPE_GROUPS, TYPE_LABELS, TYPE_PAGES } from "../utils/integrationTypes";
|
||||
|
||||
/** "pve.example.lan" out of "https://pve.example.lan:8006/", or the text itself when it isn't an address. */
|
||||
@@ -291,6 +292,7 @@ function IntegrationsList({ user, tabs }: { user: CurrentUser; tabs: ReactNode }
|
||||
Open
|
||||
</Link>
|
||||
)}
|
||||
{isOperator && i.enabled && <ReadNowButton integrationId={i.id} name={i.name} onDone={loadIntegrations} />}
|
||||
{isAdmin && (
|
||||
<>
|
||||
<button className="btn btn-sm" onClick={() => testIntegration(i)} disabled={testingId === i.id}>
|
||||
|
||||
+18
-13
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type ArrApp } from "../api/client";
|
||||
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";
|
||||
@@ -34,7 +35,7 @@ function Tile({ label, value, sub, warn }: { label: string; value: string; sub?:
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ a }: { a: ArrApp }) {
|
||||
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;
|
||||
@@ -47,7 +48,10 @@ function Card({ a }: { a: ArrApp }) {
|
||||
<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 text-secondary small">{a.status ? <>read <TimeAgo value={a.status.at} /></> : "not read yet"}</div>
|
||||
<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>}
|
||||
@@ -194,22 +198,23 @@ function Card({ a }: { a: ArrApp }) {
|
||||
}
|
||||
|
||||
/** 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() {
|
||||
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(() => {
|
||||
const load = () =>
|
||||
api.arr
|
||||
.list()
|
||||
.then((r) => {
|
||||
setData(r.apps);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
void load();
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
const canRead = user.role === "admin" || user.role === "operator";
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title">Media managers</h2>
|
||||
@@ -226,7 +231,7 @@ export default function Media() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} />)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} canRead={canRead} onRead={() => void load()} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user