your personal website on atproto - mirror blento.app

add /random route

Florian a8c1656e 3d4c2041

+34
+27
src/routes/random/+page.server.ts
··· 1 + import type { UserCache, WebsiteData } from '$lib/types.js'; 2 + import { getCache } from '$lib/website/load.js'; 3 + import { error } from '@sveltejs/kit'; 4 + 5 + export async function load({ platform }) { 6 + const cache = platform?.env?.USER_DATA_CACHE; 7 + 8 + const list = await cache?.list(); 9 + 10 + if (!list) { 11 + throw error(404); 12 + } 13 + 14 + let foundData: WebsiteData | undefined = undefined; 15 + let i = 0; 16 + 17 + while (!foundData && i < 10) { 18 + const rando = Math.floor(Math.random() * list.keys.length); 19 + 20 + foundData = await getCache(list.keys[rando].name, 'self', cache as unknown as UserCache); 21 + i++; 22 + } 23 + 24 + if (!foundData) throw error(404); 25 + 26 + return foundData; 27 + }
+7
src/routes/random/+page.svelte
··· 1 + <script lang="ts"> 2 + import Website from '$lib/website/Website.svelte'; 3 + 4 + let { data } = $props(); 5 + </script> 6 + 7 + <Website {data} />