Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions scripts/fetch-user-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,27 @@ async function fetchUserInfo(username) {

// 2. Fetch live profile ranking from the wrapper API
let liveSolved = null;
const livePromise = fetchWithTimeout(liveApiUrl).then(async (res) => {
if (res.ok) {
const apiData = await res.json();
ranking = apiData.ranking || 0;
contest = apiData.contest || null;
liveSolved = {
easy: apiData.easySolved || 0,
medium: apiData.mediumSolved || 0,
hard: apiData.hardSolved || 0,
};
} else {
throw new Error(`LeetCode API wrapper returned status ${res.status}`);
}
});

const livePromise = fetchWithTimeout(liveApiUrl)
.then(async (res) => {
if (res.ok) {
const apiData = await res.json();
ranking = apiData.ranking || 0;
contest = apiData.contest || null;
liveSolved = {
easy: apiData.easySolved || 0,
medium: apiData.mediumSolved || 0,
hard: apiData.hardSolved || 0,
};
} else {
throw new Error(`LeetCode API wrapper returned status ${res.status}`);
}
})
.catch((err) => {
console.warn(
`Live LeetCode API unavailable for ${username}. Falling back to cached repository data. Reason:`,
err.message,
);
});
// Wait for the live API task to complete
await livePromise;

Expand Down
Loading