-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.ts
42 lines (33 loc) · 945 Bytes
/
config.ts
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
import { getKeyPair } from "@hs/homeserver";
import type { Config } from "@hs/homeserver/src/plugins/config";
const { CONFIG_FOLDER = "." } = process.env;
const getConfig = async (): Promise<Config> => {
// read info
const file = Bun.file(`${CONFIG_FOLDER}/config.json`);
if (!file.exists) {
throw new Error("Config file not found");
}
const content = await file.json();
if (!content.name) {
throw new Error("Config file is missing the name property");
}
if (content.signingKey) {
return content;
}
const { signingKeyPath = `${CONFIG_FOLDER}/${content.name}.signing.key` } =
content;
if (typeof signingKeyPath !== "string") {
throw new Error("Config file is missing the signingKeyPath property");
}
const result = await getKeyPair({
signingKeyPath,
});
return {
...content,
signingKey: result,
name: content.name,
path: CONFIG_FOLDER,
signingKeyPath,
};
};
export const config = await getConfig();