your personal website on atproto - mirror
blento.app
1import { query, getRequestEvent } from '$app/server';
2import { createCache } from '$lib/cache';
3
4const GITHUB_API_URL = 'https://edge-function-github-contribution.vercel.app/api/github-data?user=';
5
6export const fetchGitHubContributions = query('unchecked', async (user: string) => {
7 const { platform } = getRequestEvent();
8 const cache = createCache(platform);
9
10 const cached = await cache?.get('github', user);
11 if (cached) return JSON.parse(cached);
12
13 const response = await fetch(GITHUB_API_URL + encodeURIComponent(user));
14 if (!response.ok) return undefined;
15
16 const data = await response.json();
17 if (!data?.user) return undefined;
18
19 await cache?.put('github', user, JSON.stringify(data.user));
20 return data.user;
21});