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

improve: handle config.administratorNames being a string (#658)

02f4d0e8
Sainan <sainan@calamity.inc>
提交于

代码差异

3 个文件 +19 -3
Modified src/index.ts +2 -1
@@ -6,11 +6,12 @@ import http from "http";
6 6 import https from "https";
7 7 import fs from "node:fs";
8 8 import { app } from "./app";
9 import { config } from "./services/configService";
9 import { config, validateConfig } from "./services/configService";
10 10 import { connectDatabase } from "@/src/services/mongoService";
11 11 import { registerLogFileCreationListener } from "@/src/utils/logger";
12 12
13 13 registerLogFileCreationListener();
14 validateConfig();
14 15
15 16 void (async (): Promise<void> => {
16 17 await connectDatabase();
Modified src/services/configService.ts +10 -1
@@ -22,6 +22,7 @@ fs.watchFile(configPath, () => {
22 22 }
23 23
24 24 Object.assign(config, JSON.parse(fs.readFileSync(configPath, "utf-8")));
25 validateConfig();
25 26 }
26 27 });
27 28
@@ -32,7 +33,7 @@ interface IConfig {
32 33 httpPort?: number;
33 34 httpsPort?: number;
34 35 myIrcAddresses?: string[];
35 administratorNames?: string[];
36 administratorNames?: string[] | string;
36 37 autoCreateAccount?: boolean;
37 38 skipTutorial?: boolean;
38 39 skipAllDialogue?: boolean;
@@ -61,3 +62,11 @@ export const updateConfig = async (data: string): Promise<void> => {
61 62 await fsPromises.writeFile(configPath, data);
62 63 Object.assign(config, JSON.parse(data));
63 64 };
65
66 export const validateConfig = (): void => {
67 if (typeof config.administratorNames == "string") {
68 logger.warn(
69 `"administratorNames" should be an array; please add square brackets: ["${config.administratorNames}"]`
70 );
71 }
72 };
Modified src/services/loginService.ts +7 -1
@@ -75,5 +75,11 @@ export const getAccountIdForRequest = async (req: Request): Promise<string> => {
75 75 };
76 76
77 77 export const isAdministrator = (account: TAccountDocument): boolean => {
78 return !!config.administratorNames?.find(x => x == account.DisplayName);
78 if (!config.administratorNames) {
79 return false;
80 }
81 if (typeof config.administratorNames == "string") {
82 return config.administratorNames == account.DisplayName;
83 }
84 return !!config.administratorNames.find(x => x == account.DisplayName);
79 85 };