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