automatically fix administratorNames being a string
This commit is contained in:
		
							parent
							
								
									5277f7cc37
								
							
						
					
					
						commit
						dc5ec24a1a
					
				
							
								
								
									
										10
									
								
								src/index.ts
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/index.ts
									
									
									
									
									
								
							@ -19,9 +19,13 @@ import mongoose from "mongoose";
 | 
			
		||||
        return "<BIGINT>" + this.toString() + "</BIGINT>";
 | 
			
		||||
    };
 | 
			
		||||
    const og_stringify = JSON.stringify;
 | 
			
		||||
    // 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(``);
 | 
			
		||||
    // 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(``);
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,7 @@ interface IConfig {
 | 
			
		||||
    httpsPort?: number;
 | 
			
		||||
    myIrcAddresses?: string[];
 | 
			
		||||
    NRS?: string[];
 | 
			
		||||
    administratorNames?: string[] | string;
 | 
			
		||||
    administratorNames?: string[];
 | 
			
		||||
    autoCreateAccount?: boolean;
 | 
			
		||||
    skipTutorial?: boolean;
 | 
			
		||||
    skipAllDialogue?: boolean;
 | 
			
		||||
@ -83,10 +83,15 @@ 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.warn(
 | 
			
		||||
            `"administratorNames" should be an array; please add square brackets: ["${config.administratorNames}"]`
 | 
			
		||||
        );
 | 
			
		||||
        logger.info(`Updating config.json to make administratorNames an array.`);
 | 
			
		||||
        config.administratorNames = [config.administratorNames];
 | 
			
		||||
        void saveConfig();
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -92,13 +92,7 @@ export const getAccountIdForRequest = async (req: Request): Promise<string> => {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const isAdministrator = (account: TAccountDocument): boolean => {
 | 
			
		||||
    if (!config.administratorNames) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (typeof config.administratorNames == "string") {
 | 
			
		||||
        return config.administratorNames == account.DisplayName;
 | 
			
		||||
    }
 | 
			
		||||
    return !!config.administratorNames.find(x => x == 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