Skip to content

Commit af13784

Browse files
committed
fix: 修复 cdn 在某些地区无法使用的问题
1 parent e54284f commit af13784

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/content/utils/utils.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,21 @@ export interface ProblemRankData {
274274
}
275275

276276
export const getProblemRankData = async (): Promise<ProblemRankData[]> => {
277-
const data = await Promise.race([
278-
fetch(
279-
'https://cdn.jsdelivr.net/gh/zerotrac/leetcode_problem_rating/data.json'
280-
).then(res => res.json()),
281-
fetch(
282-
'https://raw.githubusercontent.com/zerotrac/leetcode_problem_rating/main/data.json'
283-
).then(res => res.json()),
284-
])
277+
const dataUrls = [
278+
'https://raw.githubusercontent.com/zerotrac/leetcode_problem_rating/main/data.json',
279+
'https://cdn.jsdelivr.net/gh/zerotrac/leetcode_problem_rating/data.json',
280+
'https://testingcf.jsdelivr.net/gh/zerotrac/leetcode_problem_rating/data.json',
281+
'https://fastly.jsdelivr.net/gh/zerotrac/leetcode_problem_rating/data.json',
282+
'https://gcore.jsdelivr.net/gh/zerotrac/leetcode_problem_rating/data.json',
283+
]
284+
const data = await Promise.race(
285+
dataUrls.map(url =>
286+
fetch(url, { headers: {} })
287+
.then(res => res.json())
288+
.catch(() => new Promise((res, rej) => setTimeout(rej, 10000)))
289+
)
290+
)
291+
285292
return data
286293
}
287294

0 commit comments

Comments
 (0)