Skip to content

Commit c5ed35d

Browse files
feat: add Unsplash Stats from both profiles
1 parent 2e1654b commit c5ed35d

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

.github/workflows/astro.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
cache: ${{ steps.detect-package-manager.outputs.manager }}
5656
cache-dependency-path: ${{ env.BUILD_PATH }}/package-lock.json
5757
- name: Create .env file
58-
run: echo "UNSPLASH_ACCESS_KEY=${{ secrets.UNSPLASH_ACCESS_KEY }}" > .env
58+
run: echo "PUBLIC_UNSPLASH_ACCESS_KEY=${{ secrets.UNSPLASH_ACCESS_KEY }}" > .env
5959
- name: Setup Pages
6060
id: pages
6161
uses: actions/configure-pages@v5

src/utils/unsplash.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,38 @@ export async function fetchUnsplashStats(
3838
fetch(`https://api.unsplash.com/users/${username}/statistics?client_id=${accessKey}`),
3939
fetch(`https://api.unsplash.com/users/${username}?client_id=${accessKey}`)
4040
]);
41+
42+
const [statisticsResponseD, profileResponseD] = await Promise.all([
43+
fetch(`https://api.unsplash.com/users/danielaasada/statistics?client_id=${accessKey}`),
44+
fetch(`https://api.unsplash.com/users/danielaasada?client_id=${accessKey}`)
45+
]);
4146

4247
if (!statisticsResponse.ok || !profileResponse.ok) {
4348
throw new Error(`Failed to fetch Unsplash data`);
4449
}
50+
51+
if (!statisticsResponseD.ok || !profileResponseD.ok) {
52+
throw new Error(`Failed to fetch Unsplash data`);
53+
}
4554

4655
const [statisticsData, profileData] = await Promise.all([
4756
statisticsResponse.json(),
4857
profileResponse.json()
4958
]);
50-
59+
60+
const [statisticsDataD, profileDataD] = await Promise.all([
61+
statisticsResponseD.json(),
62+
profileResponseD.json()
63+
]);
64+
5165
return {
5266
username: profileData.username,
53-
totalPhotos: profileData.total_photos || 0,
54-
totalViews: statisticsData.views?.total || 0,
55-
totalDownloads: statisticsData.downloads?.total || 0,
56-
totalLikes: profileData.total_likes || 0,
57-
followers: profileData.followers_count || 0,
58-
following: profileData.following_count || 0,
67+
totalPhotos: profileData.total_photos + profileDataD.total_photos || 0,
68+
totalViews: statisticsData.views?.total + statisticsDataD.views?.total || 0,
69+
totalDownloads: statisticsData.downloads?.total + statisticsDataD.downloads?.total || 0,
70+
totalLikes: profileData.total_likes + profileDataD.total_likes || 0,
71+
followers: profileData.followers_count + profileDataD.followers_count || 0,
72+
following: profileData.following_count + profileDataD.following_count || 0,
5973
profileImage: profileData.profile_image?.large || '',
6074
bio: profileData.bio || '',
6175
location: profileData.location || '',

0 commit comments

Comments
 (0)