your personal website on atproto - mirror blento.app
at map 29 lines 692 B view raw
1import type { UserCache, WebsiteData } from '$lib/types.js'; 2import { getCache } from '$lib/website/load.js'; 3import { error } from '@sveltejs/kit'; 4 5export 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 < 20) { 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 22 if (!foundData?.cards.length) foundData = undefined; 23 i++; 24 } 25 26 if (!foundData) throw error(404); 27 28 return foundData; 29}