SpaceNinjaServer/src/services/configService.ts

55 lines
1.6 KiB
TypeScript
Raw Normal View History

import path from "path";
import fs from "fs";
import fsPromises from "fs/promises";
import { logger } from "@/src/utils/logger";
const rootDir = path.join(__dirname, "../..");
const repoDir = path.basename(rootDir) == "build" ? path.join(rootDir, "..") : rootDir;
const configPath = path.join(repoDir, "config.json");
export const config: IConfig = JSON.parse(fs.readFileSync(configPath, "utf-8"));
let amnesia = false;
fs.watchFile(configPath, () => {
if (amnesia) {
amnesia = false;
} else {
logger.info("Detected a change to config.json, reloading its contents.");
Object.assign(config, JSON.parse(fs.readFileSync(configPath, "utf-8")));
}
});
2024-05-15 21:55:59 +02:00
interface IConfig {
mongodbUrl: string;
logger: ILoggerConfig;
myAddress: string;
httpPort?: number;
httpsPort?: number;
myIrcAddresses?: string[];
2024-05-15 21:55:59 +02:00
autoCreateAccount?: boolean;
skipStoryModeChoice?: boolean;
skipTutorial?: boolean;
skipAllDialogue?: boolean;
2024-05-15 21:55:59 +02:00
unlockAllScans?: boolean;
unlockAllMissions?: boolean;
unlockAllQuests?: boolean;
completeAllQuests?: boolean;
2024-05-15 21:55:59 +02:00
infiniteResources?: boolean;
2024-06-11 12:56:51 +02:00
unlockAllShipFeatures?: boolean;
2024-05-15 21:55:59 +02:00
unlockAllShipDecorations?: boolean;
unlockAllFlavourItems?: boolean;
2024-05-29 22:08:41 +02:00
unlockAllSkins?: boolean;
universalPolarityEverywhere?: boolean;
spoofMasteryRank?: number;
2024-05-15 21:55:59 +02:00
}
interface ILoggerConfig {
files: boolean;
level: string; // "fatal" | "error" | "warn" | "info" | "http" | "debug" | "trace";
}
export const updateConfig = async (data: string) => {
amnesia = true;
await fsPromises.writeFile(configPath, data);
Object.assign(config, JSON.parse(data));
};