mirror of
https://github.com/khairul169/github-leaderboard.git
synced 2025-04-28 15:39:31 +07:00
fix: fix followers amount for user with thousands of followers
This commit is contained in:
parent
c983044e11
commit
9ed2984dbd
@ -13,7 +13,13 @@ export const fetchUserProfile = async (data: FetchUserProfileType) => {
|
||||
if (!user) {
|
||||
throw new Error("User not found!");
|
||||
}
|
||||
const details = await github.getUser(user.username);
|
||||
|
||||
const accessToken = user.accessToken || import.meta.env.GITHUB_DEFAULT_TOKEN;
|
||||
const details = await github.getUser(user.username, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
});
|
||||
|
||||
await db
|
||||
.update(users)
|
||||
|
@ -26,8 +26,8 @@ const selectors = {
|
||||
};
|
||||
|
||||
const github = {
|
||||
async getUser(username: string) {
|
||||
const response = await this.fetch(username);
|
||||
async getUser(username: string, options?: Partial<FetchOptions>) {
|
||||
const response = await this.fetch(username, options);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
const name = $(selectors.user.name).text().trim();
|
||||
@ -43,13 +43,21 @@ const github = {
|
||||
achievements.push({ name, image });
|
||||
});
|
||||
|
||||
const user = await github.fetch(`users/${username}`, {
|
||||
ghApi: true,
|
||||
headers: {
|
||||
accept: "application/json",
|
||||
...(options?.headers || {}),
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
name: name || username,
|
||||
avatar,
|
||||
username,
|
||||
location,
|
||||
followers,
|
||||
following,
|
||||
followers: user.followers || followers,
|
||||
following: user.following || following,
|
||||
achievements,
|
||||
};
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user