Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Accounts: runs and space in Settings, and a page of accounts' runs

Adarsh400459d0bd54
diff --git a/src/app/(studio)/settings/runs/loading.tsx b/src/app/(studio)/settings/runs/loading.tsx
new file mode 100644
index 00000000..073dbfbc
--- /dev/null
+++ b/src/app/(studio)/settings/runs/loading.tsx
@@ -0,0 +1,5 @@
+import { GalleryPageSkeleton } from "@/components/skeletons";
+
+export default function Loading() {
+ return <GalleryPageSkeleton title="Accounts' runs" />;
+}
diff --git a/src/app/(studio)/settings/runs/page.tsx b/src/app/(studio)/settings/runs/page.tsx
new file mode 100644
index 00000000..dbfbb8fb
--- /dev/null
+++ b/src/app/(studio)/settings/runs/page.tsx
@@ -0,0 +1,23 @@
+import { ArrowLeft } from "lucide-react";
+import type { Metadata } from "next";
+import Link from "next/link";
+import { Suspense } from "react";
+import { AccountRunsView } from "@/components/account-runs";
+import { PageShell } from "@/components/page-shell";
+import { GallerySkeleton } from "@/components/skeletons";
+
+export const metadata: Metadata = { title: "Accounts' runs" };
+
+/** Settings → Accounts' runs (the owner only): what accounts made on their own GPUs, one account's (?account=<id>) or everyone's. */
+export default function Page() {
+ return (
+ <PageShell>
+ <Link href="/settings#accounts" className="mb-3 inline-flex items-center gap-1.5 rounded-md text-[13px] text-muted-foreground hover:text-foreground">
+ <ArrowLeft className="size-3.5" /> Settings
+ </Link>
+ <Suspense fallback={<GallerySkeleton cards={8} />}>
+ <AccountRunsView />
+ </Suspense>
+ </PageShell>
+ );
+}
diff --git a/src/components/account-runs.tsx b/src/components/account-runs.tsx
new file mode 100644
index 00000000..fcd996ff
--- /dev/null
+++ b/src/components/account-runs.tsx
@@ -0,0 +1,349 @@
+"use client";
+
+import { keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
+import { ExternalLink, Filter, Loader2, MoreHorizontal, Trash2, UserCheck, UserX } from "lucide-react";
+import Link from "next/link";
+import { useRouter, useSearchParams } from "next/navigation";
+import { useRef, useState } from "react";
+import { adminCall, OffBadge, Stat, useAdminAccounts, useAdminAction, type AccountRow } from "@/components/accounts-admin";
+import { StatusCover } from "@/components/library/asset-card";
+import { PageHeader } from "@/components/page-shell";
+import { GallerySkeleton } from "@/components/skeletons";
+import { MediaThumb } from "@/components/studio/result-media";
+import { Button } from "@/components/ui/button";
+import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
+import { Skeleton } from "@/components/ui/skeleton";
+import { useViewer } from "@/lib/api";
+import { OPERATION_LABELS, type Generation, type MediaKind } from "@/lib/catalog/types";
+import { storageSize, timeAgo } from "@/lib/format";
+import { cn } from "@/lib/utils";
+
+/** An account's run as GET /api/admin/generations lists it, with whose it is (null email: the account was deleted). */
+type AdminRun = Generation & { account: { id: string; email: string | null } };
+type Status = "all" | "finished" | "running" | "failed";
+type Kind = "all" | MediaKind;
+
+const STATUSES: [Status, string][] = [
+ ["all", "Any status"],
+ ["finished", "Finished"],
+ ["running", "Running"],
+ ["failed", "Failed"],
+];
+const KINDS: [Kind, string][] = [
+ ["all", "All kinds"],
+ ["image", "Images"],
+ ["video", "Videos"],
+ ["audio", "Audio"],
+ ["model3d", "3D"],
+ ["text", "Text"],
+];
+const STATUS_LABELS: Record<Generation["status"], string> = { succeeded: "Finished", queued: "Queued", running: "Running", failed: "Failed", canceled: "Canceled" };
+const PAGE = 30;
+
+const featureName = (f: string) => f.charAt(0).toUpperCase() + f.slice(1).replaceAll("-", " ");
+const runsHref = (id?: string) => (id ? `/settings/runs?account=${encodeURIComponent(id)}` : "/settings/runs");
+
+/**
+ * Settings → Accounts' runs (the owner only): what accounts made on their own GPUs, newest first, one account's or every
+ * account's, with their results, prompts and errors. Its own queries only: the Library's Viewer and result actions act
+ * on the owner's library (their delete would move an account's run to the owner's Trash).
+ */
+export function AccountRunsView() {
+ const viewer = useViewer();
+ const owner = !!viewer.data?.owner;
+ const router = useRouter();
+ const account = useSearchParams().get("account") ?? "";
+ const [status, setStatus] = useState<Status>("all");
+ const [kind, setKind] = useState<Kind>("all");
+ const accounts = useAdminAccounts(owner);
+ const act = useAdminAction();
+ const rows = accounts.data?.items;
+ const me = rows?.find((a) => a.id === account);
+ const gone = !!account && !!rows && !me;
+ const runs = useInfiniteQuery({
+ queryKey: ["admin-runs", { account, status, kind }],
+ enabled: owner,
+ initialPageParam: undefined as string | undefined,
+ queryFn: ({ pageParam }) => {
+ const q = new URLSearchParams({ limit: String(PAGE) });
+ if (account) q.set("account", account);
+ if (status !== "all") q.set("status", status);
+ if (kind !== "all") q.set("kind", kind);
+ if (pageParam) q.set("before", pageParam);
+ return adminCall<{ items: AdminRun[]; next: string | null }>(`/api/admin/generations?${q}`);
+ },
+ getNextPageParam: (last) => last.next ?? undefined,
+ placeholderData: keepPreviousData,
+ // While a run is going, its progress and result come in every 10 seconds.
+ refetchInterval: (q) => (q.state.data?.pages.some((p) => p.items.some((g) => g.status === "queued" || g.status === "running")) ? 10_000 : false),
+ });
+
+ if (viewer.isPending) return <GallerySkeleton cards={8} />;
+ if (!owner) return <PageHeader title="Accounts' runs" description="Only the studio's owner sees accounts' runs." />;
+
+ const switchAccount = (a: Pick<AccountRow, "id" | "email" | "disabled">) => {
+ if (!a.disabled && !window.confirm(`Switch ${a.email} off? They're signed out at once and can't log in until you switch them on again.`)) return;
+ void act(() => adminCall(`/api/admin/accounts/${a.id}`, "PATCH", { disabled: !a.disabled }), a.disabled ? "Switched on" : "Switched off");
+ };
+ const deleteRun = (g: AdminRun) => {
+ if (!window.confirm(`Delete this run by ${g.account.email ?? "a deleted account"} and its files? This can't be undone.`)) return;
+ void act(() => adminCall(`/api/admin/generations/${g.id}`, "DELETE"), "Run deleted");
+ };
+ const items = runs.data?.pages.flatMap((p) => p.items) ?? [];
+ const filtered = status !== "all" || kind !== "all";
+
+ return (
+ <>
+ {!account ? (
+ <PageHeader title="Accounts' runs" description="What people who signed up made on their own GPUs, newest first. Your own runs are in your Library." />
+ ) : gone ? (
+ <PageHeader title="Deleted account" description="This account no longer exists. Runs it left behind are listed until the next clean-up." />
+ ) : (
+ <PageHeader title={me?.email ?? "Accounts' runs"} description="This account's runs, newest first." />
+ )}
+
+ {me && (
+ <div className="mb-4 flex flex-wrap items-center gap-x-4 gap-y-2">
+ <dl className="flex flex-wrap items-center gap-x-4 gap-y-1 text-[12px]">
+ <Stat label="Runs">{me.runs}</Stat>
+ <Stat label="In 7 days">{me.runsWeek}</Stat>
+ <Stat label="Failed in 7 days" className={cn(me.failedWeek > 0 && "text-destructive")}>
+ {me.failedWeek}
+ </Stat>
+ <Stat label="Running now">{me.running}</Stat>
+ <Stat label="Last run">{me.lastRunAt ? timeAgo(me.lastRunAt) : "—"}</Stat>
+ <Stat label="Files" className={cn(me.bytes >= 0.9 * me.capBytes && "text-warning")}>
+ {storageSize(me.bytes)} of {storageSize(me.capBytes)}
+ </Stat>
+ <Stat label="GPU">{me.gpu ? "Connected" : "Not connected"}</Stat>
+ </dl>
+ {me.disabled && <OffBadge />}
+ <Button size="sm" variant="secondary" onClick={() => switchAccount(me)}>
+ {me.disabled ? <UserCheck /> : <UserX />} {me.disabled ? "Switch on" : "Switch off"}
+ </Button>
+ </div>
+ )}
+
+ <div className="mb-4 grid grid-cols-2 gap-2 sm:flex sm:flex-wrap sm:items-center">
+ <Select value={account || "all"} onValueChange={(id) => router.replace(runsHref(id === "all" ? undefined : id), { scroll: false })}>
+ <SelectTrigger className="col-span-2 w-full sm:col-span-1 sm:w-auto sm:max-w-80 sm:min-w-44" aria-label="Account">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="all">Every account</SelectItem>
+ {rows?.map((a) => (
+ <SelectItem key={a.id} value={a.id}>
+ {a.email}
+ {a.disabled ? " (off)" : ""}
+ </SelectItem>
+ ))}
+ {gone && <SelectItem value={account}>Deleted account</SelectItem>}
+ </SelectContent>
+ </Select>
+ <Select value={status} onValueChange={(v) => setStatus(v as Status)}>
+ <SelectTrigger className="w-full sm:w-auto sm:min-w-44" aria-label="Status">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {STATUSES.map(([v, label]) => (
+ <SelectItem key={v} value={v}>
+ {label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <Select value={kind} onValueChange={(v) => setKind(v as Kind)}>
+ <SelectTrigger className="w-full sm:w-auto sm:min-w-44" aria-label="Kind">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {KINDS.map(([v, label]) => (
+ <SelectItem key={v} value={v}>
+ {label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ {runs.isFetching && !runs.isFetchingNextPage && <Loader2 className="size-4 animate-spin text-muted-foreground" />}
+ </div>
+
+ {runs.isPending ? (
+ <div className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4" aria-busy="true" aria-label="Loading">
+ {Array.from({ length: 8 }, (_, i) => (
+ <div key={i} className="space-y-2">
+ <Skeleton className="aspect-square rounded-xl" />
+ <Skeleton className="h-3.5 w-2/3" />
+ <Skeleton className="h-3 w-full" />
+ </div>
+ ))}
+ </div>
+ ) : runs.isError && !runs.data ? (
+ <div className="space-y-2">
+ <p className="text-[13px] text-destructive">Couldn&apos;t load the runs. {runs.error.message}</p>
+ <Button size="sm" variant="secondary" onClick={() => void runs.refetch()}>
+ Try again
+ </Button>
+ </div>
+ ) : !items.length ? (
+ <div className="rounded-xl border border-dashed p-8 text-center text-[13px] text-muted-foreground">
+ {filtered ? (
+ <>
+ <p>No runs match these filters.</p>
+ <Button
+ size="sm"
+ variant="secondary"
+ className="mt-3"
+ onClick={() => {
+ setStatus("all");
+ setKind("all");
+ }}
+ >
+ Clear filters
+ </Button>
+ </>
+ ) : account ? (
+ <p>This account hasn&apos;t run anything yet.</p>
+ ) : (
+ <p>No runs yet. When someone who signed up runs something on their GPU, it shows here.</p>
+ )}
+ </div>
+ ) : (
+ <div className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4">
+ {items.map((g) => (
+ <RunCard key={g.id} g={g} one={!!account} row={rows?.find((a) => a.id === g.account.id)} onSwitch={switchAccount} onDelete={deleteRun} />
+ ))}
+ </div>
+ )}
+
+ {runs.hasNextPage && (
+ <div className="mt-6 flex justify-center">
+ <Button variant="secondary" size="sm" disabled={runs.isFetchingNextPage} onClick={() => void runs.fetchNextPage()}>
+ {runs.isFetchingNextPage ? (
+ <>
+ <Loader2 className="animate-spin" /> Loading…
+ </>
+ ) : (
+ "Load more"
+ )}
+ </Button>
+ </div>
+ )}
+ </>
+ );
+}
+
+/**
+ * One run: its result (a picture opens full size, a clip plays on hover or a tap, sound has its player), what made it,
+ * the prompt, its status and when. `one`: the page shows one account, so the email is left out; `row`: the account's
+ * row (its off state), absent when the account is gone.
+ */
+function RunCard({ g, one, row, onSwitch, onDelete }: { g: AdminRun; one: boolean; row?: AccountRow; onSwitch: (a: AccountRow) => void; onDelete: (g: AdminRun) => void }) {
+ const out = g.status === "succeeded" ? g.outputs[0] : undefined;
+ // Whether the clip was paused when the press began: a tap's emulated hover starts it just before the click.
+ const paused = useRef(true);
+ return (
+ <div className="min-w-0">
+ <div
+ className="relative aspect-square overflow-hidden rounded-xl border bg-muted"
+ onPointerDown={(e) => {
+ paused.current = e.currentTarget.querySelector("video")?.paused ?? true;
+ }}
+ onClick={(e) => {
+ const v = e.currentTarget.querySelector("video");
+ if (!v) return;
+ if (paused.current) void v.play().catch(() => {});
+ else v.pause();
+ }}
+ >
+ {!out ? (
+ <StatusCover g={g} />
+ ) : out.kind === "image" ? (
+ <a href={out.url} target="_blank" rel="noreferrer" aria-label="Open the picture" className="block size-full">
+ <MediaThumb output={out} g={g} />
+ </a>
+ ) : (
+ <MediaThumb output={out} g={g} />
+ )}
+ {g.outputs.length > 1 && <span className="absolute right-2 bottom-2 rounded-md bg-black/60 px-1.5 py-0.5 text-[11px] text-white">{g.outputs.length}</span>}
+ </div>
+ <div className="relative mt-2 min-w-0 space-y-0.5 pr-8">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button size="icon" variant="ghost" className="absolute -top-1 right-0 size-7 text-muted-foreground" aria-label="Run actions">
+ <MoreHorizontal className="size-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ {g.outputs[0] && (
+ <DropdownMenuItem asChild>
+ <a href={g.outputs[0].url} target="_blank" rel="noreferrer">
+ <ExternalLink /> Open file
+ </a>
+ </DropdownMenuItem>
+ )}
+ {!one && (
+ <DropdownMenuItem asChild>
+ <Link href={runsHref(g.account.id)}>
+ <Filter /> Only this account
+ </Link>
+ </DropdownMenuItem>
+ )}
+ {row && (
+ <DropdownMenuItem onClick={() => onSwitch(row)}>
+ {row.disabled ? <UserCheck /> : <UserX />} {row.disabled ? "Switch account on" : "Switch account off"}
+ </DropdownMenuItem>
+ )}
+ <DropdownMenuSeparator />
+ <DropdownMenuItem variant="destructive" onClick={() => onDelete(g)}>
+ <Trash2 /> Delete run
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ {!one && (
+ <div className="flex min-w-0 items-center gap-1.5 text-[12px] font-medium">
+ {g.account.email ? (
+ <Link href={runsHref(g.account.id)} className="truncate underline-offset-2 hover:underline">
+ {g.account.email}
+ </Link>
+ ) : (
+ <span className="truncate text-muted-foreground">Deleted account</span>
+ )}
+ {row?.disabled && <OffBadge />}
+ </div>
+ )}
+ <p className="truncate text-[13px] font-medium">{g.presetName ?? featureName(g.feature)}</p>
+ <p className="truncate text-[12px] text-muted-foreground">
+ {g.modelName ?? g.modelId} · {OPERATION_LABELS[g.op] ?? g.op}
+ </p>
+ <RunWords g={g} />
+ <p className="truncate text-[12px] text-muted-foreground">
+ <span className={cn(g.status === "failed" ? "text-destructive" : (g.status === "queued" || g.status === "running") && "text-foreground")}>
+ {STATUS_LABELS[g.status]}
+ {g.status === "running" && g.progress != null ? ` · ${Math.round(g.progress * 100)}%` : ""}
+ </span>
+ {" · "}
+ <span title={new Date(g.createdAt).toLocaleString()}>{timeAgo(g.createdAt)}</span>
+ </p>
+ </div>
+ </div>
+ );
+}
+
+/** The prompt, two lines until "More" opens it whole, with a failed run's whole error. */
+function RunWords({ g }: { g: AdminRun }) {
+ const [open, setOpen] = useState(false);
+ const prompt = g.request.prompt?.trim() || g.prompt?.trim();
+ const error = g.status === "failed" ? g.error : null;
+ return (
+ <div className="text-[12px]">
+ {prompt ? <p className={cn("break-words", open ? "whitespace-pre-wrap" : "line-clamp-2")}>{prompt}</p> : <p className="text-muted-foreground italic">No prompt</p>}
+ {open && error && <p className="mt-1 break-words whitespace-pre-wrap text-destructive">{error}</p>}
+ {((prompt?.length ?? 0) > 120 || error) && (
+ <button type="button" className="text-muted-foreground underline-offset-2 hover:text-foreground hover:underline" aria-expanded={open} onClick={() => setOpen(!open)}>
+ {open ? "Less" : "More"}
+ </button>
+ )}
+ </div>
+ );
+}
diff --git a/src/components/accounts-admin.tsx b/src/components/accounts-admin.tsx
index b647160c..58c07fdc 100644
--- a/src/components/accounts-admin.tsx
+++ b/src/components/accounts-admin.tsx
@@ -1,22 +1,45 @@
"use client";
import { useQuery, useQueryClient } from "@tanstack/react-query";
-import { Download, Loader2, Trash2, UserX, UserCheck } from "lucide-react";
+import { Download, Images, Loader2, Trash2, UserX, UserCheck } from "lucide-react";
+import Link from "next/link";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { useViewer } from "@/lib/api";
-import { timeAgo } from "@/lib/format";
+import { storageSize, timeAgo } from "@/lib/format";
+import { cn } from "@/lib/utils";
-interface AccountRow {
+/** An account as GET /api/admin/accounts lists it: who, and what it made (src/server/account-admin.ts). */
+export interface AccountRow {
id: string;
email: string;
createdAt: number;
lastLoginAt: number | null;
disabled: boolean;
gpu: boolean;
+ /** Runs: all time, the last 24 hours and 7 days, going now, failed in the last 7 days. */
+ runs: number;
+ runsDay: number;
+ runsWeek: number;
+ running: number;
+ failedWeek: number;
+ lastRunAt: number | null;
+ /** Its files on this server, and what it may keep. */
+ bytes: number;
+ capBytes: number;
}
-async function call<T>(url: string, method = "GET", body?: unknown): Promise<T> {
+/** Every account's runs and files together; `shareBytes`: the part of the disk accounts may take (null: unknown). */
+export interface AccountTotals {
+ accounts: number;
+ runsDay: number;
+ runsWeek: number;
+ running: number;
+ bytes: number;
+ shareBytes: number | null;
+}
+
+export async function adminCall<T>(url: string, method = "GET", body?: unknown): Promise<T> {
const res = await fetch(url, { method, headers: { "Content-Type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) });
if (res.status === 204) return undefined as T;
const j = (await res.json().catch(() => ({}))) as T & { error?: string };
@@ -24,24 +47,56 @@ async function call<T>(url: string, method = "GET", body?: unknown): Promise<T>
return j;
}
-/** Settings → Accounts (the owner only): who signed up (public sign-up), with switch-off, delete and a CSV export. */
-export function AccountsAdmin() {
- const owner = useViewer().data?.owner;
+/** Everyone who signed up, with their numbers (the owner only). Settings and the runs page share it; it refreshes while runs are going. */
+export function useAdminAccounts(enabled: boolean) {
+ return useQuery({
+ queryKey: ["admin-accounts"],
+ queryFn: () => adminCall<{ total: number; items: AccountRow[]; totals: AccountTotals }>("/api/admin/accounts"),
+ enabled,
+ refetchInterval: (q) => (q.state.data?.totals.running ? 15_000 : false),
+ });
+}
+
+/** Do one of the owner's account actions, say how it went, and refresh the accounts and their runs. */
+export function useAdminAction() {
const qc = useQueryClient();
- const q = useQuery({ queryKey: ["admin-accounts"], queryFn: () => call<{ total: number; items: AccountRow[] }>("/api/admin/accounts"), enabled: !!owner });
- if (!owner || !q.data) return null;
- const refresh = () => void qc.invalidateQueries({ queryKey: ["admin-accounts"] });
- const act = async (fn: () => Promise<unknown>, done: string) => {
+ return async (fn: () => Promise<unknown>, done: string) => {
try {
await fn();
toast.success(done);
} catch (e) {
toast.error((e as Error).message);
} finally {
- refresh();
+ void qc.invalidateQueries({ queryKey: ["admin-accounts"] });
+ void qc.invalidateQueries({ queryKey: ["admin-runs"] });
}
};
- const { total, items } = q.data;
+}
+
+/** One number in a line of them (inside a `dl`): its label, then the number. */
+export function Stat({ label, className, children }: { label: string; className?: string; children: React.ReactNode }) {
+ return (
+ <div className="flex items-baseline gap-1.5">
+ <dt className="text-muted-foreground">{label}</dt>
+ <dd className={cn("font-medium whitespace-nowrap tabular-nums", className)}>{children}</dd>
+ </div>
+ );
+}
+
+/** The account is switched off. */
+export function OffBadge({ className }: { className?: string }) {
+ return <span className={cn("rounded-sm bg-muted px-1 py-0.5 text-[10px] font-normal text-muted-foreground", className)}>off</span>;
+}
+
+const runsHref = (id: string) => `/settings/runs?account=${encodeURIComponent(id)}`;
+
+/** Settings → Accounts (the owner only): who signed up (public sign-up), what each made and the space it takes, with switch-off, delete and a CSV export. */
+export function AccountsAdmin() {
+ const owner = useViewer().data?.owner;
+ const q = useAdminAccounts(!!owner);
+ const act = useAdminAction();
+ if (!owner || (!q.data && !q.isError)) return null;
+ const total = q.data?.total ?? 0;
return (
<section id="accounts" aria-labelledby="accounts-title" className="grid scroll-mt-28 grid-cols-[minmax(0,1fr)] gap-6 border-t py-8 md:scroll-mt-20 md:grid-cols-[260px_minmax(0,1fr)]">
<div className="min-w-0">
@@ -49,71 +104,123 @@ export function AccountsAdmin() {
Accounts
</h2>
<p className="mt-1 text-[13px] text-muted-foreground">
- {total} {total === 1 ? "person has" : "people have"} signed up (Settings → Security → Public sign-up). Accounts never see your library or use your keys and GPU.
+ {q.data && (
+ <>
+ {total} {total === 1 ? "person has" : "people have"} signed up (Settings → Security → Public sign-up).{" "}
+ </>
+ )}
+ Accounts never see your library or use your keys and GPU. What they make stays out of your library: see it here.
</p>
</div>
- <div className="min-w-0 space-y-3">
- <div className="flex flex-wrap items-center gap-2">
- <Button asChild size="sm" variant="secondary" disabled={!total}>
- <a href="/api/admin/accounts?format=csv" download>
- <Download /> Export CSV
- </a>
+ {!q.data ? (
+ <div className="min-w-0 space-y-3">
+ <p className="text-[13px] text-destructive">Couldn&apos;t load the accounts. {q.error?.message}</p>
+ <Button size="sm" variant="secondary" disabled={q.isFetching} onClick={() => void q.refetch()}>
+ Try again
</Button>
- {q.isFetching && <Loader2 className="size-4 animate-spin text-muted-foreground" />}
</div>
- {items.length > 0 && (
- <div className="overflow-x-auto rounded-xl border">
- <table className="w-full text-left text-[12px]">
- <thead className="bg-muted/50 text-muted-foreground">
- <tr>
- <th className="px-3 py-2 font-medium">Email</th>
- <th className="px-3 py-2 font-medium">Created</th>
- <th className="px-3 py-2 font-medium">Last login</th>
- <th className="px-3 py-2 font-medium">GPU</th>
- <th className="px-3 py-2" />
- </tr>
- </thead>
- <tbody className="divide-y">
- {items.map((a) => (
- <tr key={a.id} className={a.disabled ? "text-muted-foreground" : undefined}>
- <td className="max-w-56 truncate px-3 py-2 font-medium">
- {a.email}
- {a.disabled && <span className="ml-1.5 rounded-sm bg-muted px-1 py-0.5 text-[10px] font-normal">off</span>}
- </td>
- <td className="px-3 py-2 whitespace-nowrap">{timeAgo(a.createdAt)}</td>
- <td className="px-3 py-2 whitespace-nowrap">{a.lastLoginAt ? timeAgo(a.lastLoginAt) : "—"}</td>
- <td className="px-3 py-2">{a.gpu ? "Connected" : "—"}</td>
- <td className="px-2 py-1 text-right whitespace-nowrap">
- <Button
- size="icon"
- variant="ghost"
- className="size-7 text-muted-foreground"
- aria-label={a.disabled ? `Switch ${a.email} on` : `Switch ${a.email} off`}
- title={a.disabled ? "Switch on" : "Switch off"}
- onClick={() => void act(() => call(`/api/admin/accounts/${a.id}`, "PATCH", { disabled: !a.disabled }), a.disabled ? "Switched on" : "Switched off")}
- >
- {a.disabled ? <UserCheck className="size-3.5" /> : <UserX className="size-3.5" />}
- </Button>
- <Button
- size="icon"
- variant="ghost"
- className="size-7 text-muted-foreground hover:text-destructive"
- aria-label={`Delete ${a.email}`}
- title="Delete"
- onClick={() => {
- if (window.confirm(`Delete the account ${a.email}?`)) void act(() => call(`/api/admin/accounts/${a.id}`, "DELETE"), "Account deleted");
- }}
- >
- <Trash2 className="size-3.5" />
- </Button>
- </td>
- </tr>
- ))}
- </tbody>
- </table>
+ ) : (
+ <div className="min-w-0 space-y-3">
+ {total > 0 && (
+ <dl className="flex flex-wrap gap-x-4 gap-y-1 text-[12px]">
+ <Stat label="Runs in 24 hours">{q.data.totals.runsDay}</Stat>
+ <Stat label="Runs in 7 days">{q.data.totals.runsWeek}</Stat>
+ <Stat label="Running now">{q.data.totals.running}</Stat>
+ <Stat label="Files">
+ {storageSize(q.data.totals.bytes)}
+ {q.data.totals.shareBytes ? ` of ${storageSize(q.data.totals.shareBytes)}` : ""}
+ </Stat>
+ </dl>
+ )}
+ <div className="flex flex-wrap items-center gap-2">
+ <Button asChild size="sm" variant="secondary" disabled={!total}>
+ <Link href="/settings/runs">
+ <Images /> All accounts&apos; runs
+ </Link>
+ </Button>
+ <Button asChild size="sm" variant="secondary" disabled={!total}>
+ <a href="/api/admin/accounts?format=csv" download>
+ <Download /> Export CSV
+ </a>
+ </Button>
+ {q.isFetching && <Loader2 className="size-4 animate-spin text-muted-foreground" />}
</div>
- )}
- </div>
+ {q.data.items.length > 0 && (
+ <div className="overflow-x-auto rounded-xl border">
+ <table className="w-full text-left text-[12px]">
+ <thead className="bg-muted/50 text-muted-foreground">
+ <tr>
+ <th className="px-3 py-2 font-medium">Email</th>
+ <th className="px-3 py-2 font-medium">Runs</th>
+ <th className="px-3 py-2 font-medium">Last run</th>
+ <th className="px-3 py-2 font-medium">Space</th>
+ <th className="px-3 py-2 font-medium">GPU</th>
+ <th className="px-3 py-2 font-medium max-sm:hidden">Created</th>
+ <th className="px-3 py-2 font-medium max-sm:hidden">Last login</th>
+ <th className="px-3 py-2" />
+ </tr>
+ </thead>
+ <tbody className="divide-y">
+ {q.data.items.map((a) => (
+ <tr key={a.id} className={a.disabled ? "text-muted-foreground" : undefined}>
+ <td className="max-w-56 truncate px-3 py-2 font-medium">
+ {a.email}
+ {a.disabled && <OffBadge className="ml-1.5" />}
+ </td>
+ <td className="px-3 py-2">
+ <Link href={runsHref(a.id)} className="font-medium tabular-nums underline-offset-2 hover:underline">
+ {a.runs}
+ </Link>
+ <div className="text-[11px] whitespace-nowrap text-muted-foreground">
+ {a.runsWeek} in 7 days
+ {a.failedWeek > 0 && <span className="text-destructive"> · {a.failedWeek} failed</span>}
+ {a.running > 0 && ` · ${a.running} running`}
+ </div>
+ </td>
+ <td className="px-3 py-2 whitespace-nowrap">{a.lastRunAt ? timeAgo(a.lastRunAt) : "—"}</td>
+ <td className={cn("px-3 py-2 whitespace-nowrap", a.bytes >= 0.9 * a.capBytes && "text-warning")} title="Uploads and results kept on this server">
+ {storageSize(a.bytes)} of {storageSize(a.capBytes)}
+ </td>
+ <td className="px-3 py-2">{a.gpu ? "Connected" : "—"}</td>
+ <td className="px-3 py-2 whitespace-nowrap max-sm:hidden">{timeAgo(a.createdAt)}</td>
+ <td className="px-3 py-2 whitespace-nowrap max-sm:hidden">{a.lastLoginAt ? timeAgo(a.lastLoginAt) : "—"}</td>
+ <td className="px-2 py-1 text-right whitespace-nowrap">
+ <Button asChild size="icon" variant="ghost" className="size-7 text-muted-foreground">
+ <Link href={runsHref(a.id)} aria-label={`Runs by ${a.email}`} title="Runs">
+ <Images className="size-3.5" />
+ </Link>
+ </Button>
+ <Button
+ size="icon"
+ variant="ghost"
+ className="size-7 text-muted-foreground"
+ aria-label={a.disabled ? `Switch ${a.email} on` : `Switch ${a.email} off`}
+ title={a.disabled ? "Switch on" : "Switch off"}
+ onClick={() => void act(() => adminCall(`/api/admin/accounts/${a.id}`, "PATCH", { disabled: !a.disabled }), a.disabled ? "Switched on" : "Switched off")}
+ >
+ {a.disabled ? <UserCheck className="size-3.5" /> : <UserX className="size-3.5" />}
+ </Button>
+ <Button
+ size="icon"
+ variant="ghost"
+ className="size-7 text-muted-foreground hover:text-destructive"
+ aria-label={`Delete ${a.email}`}
+ title="Delete"
+ onClick={() => {
+ if (window.confirm(`Delete the account ${a.email}?`)) void act(() => adminCall(`/api/admin/accounts/${a.id}`, "DELETE"), "Account deleted");
+ }}
+ >
+ <Trash2 className="size-3.5" />
+ </Button>
+ </td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </div>
+ )}
+ </div>
+ )}
</section>
);
}
diff --git a/src/components/library/asset-card.tsx b/src/components/library/asset-card.tsx
index 742e4cdd..95d6b71a 100644
--- a/src/components/library/asset-card.tsx
+++ b/src/components/library/asset-card.tsx
@@ -41,7 +41,7 @@ const LIST_MENU ="grid size-8 shrink-0 place-items-center rounded-lg text-muted-
const idsOf = (e: LibraryEntry) => (e.type === "single" ? [e.g.id] : e.items.map((g) => g.id));
-function StatusCover({ g }: { g: Generation }) {
+export function StatusCover({ g }: { g: Generation }) {
if (g.status === "queued" || g.status === "running") {
const pct = g.progress != null ? Math.round(g.progress * 100) : null;
return (
diff --git a/tests/settings-links.test.ts b/tests/settings-links.test.ts
index cae146ea..fa72e9f3 100644
--- a/tests/settings-links.test.ts
+++ b/tests/settings-links.test.ts
@@ -7,8 +7,9 @@ import { describe, expect, it } from "vitest";
const root = path.join(__dirname, "../src");
const files = (d: string): string[] => fs.readdirSync(d, { withFileTypes: true }).flatMap((e) => (e.isDirectory() ? files(path.join(d, e.name)) : /\.tsx?$/.test(e.name) ? [path.join(d, e.name)] : []));
const form = fs.readFileSync(path.join(root, "components/settings-form.tsx"), "utf8");
-/** The anchors Settings has: its sections' and fields' ids (id="…", or a Section's id prop on its own line). */
-const anchors = new Set([...form.matchAll(/\bid="([a-z0-9-]+)"/g)].map((m) => m[1]));
+/** The anchors Settings has: its sections' and fields' ids (id="…", or a Section's id prop on its own line), the form's and the sections around it. */
+const page = [form, ...["components/gpu/account-gpu-section.tsx", "components/accounts-admin.tsx"].map((f) => fs.readFileSync(path.join(root, f), "utf8"))].join("\n");
+const anchors = new Set([...page.matchAll(/\bid="([a-z0-9-]+)"/g)].map((m) => m[1]));
describe("Settings deep links", () => {
it("every /settings#… link in the app has its anchor", () => {