Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e14fbc9205 | ||
|
|
813cad613e |
@@ -144,6 +144,7 @@ body {
|
|||||||
.pn-bento {
|
.pn-bento {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(12, 1fr);
|
grid-template-columns: repeat(12, 1fr);
|
||||||
|
grid-auto-flow: dense;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 860px) {
|
@media (max-width: 860px) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export function SystemWidget({ widget, widgetId }: { widget: SystemWidget; widge
|
|||||||
const errorMessage = result?.type === "error" ? result.message : null;
|
const errorMessage = result?.type === "error" ? result.message : null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WidgetCard span={5} rowSpan={2}>
|
<WidgetCard span={4} rowSpan={2}>
|
||||||
<div className="text-[10px] tracking-[0.1em] text-accent uppercase">System</div>
|
<div className="text-[10px] tracking-[0.1em] text-accent uppercase">System</div>
|
||||||
<span className="text-[15px] font-medium text-fg">{widget.name}</span>
|
<span className="text-[15px] font-medium text-fg">{widget.name}</span>
|
||||||
{errorMessage && <span className="text-xs text-status-down">{errorMessage}</span>}
|
{errorMessage && <span className="text-xs text-status-down">{errorMessage}</span>}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Lock } from "@phosphor-icons/react/ssr";
|
|
||||||
import type { Widget } from "@/lib/config/schema";
|
import type { Widget } from "@/lib/config/schema";
|
||||||
import { useWidgetSubscription } from "@/lib/ws/client";
|
import { useWidgetSubscription } from "@/lib/ws/client";
|
||||||
import { SkeletonLines } from "@/components/widgets/Skeleton";
|
import { SkeletonLines } from "@/components/widgets/Skeleton";
|
||||||
import { WidgetCard } from "@/components/widgets/WidgetCard";
|
import { WidgetCard } from "@/components/widgets/WidgetCard";
|
||||||
|
import { StatusDot } from "@/components/widgets/StatusDot";
|
||||||
|
import { BrandIcon } from "@/components/widgets/BrandIcon";
|
||||||
|
|
||||||
type TraefikWidget = Extract<Widget, { type: "traefik" }>;
|
type TraefikWidget = Extract<Widget, { type: "traefik" }>;
|
||||||
|
|
||||||
@@ -12,41 +13,59 @@ export function TraefikWidget({ widget, widgetId }: { widget: TraefikWidget; wid
|
|||||||
const result = useWidgetSubscription(widgetId);
|
const result = useWidgetSubscription(widgetId);
|
||||||
const data = result?.type === "traefik" ? result.data : null;
|
const data = result?.type === "traefik" ? result.data : null;
|
||||||
const errorMessage = result?.type === "error" ? result.message : null;
|
const errorMessage = result?.type === "error" ? result.message : null;
|
||||||
|
const enabledCount = data?.routers.filter((router) => router.status === "enabled").length ?? 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WidgetCard span={4}>
|
<WidgetCard span={4}>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between gap-2">
|
||||||
<span className="text-[15px] font-medium text-fg">{widget.name}</span>
|
<div className="flex min-w-0 items-center gap-2">
|
||||||
{data && (
|
<BrandIcon slug={widget.icon} />
|
||||||
<span className="font-mono text-[11px] tabular-nums text-fg-muted">
|
{widget.href ? (
|
||||||
{data.entrypoints.map((ep) => ep.address).join(" · ") || `${data.entrypoints.length} entrypoints`}
|
<a
|
||||||
</span>
|
href={widget.href}
|
||||||
)}
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
className="truncate text-[15px] font-medium text-fg hover:text-accent"
|
||||||
|
>
|
||||||
|
{widget.name}
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<span className="truncate text-[15px] font-medium text-fg">{widget.name}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{data && (
|
||||||
|
<span className="font-mono text-[11px] tabular-nums text-fg-muted">
|
||||||
|
{data.entrypoints.length} entrypoints
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<StatusDot status={data ? "running" : undefined} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{errorMessage && <span className="text-xs text-status-down">{errorMessage}</span>}
|
{errorMessage && <span className="text-xs text-status-down">{errorMessage}</span>}
|
||||||
{!result && !errorMessage && <SkeletonLines count={3} />}
|
{!result && !errorMessage && <SkeletonLines count={3} />}
|
||||||
{data && (
|
{data && (
|
||||||
<div className="flex flex-col">
|
<>
|
||||||
{data.routers.map((router) => (
|
<div className="flex items-start gap-4">
|
||||||
<div key={router.name} className="flex items-center justify-between gap-2 border-t border-border py-1.5 text-[13px] first:border-t-0">
|
<div className="flex flex-col gap-0.5">
|
||||||
<span className="truncate text-fg" title={router.rule}>
|
<span className="font-mono text-2xl leading-none font-semibold tabular-nums text-accent">
|
||||||
{router.name.replace(/@.*$/, "")}
|
{data.routers.length}
|
||||||
</span>
|
|
||||||
<span className="flex items-center gap-1.5 text-[11px] text-fg-muted">
|
|
||||||
{router.tls && <Lock size={11} aria-label="TLS enabled" />}
|
|
||||||
<span
|
|
||||||
className={`flex items-center gap-1.5 ${router.status === "enabled" ? "text-status-up" : "text-status-down"}`}
|
|
||||||
>
|
|
||||||
<span className="h-1.5 w-1.5 rounded-full bg-current" />
|
|
||||||
{router.status}
|
|
||||||
</span>
|
|
||||||
</span>
|
</span>
|
||||||
|
<span className="text-[10px] tracking-wide text-fg-muted uppercase">Routes</span>
|
||||||
</div>
|
</div>
|
||||||
))}
|
{enabledCount !== data.routers.length && (
|
||||||
<span className="pt-2 text-[11px] text-fg-muted">
|
<div className="flex flex-col gap-0.5 border-l border-border pl-4">
|
||||||
|
<span className="font-mono text-2xl leading-none font-semibold tabular-nums text-status-degraded">
|
||||||
|
{enabledCount}
|
||||||
|
</span>
|
||||||
|
<span className="text-[10px] tracking-wide text-fg-muted uppercase">Enabled</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<span className="text-[11px] text-fg-muted">
|
||||||
<span className="font-mono tabular-nums">{data.middlewaresCount}</span> middlewares
|
<span className="font-mono tabular-nums">{data.middlewaresCount}</span> middlewares
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</>
|
||||||
)}
|
)}
|
||||||
</WidgetCard>
|
</WidgetCard>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,23 +8,33 @@ interface CoolifyProject {
|
|||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function collectCoolify(
|
async function fetchCoolify<T>(base: string, path: string, apiToken: string): Promise<T> {
|
||||||
widget: CoolifyServiceWidget
|
const response = await fetch(`${base}${path}`, {
|
||||||
): Promise<{ stats: ServiceStat[]; detail?: string[] }> {
|
headers: { Authorization: `Bearer ${apiToken}` },
|
||||||
const base = serviceBaseUrl(widget);
|
|
||||||
const response = await fetch(`${base}/api/v1/projects`, {
|
|
||||||
headers: { Authorization: `Bearer ${widget.apiToken}` },
|
|
||||||
signal: AbortSignal.timeout(5_000),
|
signal: AbortSignal.timeout(5_000),
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Coolify API returned ${response.status}`);
|
throw new Error(`Coolify API returned ${response.status}`);
|
||||||
}
|
}
|
||||||
const projects = (await response.json()) as CoolifyProject[];
|
return (await response.json()) as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function collectCoolify(
|
||||||
|
widget: CoolifyServiceWidget
|
||||||
|
): Promise<{ stats: ServiceStat[]; detail?: string[] }> {
|
||||||
|
const base = serviceBaseUrl(widget);
|
||||||
|
const [projects, resources] = await Promise.all([
|
||||||
|
fetchCoolify<CoolifyProject[]>(base, "/api/v1/projects", widget.apiToken),
|
||||||
|
fetchCoolify<unknown[]>(base, "/api/v1/resources", widget.apiToken),
|
||||||
|
]);
|
||||||
const names = projects.slice(0, DETAIL_LIMIT).map((p) => p.name);
|
const names = projects.slice(0, DETAIL_LIMIT).map((p) => p.name);
|
||||||
if (projects.length > DETAIL_LIMIT) names.push(`+${projects.length - DETAIL_LIMIT} more`);
|
if (projects.length > DETAIL_LIMIT) names.push(`+${projects.length - DETAIL_LIMIT} more`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
stats: [{ label: "Projects", value: String(projects.length) }],
|
stats: [
|
||||||
|
{ label: "Projects", value: String(projects.length) },
|
||||||
|
{ label: "Resources", value: String(resources.length) },
|
||||||
|
],
|
||||||
detail: names.length > 0 ? names : undefined,
|
detail: names.length > 0 ? names : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ export const traefikWidgetSchema = z.object({
|
|||||||
type: z.literal("traefik"),
|
type: z.literal("traefik"),
|
||||||
name: z.string().default("Traefik"),
|
name: z.string().default("Traefik"),
|
||||||
apiUrl: z.string().url(),
|
apiUrl: z.string().url(),
|
||||||
|
href: z.string().url().optional(),
|
||||||
|
icon: z.string().optional(),
|
||||||
interval: durationSchema.default("15s"),
|
interval: durationSchema.default("15s"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user