mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: add statistics page
This commit is contained in:
@@ -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');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user