115 lines
3.5 KiB
TypeScript
115 lines
3.5 KiB
TypeScript
import { readFileSync } from "fs";
|
|
import { join } from "path";
|
|
|
|
interface Config {
|
|
canvasWidth: number;
|
|
canvasHeight: number;
|
|
defaultCooldown: number;
|
|
enableAutomaticEvents: boolean;
|
|
eventDurationMinutes: number;
|
|
eventIntervalHours: number;
|
|
|
|
autoExportIntervalSeconds: number;
|
|
exportPath: string;
|
|
|
|
enableKeycloak: boolean;
|
|
keycloakRealm: string;
|
|
keycloakAuthUrl: string;
|
|
keycloakClientId: string;
|
|
}
|
|
|
|
function parseConfigFile(): Config {
|
|
try {
|
|
const configPath = join(process.cwd(), "config.cfg");
|
|
const configContent = readFileSync(configPath, "utf-8");
|
|
|
|
const config: Partial<Config> = {};
|
|
|
|
configContent.split("\n").forEach(line => {
|
|
line = line.trim();
|
|
if (line.startsWith("#") || !line.includes("=")) return;
|
|
|
|
const [key, value] = line.split("=");
|
|
const trimmedKey = key.trim();
|
|
const trimmedValue = value.trim();
|
|
|
|
switch (trimmedKey) {
|
|
case "CANVAS_WIDTH":
|
|
config.canvasWidth = parseInt(trimmedValue);
|
|
break;
|
|
case "CANVAS_HEIGHT":
|
|
config.canvasHeight = parseInt(trimmedValue);
|
|
break;
|
|
case "DEFAULT_COOLDOWN":
|
|
config.defaultCooldown = parseInt(trimmedValue);
|
|
break;
|
|
case "ENABLE_AUTOMATIC_EVENTS":
|
|
config.enableAutomaticEvents = trimmedValue.toLowerCase() === "true";
|
|
break;
|
|
case "EVENT_DURATION_MINUTES":
|
|
config.eventDurationMinutes = parseInt(trimmedValue);
|
|
break;
|
|
case "EVENT_INTERVAL_HOURS":
|
|
config.eventIntervalHours = parseInt(trimmedValue);
|
|
break;
|
|
|
|
case "AUTO_EXPORT_INTERVAL_SECONDS":
|
|
config.autoExportIntervalSeconds = parseInt(trimmedValue);
|
|
break;
|
|
case "EXPORT_PATH":
|
|
config.exportPath = trimmedValue;
|
|
break;
|
|
case "ENABLE_KEYCLOAK":
|
|
config.enableKeycloak = trimmedValue.toLowerCase() === "true";
|
|
break;
|
|
case "KEYCLOAK_REALM":
|
|
config.keycloakRealm = trimmedValue;
|
|
break;
|
|
case "KEYCLOAK_AUTH_URL":
|
|
config.keycloakAuthUrl = trimmedValue;
|
|
break;
|
|
case "KEYCLOAK_CLIENT_ID":
|
|
config.keycloakClientId = trimmedValue;
|
|
break;
|
|
}
|
|
});
|
|
|
|
// Set defaults for missing values
|
|
return {
|
|
canvasWidth: config.canvasWidth || 100,
|
|
canvasHeight: config.canvasHeight || 100,
|
|
defaultCooldown: config.defaultCooldown || 5,
|
|
enableAutomaticEvents: config.enableAutomaticEvents || false,
|
|
eventDurationMinutes: config.eventDurationMinutes || 30,
|
|
eventIntervalHours: config.eventIntervalHours || 6,
|
|
|
|
autoExportIntervalSeconds: config.autoExportIntervalSeconds || 60,
|
|
exportPath: config.exportPath || "./exports/",
|
|
|
|
enableKeycloak: config.enableKeycloak || false,
|
|
keycloakRealm: config.keycloakRealm || "rplace",
|
|
keycloakAuthUrl: config.keycloakAuthUrl || "http://localhost:8080/auth",
|
|
keycloakClientId: config.keycloakClientId || "rplace-client",
|
|
};
|
|
} catch (error) {
|
|
console.error("Error reading config file, using defaults:", error);
|
|
return {
|
|
canvasWidth: 100,
|
|
canvasHeight: 100,
|
|
defaultCooldown: 5,
|
|
enableAutomaticEvents: false,
|
|
eventDurationMinutes: 30,
|
|
eventIntervalHours: 6,
|
|
|
|
autoExportIntervalSeconds: 60,
|
|
exportPath: "./exports/",
|
|
|
|
enableKeycloak: false,
|
|
keycloakRealm: "rplace",
|
|
keycloakAuthUrl: "http://localhost:8080/auth",
|
|
keycloakClientId: "rplace-client",
|
|
};
|
|
}
|
|
}
|
|
|
|
export const config = parseConfigFile(); |