Compare commits
No commits in common. "9700416355547e886a479aa61ebf1e8dc2481ef7" and "5277f7cc3781d45bae899b4c45b4927ea66c3f69" have entirely different histories.
9700416355
...
5277f7cc37
@ -1,6 +1,5 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { getAccountForRequest, isAdministrator, isNameTaken } from "@/src/services/loginService";
|
||||
import { config, saveConfig } from "@/src/services/configService";
|
||||
import { getAccountForRequest, isNameTaken } from "@/src/services/loginService";
|
||||
|
||||
export const renameAccountController: RequestHandler = async (req, res) => {
|
||||
const account = await getAccountForRequest(req);
|
||||
@ -8,18 +7,8 @@ export const renameAccountController: RequestHandler = async (req, res) => {
|
||||
if (await isNameTaken(req.query.newname)) {
|
||||
res.status(409).json("Name already in use");
|
||||
} else {
|
||||
if (isAdministrator(account)) {
|
||||
for (let i = 0; i != config.administratorNames!.length; ++i) {
|
||||
if (config.administratorNames![i] == account.DisplayName) {
|
||||
config.administratorNames![i] = req.query.newname;
|
||||
}
|
||||
}
|
||||
await saveConfig();
|
||||
}
|
||||
|
||||
account.DisplayName = req.query.newname;
|
||||
await account.save();
|
||||
|
||||
res.end();
|
||||
}
|
||||
} else {
|
||||
|
10
src/index.ts
10
src/index.ts
@ -19,13 +19,9 @@ import mongoose from "mongoose";
|
||||
return "<BIGINT>" + this.toString() + "</BIGINT>";
|
||||
};
|
||||
const og_stringify = JSON.stringify;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
JSON.stringify = (obj: any, replacer?: any, space?: string | number): string => {
|
||||
return og_stringify(obj, replacer as string[], space)
|
||||
.split(`"<BIGINT>`)
|
||||
.join(``)
|
||||
.split(`</BIGINT>"`)
|
||||
.join(``);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
||||
(JSON as any).stringify = (obj: any): string => {
|
||||
return og_stringify(obj).split(`"<BIGINT>`).join(``).split(`</BIGINT>"`).join(``);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ interface IConfig {
|
||||
httpsPort?: number;
|
||||
myIrcAddresses?: string[];
|
||||
NRS?: string[];
|
||||
administratorNames?: string[];
|
||||
administratorNames?: string[] | string;
|
||||
autoCreateAccount?: boolean;
|
||||
skipTutorial?: boolean;
|
||||
skipAllDialogue?: boolean;
|
||||
@ -83,15 +83,10 @@ export const updateConfig = async (data: string): Promise<void> => {
|
||||
Object.assign(config, JSON.parse(data));
|
||||
};
|
||||
|
||||
export const saveConfig = async (): Promise<void> => {
|
||||
amnesia = true;
|
||||
await fsPromises.writeFile(configPath, JSON.stringify(config, null, 2));
|
||||
};
|
||||
|
||||
export const validateConfig = (): void => {
|
||||
if (typeof config.administratorNames == "string") {
|
||||
logger.info(`Updating config.json to make administratorNames an array.`);
|
||||
config.administratorNames = [config.administratorNames];
|
||||
void saveConfig();
|
||||
logger.warn(
|
||||
`"administratorNames" should be an array; please add square brackets: ["${config.administratorNames}"]`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -92,7 +92,13 @@ export const getAccountIdForRequest = async (req: Request): Promise<string> => {
|
||||
};
|
||||
|
||||
export const isAdministrator = (account: TAccountDocument): boolean => {
|
||||
return !!config.administratorNames?.find(x => x == account.DisplayName);
|
||||
if (!config.administratorNames) {
|
||||
return false;
|
||||
}
|
||||
if (typeof config.administratorNames == "string") {
|
||||
return config.administratorNames == account.DisplayName;
|
||||
}
|
||||
return !!config.administratorNames.find(x => x == account.DisplayName);
|
||||
};
|
||||
|
||||
const platform_magics = [753, 639, 247, 37, 60];
|
||||
|
Loading…
x
Reference in New Issue
Block a user