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) {
|
if (!user) {
|
||||||
throw new Error("User not found!");
|
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
|
await db
|
||||||
.update(users)
|
.update(users)
|
||||||
|
@ -26,8 +26,8 @@ const selectors = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const github = {
|
const github = {
|
||||||
async getUser(username: string) {
|
async getUser(username: string, options?: Partial<FetchOptions>) {
|
||||||
const response = await this.fetch(username);
|
const response = await this.fetch(username, options);
|
||||||
const $ = cheerio.load(response);
|
const $ = cheerio.load(response);
|
||||||
|
|
||||||
const name = $(selectors.user.name).text().trim();
|
const name = $(selectors.user.name).text().trim();
|
||||||
@ -43,13 +43,21 @@ const github = {
|
|||||||
achievements.push({ name, image });
|
achievements.push({ name, image });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const user = await github.fetch(`users/${username}`, {
|
||||||
|
ghApi: true,
|
||||||
|
headers: {
|
||||||
|
accept: "application/json",
|
||||||
|
...(options?.headers || {}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: name || username,
|
name: name || username,
|
||||||
avatar,
|
avatar,
|
||||||
username,
|
username,
|
||||||
location,
|
location,
|
||||||
followers,
|
followers: user.followers || followers,
|
||||||
following,
|
following: user.following || following,
|
||||||
achievements,
|
achievements,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user