Skip to content

Commit 91a14bd

Browse files
committed
fix
1 parent 887b8fc commit 91a14bd

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

packages/server/config.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ if (!fs.existsSync(configPath)) {
1818
// eslint-disable-next-line no-promise-executor-return
1919
exit = new Promise((resolve) => (async () => {
2020
const serverConfigDefault = `\
21-
type:
22-
viewPass: ${String.random(8)}
21+
type: server # server | domjudge | hydro
22+
viewPass: ${String.random(8)} # use admin / viewPass to login
2323
server:
2424
token:
2525
username:
@@ -45,22 +45,29 @@ const serverSchema = Schema.intersect([
4545
Schema.object({
4646
type: Schema.union([
4747
Schema.const('server'),
48-
Schema.const('client'),
48+
Schema.const('domjudge'),
49+
Schema.const('hydro'),
4950
] as const).description('server type').required(),
51+
port: Schema.number().default(5283),
5052
viewPass: Schema.string().default(String.random(8)),
5153
secretRoute: Schema.string().default(String.random(12)),
5254
seatFile: Schema.string().default('/home/icpc/Desktop/seat.txt'),
53-
}).description('setting_file'),
55+
}).description('Basic Config'),
5456
Schema.union([
5557
Schema.object({
56-
type: Schema.const('server'),
57-
token: Schema.string().required(),
58-
}),
59-
Schema.object({
60-
type: Schema.const('client'),
58+
type: Schema.const('domjudge').required(),
59+
server: Schema.string().role('url').required(),
6160
username: Schema.string().required(),
6261
password: Schema.string().required(),
63-
}),
62+
}).description('DomJudge Fetcher Config'),
63+
Schema.object({
64+
type: Schema.const('hydro').required(),
65+
server: Schema.string().role('url').required(),
66+
token: Schema.string().required(),
67+
}).description('Hydro Fetcher Config'),
68+
Schema.object({
69+
type: Schema.const('server').required(),
70+
}).description('Server Mode Config'),
6471
]),
6572
]);
6673
const clientSchema = Schema.object({

packages/server/handler/monitor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable no-await-in-loop */
2-
import http from 'http';
32
import { Context } from 'cordis';
43
import { BadRequestError, Handler } from '@hydrooj/framework';
54
import { Logger } from '../utils';

packages/server/service/db.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,24 @@ export default class DBService extends Service {
2626
fs.ensureDirSync(path.resolve(process.cwd(), 'data/.db'));
2727
super(ctx, 'dbservice', true);
2828
ctx.mixin('dbservice', ['db']);
29+
this.start();
2930
}
3031

31-
db: { [T in keyof Collections]: Datastore<Collections[T]> };
32+
db: { [T in keyof Collections]: Datastore<Collections[T]> } = {} as any;
3233

3334
async initDatabase(key: string, fields: string[]) {
3435
this.db[key] = Datastore.create(path.resolve(process.cwd(), `data/.db/${key}.db`));
35-
await this[key].load();
36+
await this.db[key].load();
3637
// eslint-disable-next-line no-await-in-loop
37-
for (const field of fields) await this[key].ensureIndex({ fieldName: field });
38+
for (const field of fields) await this.db[key].ensureIndex({ fieldName: field });
3839
this.ctx.logger('db').info(`${key} Database loaded`);
3940
}
4041

4142
async start() {
42-
await this.initDatabase('codeDB', ['_id', 'createAt', 'done', 'printer', 'deleted']);
43-
await this.initDatabase('monitorDB', ['_id', 'mac', 'name', 'group']);
44-
await this.initDatabase('clientDB', ['id', 'name', 'type', 'group']);
45-
await this.initDatabase('balloonDB', ['id', 'time', 'problem', 'teamid', 'awards', 'done', 'printDone']);
46-
await this.initDatabase('teamsDB', []);
43+
await this.initDatabase('code', ['_id', 'createAt', 'done', 'printer', 'deleted']);
44+
await this.initDatabase('monitor', ['_id', 'mac', 'name', 'group']);
45+
await this.initDatabase('client', ['id', 'name', 'type', 'group']);
46+
await this.initDatabase('balloon', ['id', 'time', 'problem', 'teamid', 'awards', 'done', 'printDone']);
47+
await this.initDatabase('teams', []);
4748
}
4849
}

packages/server/service/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export * from '@hydrooj/framework/decorators';
66

77
export async function apply(pluginContext: Context) {
88
pluginContext.plugin(WebService, {
9-
port: 5283,
9+
port: config.port,
1010
});
1111
pluginContext.inject(['server'], ({ server }) => {
1212
server.addServerLayer('stream', async (ctx, next) => {

0 commit comments

Comments
 (0)