mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: add recent pastes page with data fetching and display logic
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import type { Paste } from '$lib/types/paste';
|
||||
import { extractError } from '$lib/utils/misc';
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch }) => {
|
||||
try {
|
||||
const res = await fetch('/api/paste/recent');
|
||||
if (!res.ok) {
|
||||
const errorMsg = extractError(await res.json()) || 'Failed to fetch recent pastes.';
|
||||
throw new Error(errorMsg);
|
||||
}
|
||||
const recentPastes: Paste[] = await res.json();
|
||||
return { recentPastes };
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
return { recentPastes: [] };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user