返回提交历史
Modified
src/controllers/custom/getConfigDataController.ts
+2
-2
Modified
src/controllers/custom/updateConfigDataController.ts
+4
-11
Modified
src/services/configService.ts
+23
-2
Modified
static/webui/index.html
+57
-75
XFEstudio/SpaceNinjaServer
fix: config change on WebUI causing hot reload in dev mode (#297)
e5451d52
代码差异
4 个文件
+86
-90
@@ -1,8 +1,8 @@
1
1
import { RequestHandler } from "express";
2
import configFile from "@/config.json";
2
import { config } from "@/src/services/configService";
3
3
4
4
const getConfigDataController: RequestHandler = (_req, res) => {
5
res.json(configFile);
5
res.json(config);
6
6
};
7
7
8
8
export { getConfigDataController };
@@ -1,16 +1,9 @@
1
1
import { RequestHandler } from "express";
2
import path from "path";
3
import fs from "fs";
4
const rootDir = path.join(__dirname, "../../..");
2
import { updateConfig } from "@/src/services/configService";
5
3
6
const updateConfigDataController: RequestHandler = req => {
7
const updateSettingsData = req.body;
8
9
fs.writeFile(path.join(rootDir, "config.json"), updateSettingsData, function (err: any) {
10
if (err) {
11
return console.log(err);
12
}
13
});
4
const updateConfigDataController: RequestHandler = async (req, res) => {
5
await updateConfig(req.body.toString());
6
res.end();
14
7
};
15
8
16
9
export { updateConfigDataController };
@@ -1,4 +1,22 @@
1
import rawConfig from "@/config.json";
1
import path from "path";
2
import fs from "fs";
3
import fsPromises from "fs/promises";
4
import { logger } from "@/src/utils/logger";
5
6
const rootDir = path.join(__dirname, "../..");
7
const repoDir = path.basename(rootDir) == "build" ? path.join(rootDir, "..") : rootDir;
8
const configPath = path.join(repoDir, "config.json");
9
export const config: IConfig = JSON.parse(fs.readFileSync(configPath, "utf-8"));
10
11
let amnesia = false;
12
fs.watchFile(configPath, () => {
13
if (amnesia) {
14
amnesia = false;
15
} else {
16
logger.info("Detected a change to config.json, reloading its contents.");
17
Object.assign(config, JSON.parse(fs.readFileSync(configPath, "utf-8")));
18
}
19
});
2
20
3
21
interface IConfig {
4
22
mongodbUrl: string;
@@ -26,4 +44,7 @@ interface ILoggerConfig {
26
44
level: string; // "fatal" | "error" | "warn" | "info" | "http" | "debug" | "trace";
27
45
}
28
46
29
export const config: IConfig = rawConfig;
47
export const updateConfig = async (data: string) => {
48
amnesia = true;
49
return await fsPromises.writeFile(configPath, data);
50
};
@@ -204,81 +204,63 @@
204
204
</div>
205
205
</div>
206
206
<div data-route="/webui/settings" data-title="Settings | OpenWF WebUI">
207
<div class="card mb-4">
208
<h5 class="card-header">Change Settings</h5>
209
<form class="card-body" onsubmit="doChangeSettings();return false;">
210
<div class="form-check">
211
<input class="form-check-input" type="checkbox" value="" id="skipStoryModeChoice" />
212
<label label class="form-check-label" for="skipStoryModeChoice"
213
>Skip Story Mode Choice?</label
214
>
215
</div>
216
<div class="form-check">
217
<input class="form-check-input" type="checkbox" value="" id="skipTutorial" />
218
<label label class="form-check-label" for="skipTutorial">Skip Tutorial?</label>
219
</div>
220
<div class="form-check">
221
<input class="form-check-input" type="checkbox" value="" id="unlockAllScans" />
222
<label label class="form-check-label" for="unlockAllScans">Unlock All Scans?</label>
223
</div>
224
<div class="form-check">
225
<input class="form-check-input" type="checkbox" value="" id="unlockAllMissions" />
226
<label label class="form-check-label" for="unlockAllMissions"
227
>Unlock All Missions?</label
228
>
229
</div>
230
<div class="form-check">
231
<input class="form-check-input" type="checkbox" value="" id="unlockAllQuests" />
232
<label label class="form-check-label" for="unlockAllQuests">Unlock All Quests?</label>
233
</div>
234
<div class="form-check">
235
<input class="form-check-input" type="checkbox" value="" id="completeAllQuests" />
236
<label label class="form-check-label" for="completeAllQuests"
237
>Complete All Quests?</label
238
>
239
</div>
240
<div class="form-check">
241
<input class="form-check-input" type="checkbox" value="" id="infiniteResources" />
242
<label label class="form-check-label" for="infiniteResources"
243
>Infinite Credits and Platinum?</label
244
>
245
</div>
246
<div class="form-check">
247
<input class="form-check-input" type="checkbox" value="" id="unlockallShipFeatures" />
248
<label label class="form-check-label" for="unlockallShipFeatures"
249
>Unlock All Ship Features?</label
250
>
251
</div>
252
<div class="form-check">
253
<input
254
class="form-check-input"
255
type="checkbox"
256
value=""
257
id="unlockAllShipDecorations"
258
/>
259
<label label class="form-check-label" for="unlockAllShipDecorations"
260
>Unlock All Ship Decorations?</label
261
>
262
</div>
263
<div class="form-check">
264
<input class="form-check-input" type="checkbox" value="" id="unlockAllFlavourItems" />
265
<label label class="form-check-label" for="unlockAllFlavourItems"
266
>Unlock All Accessories?</label
267
>
268
</div>
269
<div class="form-check">
270
<input class="form-check-input" type="checkbox" value="" id="unlockAllSkins" />
271
<label label class="form-check-label" for="unlockAllSkins">Unlock All Skins?</label>
272
</div>
273
<div class="form-check">
274
<label label class="form-check-label" for="spoofMasteryRank"
275
>Spoofed Mastery Rank (-1 to disable)</label
276
>
277
<input class="form-control" id="spoofMasteryRank" type="number" min="-1" value="" />
278
</div>
279
<button class="btn btn-primary" type="submit">Save Settings</button>
280
</form>
281
</div>
207
<form onsubmit="doChangeSettings();return false;">
208
<div class="form-check">
209
<input class="form-check-input" type="checkbox" id="skipStoryModeChoice" />
210
<label class="form-check-label" for="skipStoryModeChoice">Skip Story Mode Choice</label>
211
</div>
212
<div class="form-check">
213
<input class="form-check-input" type="checkbox" id="skipTutorial" />
214
<label class="form-check-label" for="skipTutorial">Skip Tutorial</label>
215
</div>
216
<div class="form-check">
217
<input class="form-check-input" type="checkbox" id="unlockAllScans" />
218
<label class="form-check-label" for="unlockAllScans">Unlock All Scans</label>
219
</div>
220
<div class="form-check">
221
<input class="form-check-input" type="checkbox" id="unlockAllMissions" />
222
<label class="form-check-label" for="unlockAllMissions">Unlock All Missions</label>
223
</div>
224
<div class="form-check">
225
<input class="form-check-input" type="checkbox" id="unlockAllQuests" />
226
<label class="form-check-label" for="unlockAllQuests">Unlock All Quests</label>
227
</div>
228
<div class="form-check">
229
<input class="form-check-input" type="checkbox" id="completeAllQuests" />
230
<label class="form-check-label" for="completeAllQuests">Complete All Quests</label>
231
</div>
232
<div class="form-check">
233
<input class="form-check-input" type="checkbox" id="infiniteResources" />
234
<label class="form-check-label" for="infiniteResources"
235
>Infinite Credits and Platinum</label
236
>
237
</div>
238
<div class="form-check">
239
<input class="form-check-input" type="checkbox" id="unlockAllShipFeatures" />
240
<label class="form-check-label" for="unlockAllShipFeatures">Unlock All Ship Features</label>
241
</div>
242
<div class="form-check">
243
<input class="form-check-input" type="checkbox" id="unlockAllShipDecorations" />
244
<label class="form-check-label" for="unlockAllShipDecorations"
245
>Unlock All Ship Decorations</label
246
>
247
</div>
248
<div class="form-check">
249
<input class="form-check-input" type="checkbox" id="unlockAllFlavourItems" />
250
<label class="form-check-label" for="unlockAllFlavourItems">Unlock All Accessories</label>
251
</div>
252
<div class="form-check">
253
<input class="form-check-input" type="checkbox" id="unlockAllSkins" />
254
<label class="form-check-label" for="unlockAllSkins">Unlock All Skins</label>
255
</div>
256
<div class="form-group">
257
<label class="form-label" for="spoofMasteryRank"
258
>Spoofed Mastery Rank (-1 to disable)</label
259
>
260
<input class="form-control" id="spoofMasteryRank" type="number" min="-1" />
261
</div>
262
<button class="btn btn-primary mt-3" type="submit">Save Settings</button>
263
</form>
282
264
</div>
283
265
</div>
284
266
</div>