From 22317a2fae8f8a8ed45f313a46bb2489b8042f92 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Tue, 3 Feb 2026 20:16:19 -0500 Subject: [PATCH] feat: add statistics page --- .../src/routes/stats/+page.server.ts | 23 ++++ .../src/routes/stats/+page.svelte | 116 ++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 SharpbinV3.Client/src/routes/stats/+page.server.ts create mode 100644 SharpbinV3.Client/src/routes/stats/+page.svelte diff --git a/SharpbinV3.Client/src/routes/stats/+page.server.ts b/SharpbinV3.Client/src/routes/stats/+page.server.ts new file mode 100644 index 0000000..a79c077 --- /dev/null +++ b/SharpbinV3.Client/src/routes/stats/+page.server.ts @@ -0,0 +1,23 @@ +import type { PageServerLoad } from './$types'; +import { env } from '$env/dynamic/private'; +import { error, isHttpError } from '@sveltejs/kit'; +import { extractError } from '$lib/utils/misc'; + +const API_URL = env.VITE_API_URL ?? 'http://localhost:5050'; + +export const load: PageServerLoad = async ({ fetch }) => { + try { + const res = await fetch(`${API_URL}/api/stats`); + + if (!res.ok) { + const json = await res.json().catch(() => ({})); + const message = extractError(json); + throw error(res.status, message ?? 'Failed to load statistics'); + } + const stats = await res.json(); + return { stats }; + } catch (e) { + if (isHttpError(e)) throw e; + throw error(500, 'Failed to load statistics'); + } +}; diff --git a/SharpbinV3.Client/src/routes/stats/+page.svelte b/SharpbinV3.Client/src/routes/stats/+page.svelte new file mode 100644 index 0000000..4f18d0a --- /dev/null +++ b/SharpbinV3.Client/src/routes/stats/+page.svelte @@ -0,0 +1,116 @@ + + + + Statistics - Sharpbin + + +
+
+

Statistics

+
+
+
+ +
+
+

Total Pastes

+

{formatNumber(stats.pastes.total)}

+
+
+
+
+ +
+
+

Last 7 Days

+

{formatNumber(stats.pastes.past7Days)}

+
+
+
+
+ +
+
+

Total Storage Used

+

{formatBytes(stats.pastes.totalSizeInBytes)}

+
+
+
+
+ +
+
+

Total Users

+

{formatNumber(stats.users.total)}

+
+
+
+ +
+

Pastes Growth (Last 7 Days)

+
+ {#if dailyData.length > 0} + {#each dailyData as d} +
+
+
+ {formatDate(d.date)} +
+
+ {/each} + {:else} +
+ No data available for the last 7 days. +
+ {/if} +
+
+
+
+