XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

chore: fix cyclic includes due to saveConfig used in controllers (#2409)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2409 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

b54fd960
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

4 个文件 +21 -12
Modified src/controllers/custom/configController.ts +1 -1
@@ -1,7 +1,7 @@
1 1 import { RequestHandler } from "express";
2 2 import { config } from "@/src/services/configService";
3 3 import { getAccountForRequest, isAdministrator } from "@/src/services/loginService";
4 import { saveConfig } from "@/src/services/configWatcherService";
4 import { saveConfig } from "@/src/services/configWriterService";
5 5 import { sendWsBroadcastExcept } from "@/src/services/wsService";
6 6
7 7 export const getConfigController: RequestHandler = async (req, res) => {
Modified src/controllers/custom/renameAccountController.ts +1 -1
@@ -1,7 +1,7 @@
1 1 import { RequestHandler } from "express";
2 2 import { getAccountForRequest, isAdministrator, isNameTaken } from "@/src/services/loginService";
3 3 import { config } from "@/src/services/configService";
4 import { saveConfig } from "@/src/services/configWatcherService";
4 import { saveConfig } from "@/src/services/configWriterService";
5 5
6 6 export const renameAccountController: RequestHandler = async (req, res) => {
7 7 const account = await getAccountForRequest(req);
Modified src/services/configWatcherService.ts +2 -10
@@ -1,17 +1,14 @@
1 1 import chokidar from "chokidar";
2 import fsPromises from "fs/promises";
3 2 import { logger } from "@/src/utils/logger";
4 3 import { config, configPath, loadConfig } from "@/src/services/configService";
4 import { saveConfig, shouldReloadConfig } from "@/src/services/configWriterService";
5 5 import { getWebPorts, startWebServer, stopWebServer } from "@/src/services/webService";
6 6 import { sendWsBroadcast } from "@/src/services/wsService";
7 7 import { Inbox } from "@/src/models/inboxModel";
8 8 import varzia from "@/static/fixed_responses/worldState/varzia.json";
9 9
10 let amnesia = false;
11 10 chokidar.watch(configPath).on("change", () => {
12 if (amnesia) {
13 amnesia = false;
14 } else {
11 if (shouldReloadConfig()) {
15 12 logger.info("Detected a change to config file, reloading its contents.");
16 13 try {
17 14 loadConfig();
@@ -72,11 +69,6 @@ export const validateConfig = (): void => {
72 69 }
73 70 };
74 71
75 export const saveConfig = async (): Promise<void> => {
76 amnesia = true;
77 await fsPromises.writeFile(configPath, JSON.stringify(config, null, 2));
78 };
79
80 72 export const syncConfigWithDatabase = (): void => {
81 73 // Event messages are deleted after endDate. Since we don't use beginDate/endDate and instead have config toggles, we need to delete the messages once those bools are false.
82 74 if (!config.worldState?.galleonOfGhouls) {
Added src/services/configWriterService.ts +17 -0
@@ -0,0 +1,17 @@
1 import fsPromises from "fs/promises";
2 import { config, configPath } from "@/src/services/configService";
3
4 let amnesia = false;
5
6 export const saveConfig = async (): Promise<void> => {
7 amnesia = true;
8 await fsPromises.writeFile(configPath, JSON.stringify(config, null, 2));
9 };
10
11 export const shouldReloadConfig = (): boolean => {
12 if (amnesia) {
13 amnesia = false;
14 return false;
15 }
16 return true;
17 };