your personal website on atproto - mirror
blento.app
1import { query, getRequestEvent } from '$app/server';
2import { createCache } from '$lib/cache';
3
4const LEADERBOARD_API_URL =
5 'https://npmx-likes-leaderboard-api-production.up.railway.app/api/leaderboard/likes?limit=20';
6
7export const fetchNpmxLeaderboard = query(async () => {
8 const { platform } = getRequestEvent();
9 const cache = createCache(platform);
10
11 const cached = await cache?.get('npmx', 'likes');
12 if (cached) return JSON.parse(cached);
13
14 const response = await fetch(LEADERBOARD_API_URL);
15 if (!response.ok) return undefined;
16
17 const data = await response.json();
18 await cache?.put('npmx', 'likes', JSON.stringify(data));
19 return data;
20});