tangled
alpha
login
or
join now
flo-bit.dev
/
blento
21
fork
atom
your personal website on atproto - mirror
blento.app
21
fork
atom
overview
issues
pulls
pipelines
add /random route
Florian
2 months ago
a8c1656e
3d4c2041
+34
2 changed files
expand all
collapse all
unified
split
src
routes
random
+page.server.ts
+page.svelte
+27
src/routes/random/+page.server.ts
···
1
1
+
import type { UserCache, WebsiteData } from '$lib/types.js';
2
2
+
import { getCache } from '$lib/website/load.js';
3
3
+
import { error } from '@sveltejs/kit';
4
4
+
5
5
+
export async function load({ platform }) {
6
6
+
const cache = platform?.env?.USER_DATA_CACHE;
7
7
+
8
8
+
const list = await cache?.list();
9
9
+
10
10
+
if (!list) {
11
11
+
throw error(404);
12
12
+
}
13
13
+
14
14
+
let foundData: WebsiteData | undefined = undefined;
15
15
+
let i = 0;
16
16
+
17
17
+
while (!foundData && i < 10) {
18
18
+
const rando = Math.floor(Math.random() * list.keys.length);
19
19
+
20
20
+
foundData = await getCache(list.keys[rando].name, 'self', cache as unknown as UserCache);
21
21
+
i++;
22
22
+
}
23
23
+
24
24
+
if (!foundData) throw error(404);
25
25
+
26
26
+
return foundData;
27
27
+
}
+7
src/routes/random/+page.svelte
···
1
1
+
<script lang="ts">
2
2
+
import Website from '$lib/website/Website.svelte';
3
3
+
4
4
+
let { data } = $props();
5
5
+
</script>
6
6
+
7
7
+
<Website {data} />