Skip to content

Commit

Permalink
Merge pull request #27 from kohrVid/add-gitlab-support
Browse files Browse the repository at this point in the history
Add support for GitLab profile pictures
  • Loading branch information
janajri authored Jan 23, 2024
2 parents cfcd451 + 017f384 commit 3c00e21
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
6 changes: 6 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const nextConfig = {
},
{
hostname: 'avatars.githubusercontent.com'
},
{
hostname: 'secure.gravatar.com'
},
{
hostname: 'gitlab.com'
}
],
},
Expand Down
15 changes: 14 additions & 1 deletion src/app/api/retrieve-profile-pic/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export async function GET(request: NextRequest) {
case SocialPlatform.Github:
profilePicUrl = await fetchGithubProfilePic(username);
break;
case SocialPlatform.Gitlab:
profilePicUrl = await fetchGitlabProfilePic(username);
break;
}

if (profilePicUrl === null) {
Expand Down Expand Up @@ -51,4 +54,14 @@ const fetchGithubProfilePic = async (username: string) => {
return null;
}
return response.avatar_url;
}
}

const fetchGitlabProfilePic = async (username: string) => {
const endpoint = `https://gitlab.com/api/v4/users?username=${username}`;
const response = await fetch(endpoint).then(res => res.ok ? res.json() : null);

if (response === null) {
return null;
}
return response[0].avatar_url;
}
5 changes: 4 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import download from 'downloadjs';
import { toPng } from 'html-to-image';
import Image from 'next/image';
import { useEffect, useRef, useState } from "react";
import { FaArrowRotateLeft, FaDownload, FaGithub, FaShare, FaXTwitter } from "react-icons/fa6";
import { FaArrowRotateLeft, FaDownload, FaGithub, FaGitlab, FaShare, FaXTwitter } from "react-icons/fa6";

export default function Home() {
const ref = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -173,6 +173,9 @@ export default function Home() {
<button onClick={async () => await handleRetrieveProfilePicture(SocialPlatform.Github)} className="rounded-full my-2 py-3 px-2 w-full border border-gray-900 text-xl">
Use <FaGithub className="inline mb-1" /> Profile Pic
</button>
<button onClick={async () => await handleRetrieveProfilePicture(SocialPlatform.Gitlab)} className="rounded-full my-2 py-3 px-2 w-full border border-gray-900 text-xl">
Use <FaGitlab className="inline mb-1" /> Profile Pic
</button>
</>
}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum SocialPlatform {
Twitter = "twitter",
Github = "github"
Github = "github",
Gitlab = "gitlab",
}

0 comments on commit 3c00e21

Please sign in to comment.