Skip to content

Commit 26466ee

Browse files
committed
fix: content extension read data twice
1 parent e53acae commit 26466ee

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

packages/core/src/exts/contest.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ContestInfo, ContestRanking, LeetCode, UserContestInfo } from "leetcode-query";
1+
import { ContestInfo, ContestRanking, LeetCode } from "leetcode-query";
22
import { Generator } from "../card";
33
import { Item } from "../item";
44
import { Extension } from "../types";
@@ -7,23 +7,23 @@ export async function ContestExtension(generator: Generator): Promise<Extension>
77
const pre_result = new Promise<null | { ranking: ContestRanking; history: ContestInfo[] }>(
88
(resolve) => {
99
const lc = new LeetCode();
10-
lc.once("receive-graphql", async (res) => {
11-
try {
12-
const { data } = (await res.json()) as { data: UserContestInfo };
13-
const history = data.userContestRankingHistory.filter((x) => x.attended);
10+
lc.user_contest_info(generator.config.username)
11+
.then((data) => {
12+
try {
13+
const history = data.userContestRankingHistory.filter((x) => x.attended);
1414

15-
if (history.length === 0) {
15+
if (history.length === 0) {
16+
resolve(null);
17+
return;
18+
}
19+
20+
resolve({ ranking: data.userContestRanking, history });
21+
} catch (e) {
22+
console.error(e);
1623
resolve(null);
17-
return;
1824
}
19-
20-
resolve({ ranking: data.userContestRanking, history });
21-
} catch (e) {
22-
console.error(e);
23-
resolve(null);
24-
}
25-
});
26-
lc.user_contest_info(generator.config.username).catch(() => resolve(null));
25+
})
26+
.catch(() => resolve(null));
2727
},
2828
);
2929

0 commit comments

Comments
 (0)