tangled
alpha
login
or
join now
flo-bit.dev
/
blento
your personal website on atproto - mirror
blento.app
20
fork
atom
overview
issues
pulls
pipelines
change github activity fetching
Florian
3 weeks ago
b2e41b67
fb67283a
+9
-63
2 changed files
expand all
collapse all
unified
split
src
lib
cards
GitHubProfileCard
GitHubProfileCard.svelte
routes
api
github
+server.ts
+2
-14
src/lib/cards/GitHubProfileCard/GitHubProfileCard.svelte
···
38
38
</script>
39
39
40
40
<div class="h-full overflow-hidden p-4">
41
41
-
{#if contributionsData}
42
41
<div class="flex h-full flex-col justify-between">
43
42
<!-- Header -->
44
43
<div class="flex justify-between">
···
66
65
{/if}
67
66
</div>
68
67
68
68
+
{#if contributionsData}
69
69
<div class="flex">
70
70
<GithubContributionsGraph
71
71
data={contributionsData}
72
72
isBig={isMobile() ? item.mobileH > 5 : item.h > 2}
73
73
/>
74
74
</div>
75
75
-
</div>
76
76
-
{:else if isLoaded}
77
77
-
<div
78
78
-
class="text-base-600 dark:text-base-400 accent:text-base-800 flex h-full w-full items-center justify-center text-sm"
79
79
-
>
80
80
-
Could not load GitHub contributions
75
75
+
{/if}
81
76
</div>
82
82
-
{:else}
83
83
-
<div
84
84
-
class="text-base-600 dark:text-base-400 accent:text-base-800 flex h-full w-full items-center justify-center text-sm"
85
85
-
>
86
86
-
Loading contributions...
87
87
-
</div>
88
88
-
{/if}
89
77
</div>
90
78
91
79
{#if item.cardData.href}
+7
-49
src/routes/api/github/+server.ts
···
1
1
import { json } from '@sveltejs/kit';
2
2
import type { RequestHandler } from './$types';
3
3
-
import { env } from '$env/dynamic/private';
4
3
import type { GitHubContributionsData } from '$lib/cards/GitHubProfileCard/types';
5
4
6
6
-
const GITHUB_GRAPHQL_URL = 'https://api.github.com/graphql';
7
7
-
8
8
-
const CONTRIBUTIONS_QUERY = `
9
9
-
query($login: String!) {
10
10
-
user(login: $login) {
11
11
-
login
12
12
-
avatarUrl
13
13
-
contributionsCollection {
14
14
-
contributionCalendar {
15
15
-
totalContributions
16
16
-
weeks {
17
17
-
contributionDays {
18
18
-
date
19
19
-
contributionCount
20
20
-
color
21
21
-
}
22
22
-
}
23
23
-
}
24
24
-
}
25
25
-
followers {
26
26
-
totalCount
27
27
-
}
28
28
-
}
29
29
-
}
30
30
-
`;
5
5
+
const GithubAPIURL = 'https://edge-function-github-contribution.vercel.app/api/github-data?user=';
31
6
32
7
export const GET: RequestHandler = async ({ url, platform }) => {
33
8
const user = url.searchParams.get('user');
···
49
24
}
50
25
}
51
26
52
52
-
const token = env.GITHUB_TOKEN;
53
53
-
54
54
-
if (!token) {
55
55
-
return json({ error: 'GitHub token not configured' }, { status: 500 });
56
56
-
}
57
57
-
58
27
try {
59
59
-
const response = await fetch(GITHUB_GRAPHQL_URL, {
60
60
-
method: 'POST',
61
61
-
headers: {
62
62
-
'Content-Type': 'application/json',
63
63
-
Authorization: `Bearer ${token}`
64
64
-
},
65
65
-
body: JSON.stringify({
66
66
-
query: CONTRIBUTIONS_QUERY,
67
67
-
variables: { login: user }
68
68
-
})
69
69
-
});
28
28
+
const response = await fetch(GithubAPIURL + user);
29
29
+
console.log('hello', user);
70
30
71
31
if (!response.ok) {
32
32
+
console.log('error', response.statusText);
72
33
return json(
73
34
{ error: 'Failed to fetch GitHub data ' + response.statusText },
74
35
{ status: response.status }
···
77
38
78
39
const data = await response.json();
79
40
80
80
-
if (data.errors) {
81
81
-
return json({ error: data.errors[0]?.message || 'GraphQL error' }, { status: 400 });
82
82
-
}
83
83
-
84
84
-
if (!data.data?.user) {
41
41
+
if (!data?.user) {
42
42
+
console.log('user not found', response.statusText);
85
43
return json({ error: 'User not found' }, { status: 404 });
86
44
}
87
45
88
88
-
const result = data.data.user as GitHubContributionsData;
46
46
+
const result = data.user as GitHubContributionsData;
89
47
result.updatedAt = Date.now();
90
48
91
49
await platform?.env?.USER_DATA_CACHE?.put('#github:' + user, JSON.stringify(result));