Files

34 lines
804 B
TypeScript
Raw Permalink Normal View History

2024-07-05 16:04:12 +02:00
// CONFIG
const configPath = "config.json";
export const defaultConfig = {
port: 3000,
2026-10-12 20:38:04 +02:00
privacy: "",
imprint: "",
connectedServers: [],
subscribedChannels: [],
2024-07-05 16:04:12 +02:00
};
// METHODS
export async function createConfig() {
const configString = JSON.stringify(defaultConfig, null, 4);
await Bun.write(configPath, configString);
2024-07-05 16:04:12 +02:00
}
export async function getConfig(): Promise<typeof defaultConfig> {
try {
const configString = await Bun.file(configPath).text();
const configObject = JSON.parse(configString);
2024-07-05 16:04:12 +02:00
// validate config file
Object.keys(defaultConfig).forEach((key) => {
if (!configObject[key]) throw null;
});
2024-07-05 16:04:12 +02:00
return configObject;
} catch {
await createConfig();
return defaultConfig;
}
2024-07-05 16:04:12 +02:00
}