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