返回提交历史
Modified
src/controllers/custom/configController.ts
+1
-2
Modified
src/index.ts
+2
-2
Modified
src/services/configService.ts
+18
-0
Modified
src/services/configWatcherService.ts
+1
-19
XFEstudio/SpaceNinjaServer
chore: move syncConfigWithDatabase to configService (#2505)
This avoids a cyclic dependency due to configController using this Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2505 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2c62fb3c
代码差异
4 个文件
+22
-23
@@ -1,9 +1,8 @@
1
1
import { RequestHandler } from "express";
2
import { config } from "@/src/services/configService";
2
import { config, syncConfigWithDatabase } from "@/src/services/configService";
3
3
import { getAccountForRequest, isAdministrator } from "@/src/services/loginService";
4
4
import { saveConfig } from "@/src/services/configWriterService";
5
5
import { sendWsBroadcastExcept } from "@/src/services/wsService";
6
import { syncConfigWithDatabase } from "@/src/services/configWatcherService";
7
6
8
7
export const getConfigController: RequestHandler = async (req, res) => {
9
8
const account = await getAccountForRequest(req);
@@ -1,5 +1,5 @@
1
1
// First, init config.
2
import { config, configPath, loadConfig } from "@/src/services/configService";
2
import { config, configPath, loadConfig, syncConfigWithDatabase } from "@/src/services/configService";
3
3
import fs from "fs";
4
4
try {
5
5
loadConfig();
@@ -21,7 +21,7 @@ import mongoose from "mongoose";
21
21
import { JSONStringify } from "json-with-bigint";
22
22
import { startWebServer } from "@/src/services/webService";
23
23
24
import { syncConfigWithDatabase, validateConfig } from "@/src/services/configWatcherService";
24
import { validateConfig } from "@/src/services/configWatcherService";
25
25
import { updateWorldStateCollections } from "@/src/services/worldStateService";
26
26
27
27
// Patch JSON.stringify to work flawlessly with Bigints.
@@ -2,6 +2,7 @@ import fs from "fs";
2
2
import path from "path";
3
3
import { repoDir } from "@/src/helpers/pathHelper";
4
4
import { args } from "@/src/helpers/commandLineArguments";
5
import { Inbox } from "@/src/models/inboxModel";
5
6
6
7
export interface IConfig {
7
8
mongodbUrl: string;
@@ -119,3 +120,20 @@ export const loadConfig = (): void => {
119
120
120
121
Object.assign(config, newConfig);
121
122
};
123
124
export const syncConfigWithDatabase = (): void => {
125
// 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.
126
// Also, for some reason, I can't just do `Inbox.deleteMany(...)`; - it needs this whole circus.
127
if (!config.worldState?.creditBoost) {
128
void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666672" }).then(() => {});
129
}
130
if (!config.worldState?.affinityBoost) {
131
void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666673" }).then(() => {});
132
}
133
if (!config.worldState?.resourceBoost) {
134
void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666674" }).then(() => {});
135
}
136
if (!config.worldState?.galleonOfGhouls) {
137
void Inbox.deleteMany({ goalTag: "GalleonRobbery" }).then(() => {});
138
}
139
};
@@ -1,10 +1,9 @@
1
1
import chokidar from "chokidar";
2
2
import { logger } from "@/src/utils/logger";
3
import { config, configPath, loadConfig } from "@/src/services/configService";
3
import { config, configPath, loadConfig, syncConfigWithDatabase } from "@/src/services/configService";
4
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
import { Inbox } from "@/src/models/inboxModel";
8
7
import varzia from "@/static/fixed_responses/worldState/varzia.json";
9
8
10
9
chokidar.watch(configPath).on("change", () => {
@@ -68,20 +67,3 @@ export const validateConfig = (): void => {
68
67
void saveConfig();
69
68
}
70
69
};
71
72
export const syncConfigWithDatabase = (): void => {
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.
74
// Also, for some reason, I can't just do `Inbox.deleteMany(...)`; - it needs this whole circus.
75
if (!config.worldState?.creditBoost) {
76
void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666672" }).then(() => {});
77
}
78
if (!config.worldState?.affinityBoost) {
79
void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666673" }).then(() => {});
80
}
81
if (!config.worldState?.resourceBoost) {
82
void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666674" }).then(() => {});
83
}
84
if (!config.worldState?.galleonOfGhouls) {
85
void Inbox.deleteMany({ goalTag: "GalleonRobbery" }).then(() => {});
86
}
87
};