Skip to content

Commit bd5a7d5

Browse files
committed
add auto contestId
1 parent d77e8a0 commit bd5a7d5

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

packages/server/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const serverSchema = Schema.intersect([
7777
Schema.const('hydro'),
7878
] as const).required(),
7979
server: Schema.string().role('url').required(),
80+
contestId: Schema.string(),
8081
token: Schema.string(),
8182
username: Schema.string(),
8283
password: Schema.string(),

packages/server/service/fetcher.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,22 @@ class BasicFetcher extends Service implements IBasicFetcher {
6262

6363
class DomJudgeFetcher extends BasicFetcher {
6464
async contestInfo() {
65-
const { body } = await fetch('/api/v4/contests?onlyActive=true');
66-
if (!body || !body.length) {
67-
logger.error('Contest not found');
68-
return false;
65+
let contest;
66+
if (!config.contestId) {
67+
const { body } = await fetch('/api/v4/contests?onlyActive=true');
68+
if (!body || !body.length) {
69+
logger.error('Contest not found');
70+
return false;
71+
}
72+
contest = body[0];
73+
} else {
74+
const { body } = await fetch(`/api/v4/contests/${config.contestId}`);
75+
if (!body || !body.id) {
76+
logger.error(`Contest ${config.contestId} not found`);
77+
return false;
78+
}
79+
contest = body;
6980
}
70-
const contest = body[0];
7181
let freeze = contest.scoreboard_freeze_duration.split(':');
7282
freeze = parseInt(freeze[0], 10) * 3600 + parseInt(freeze[1], 10) * 60 + parseInt(freeze[2], 10);
7383
contest.freeze_time = new Date(contest.end_time).getTime() - freeze * 1000;

0 commit comments

Comments
 (0)