-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
56 lines (53 loc) · 3.55 KB
/
index.ts
File metadata and controls
56 lines (53 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Context, Schema } from 'hydrooj';
import * as handler from './handler';
import { CCSEventFeedService } from './lib/event-mgr';
import { CCSEventContest, CCSEventDoc } from './lib/types';
declare module 'hydrooj' {
interface Collections {
'ccs.contest': CCSEventContest;
'ccs.event': CCSEventDoc;
}
interface Context {
ccs: CCSEventFeedService;
}
}
export const name = 'ccs-api';
export const Config = Schema.object({
username: Schema.string().default('ccs_hydro').description('CCS Username'),
password: Schema.string().default('defaultKey@ccs').description('CCS Password'),
}).description('CCS API');
export async function apply(ctx: Context) {
ctx.plugin(CCSEventFeedService);
ctx.inject(['ccs'], async (c: Context) => {
c.server.config.enableSSE = true;
c.Route('ccs_operation', '/ccs/api/contests/:contestId/operation/:operation', handler.CCSOperationHandler);
c.Route('ccs_api_info', '/ccs/api', handler.ApiInfoHandler);
c.Route('ccs_contests', '/ccs/api/contests', handler.ContestsHandler);
c.Route('ccs_contest', '/ccs/api/contests/:contestId', handler.ContestsHandler);
c.Route('ccs_contest_state', '/ccs/api/contests/:contestId/state', handler.ContestStateHandler);
c.Route('ccs_contest_languages', '/ccs/api/contests/:contestId/languages', handler.LanguagesHandler);
c.Route('ccs_contest_language', '/ccs/api/contests/:contestId/languages/:id', handler.LanguagesHandler);
c.Route('ccs_contest_problems', '/ccs/api/contests/:contestId/problems', handler.ProblemsHandler);
c.Route('ccs_contest_problem', '/ccs/api/contests/:contestId/problems/:id', handler.ProblemsHandler);
c.Route('ccs_contest_teams', '/ccs/api/contests/:contestId/teams', handler.TeamsHandler);
c.Route('ccs_contest_team', '/ccs/api/contests/:contestId/teams/:id', handler.TeamsHandler);
c.Route('ccs_contest_organizations', '/ccs/api/contests/:contestId/organizations', handler.OrganizationsHandler);
c.Route('ccs_contest_organization', '/ccs/api/contests/:contestId/organizations/:id', handler.OrganizationsHandler);
c.Route('ccs_contest_groups', '/ccs/api/contests/:contestId/groups', handler.GroupsHandler);
c.Route('ccs_contest_group', '/ccs/api/contests/:contestId/groups/:id', handler.GroupsHandler);
c.Route('ccs_contest_judgement_types', '/ccs/api/contests/:contestId/judgement-types', handler.JudgementTypesHandler);
c.Route('ccs_contest_judgement_type', '/ccs/api/contests/:contestId/judgement-types/:id', handler.JudgementTypesHandler);
c.Route('ccs_contest_submissions', '/ccs/api/contests/:contestId/submissions', handler.SubmissionsHandler);
c.Route('ccs_contest_submission', '/ccs/api/contests/:contestId/submissions/:id', handler.SubmissionsHandler);
c.Route('ccs_contest_judgements', '/ccs/api/contests/:contestId/judgements', handler.JudgementsHandler);
c.Route('ccs_contest_judgement', '/ccs/api/contests/:contestId/judgements/:id', handler.JudgementsHandler);
c.Route('ccs_contest_runs', '/ccs/api/contests/:contestId/runs', handler.RunsHandler);
c.Route('ccs_contest_run', '/ccs/api/contests/:contestId/runs/:id', handler.RunsHandler);
c.Connection('ccs_contest_event_feed', '/ccs/api/contests/:contestId/event-feed', handler.EventFeedHandler);
if (process.env.NODE_APP_INSTANCE === '0') {
c.on('record/change', async (rdoc, $set, $push) => {
await c.ccs.handleRecordChange(rdoc, $set, $push);
});
}
});
}