Skip to content

Commit 887b8fc

Browse files
committed
update setting schema
1 parent ebd2513 commit 887b8fc

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

packages/server/config.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,28 @@ seatFile: /home/icpc/Desktop/seat.txt
4141
throw new Error('no-config');
4242
}
4343

44-
const serverSchema = Schema.object({
45-
viewPass: Schema.string().default(String.random(8)),
46-
server: Schema.string().role('url').required(),
47-
type: Schema.union(['server', 'client']).required(),
48-
token: Schema.string().required(),
49-
username: Schema.string().required(),
50-
password: Schema.string().required(),
51-
secretRoute: Schema.string().default(String.random(12)),
52-
seatFile: Schema.string().default('/home/icpc/Desktop/seat.txt'),
53-
});
44+
const serverSchema = Schema.intersect([
45+
Schema.object({
46+
type: Schema.union([
47+
Schema.const('server'),
48+
Schema.const('client'),
49+
] as const).description('server type').required(),
50+
viewPass: Schema.string().default(String.random(8)),
51+
secretRoute: Schema.string().default(String.random(12)),
52+
seatFile: Schema.string().default('/home/icpc/Desktop/seat.txt'),
53+
}).description('setting_file'),
54+
Schema.union([
55+
Schema.object({
56+
type: Schema.const('server'),
57+
token: Schema.string().required(),
58+
}),
59+
Schema.object({
60+
type: Schema.const('client'),
61+
username: Schema.string().required(),
62+
password: Schema.string().required(),
63+
}),
64+
]),
65+
]);
5466
const clientSchema = Schema.object({
5567
server: Schema.string().role('url').required(),
5668
balloon: Schema.string().required(),
@@ -66,4 +78,4 @@ export const saveConfig = () => {
6678

6779
logger.info(`Config loaded from ${configPath}`);
6880
logger.info(`xcpc-tools version: ${version}`);
69-
if (!isClient && !exit) logger.info(`Server View User Info: admin/${config.viewPassword}`);
81+
if (!isClient && !exit) logger.info(`Server View User Info: admin/${config.viewPass}`);

0 commit comments

Comments
 (0)