Show SPA e621 request times in the status pill

- New e621 metrics store tracks request count, cumulative time and the
  last request (path + duration) for the session
- The e621 client measures each request around fetch and JSON parsing
- Status pill appends a teal 'e621: <total>' segment with a tooltip
  showing request count and the last request; a server-side e621 time
  is shown separately if the backend ever reports one
This commit is contained in:
2026-09-17 10:32:51 -05:00
parent ebac3ac922
commit afca89de8f
3 changed files with 81 additions and 20 deletions
+26 -18
View File
@@ -1,10 +1,11 @@
import { useE621Metrics } from "@/store/e621Metrics";
export interface E621Credentials {
username: string;
api_key: string;
base_url: string;
configured: boolean;
}
export interface E621User {
id: number;
name: string;
@@ -141,26 +142,33 @@ export function e621Request<T>(
);
}
const response = await fetch(url, {
method: options.method ?? "GET",
headers,
body: options.body,
signal: options.signal,
});
const startedAt = performance.now();
try {
const response = await fetch(url, {
method: options.method ?? "GET",
headers,
body: options.body,
signal: options.signal,
});
if (!response.ok) {
let data: unknown = null;
try {
data = await response.json();
} catch {
data = null;
if (!response.ok) {
let data: unknown = null;
try {
data = await response.json();
} catch {
data = null;
}
throw new E621Error(response.status, data);
}
throw new E621Error(response.status, data);
if (response.status === 204) {
return undefined as T;
}
return (await response.json()) as T;
} finally {
useE621Metrics
.getState()
.record(path, performance.now() - startedAt);
}
if (response.status === 204) {
return undefined as T;
}
return (await response.json()) as T;
});
}