27 lines
839 B
TypeScript
27 lines
839 B
TypeScript
import type { ImmichServiceWidget } from "@/lib/config/schema";
|
|||
|
|
import type { ServiceStat } from "@/lib/types/service-result";
|
||
|
|
import { serviceBaseUrl } from "./base-url";
|
||
|
|
|
||
|
|
interface ImmichStatistics {
|
||
|
|
photos: number;
|
||
|
|
videos: number;
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function collectImmich(widget: ImmichServiceWidget): Promise<{ stats: ServiceStat[] }> {
|
||
|
|
const base = serviceBaseUrl(widget);
|
||
|
|
const response = await fetch(`${base}/api/server/statistics`, {
|
||
|
|
headers: { "x-api-key": widget.apiKey },
|
||
|
|
signal: AbortSignal.timeout(5_000),
|
||
|
|
});
|
||
|
|
if (!response.ok) {
|
||
|
|
throw new Error(`Immich API returned ${response.status}`);
|
||
|
|
}
|
||
|
|
const stats = (await response.json()) as ImmichStatistics;
|
||
|
|
return {
|
||
|
|
stats: [
|
||
|
|
{ label: "Photos", value: String(stats.photos) },
|
||
|
|
{ label: "Videos", value: String(stats.videos) },
|
||
|
|
],
|
||
|
|
};
|
||
|
|
}
|